Quite often, applications need to playback sounds in response to GUI events, as you might do in a game or just to provide audio feedback for user actions. For this application, QtMultimedia offers the QSoundEffect class. QSoundEffect is limited to playing back uncompressed audio, so it works with Pulse Code Modulation (PCM), Waveform data (WAV) files but not MP3 or OGG files. The trade-off is that it is low-latency and very efficient with resources, so while it's not useful as a general-purpose audio player, it is perfect for fast playback of sound effects.
To demonstrate QSoundEffect, let's build a phone dialer. Copy the application template from Chapter 4, Building Applications with QMainWindow, into a new file called phone_dialer.py and open it in your editor.
Let's start by importing the QtMultimedia library, as follows:
from PyQt5 import...