PySide6.QtMultimedia.QAudioDevice¶
- class QAudioDevice¶
- The - QAudioDeviceclass provides an information about audio devices and their functionality. More…- Synopsis¶- Properties¶- Methods¶- def - __init__()
- def - description()
- def - id()
- def - isDefault()
- def - isNull()
- def - mode()
- def - __ne__()
- def - __eq__()
- def - swap()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - QAudioDevicedescribes an audio device available in the system, either for input or for playback.- A - QAudioDeviceis used by Qt to construct classes that communicate with the device – such as- QAudioSource, and- QAudioSink. It is also used to determine the input or output device to use in a capture session or during media playback.- You can also query each device for the formats it supports. A format in this context is a set consisting of a channel count, sample rate, and sample type. A format is represented by the - QAudioFormatclass.- The values supported by the device for each of these parameters can be fetched with - minimumChannelCount(),- maximumChannelCount(),- minimumSampleRate(),- maximumSampleRate()and- supportedSampleFormats(). The combinations supported are dependent on the audio device capabilities. If you need a specific format, you can check if the device supports it with- isFormatSupported(). For instance:- sourceFile.setFileName("/tmp/test.raw") sourceFile.open(QIODevice.ReadOnly) format = QAudioFormat() # Set up the format, eg. format.setSampleRate(8000) format.setChannelCount(1) format.setSampleFormat(QAudioFormat.UInt8) info = QAudioDevice(QMediaDevices.defaultAudioOutput()) if not info.isFormatSupported(format): qWarning() << "Raw audio format not supported by backend, cannot play audio." return audio = QAudioSink(format, self) audio.connect(QAudioSink::stateChanged, self.handleStateChanged) audio.start(sourceFile) - The set of available devices can be retrieved from the - QMediaDevicesclass.- For instance: - devices = QMediaDevices.audioOutputs() for device in devices: print("Device: ", device.description()) - In this code sample, we loop through all devices that are able to output sound, i.e., play an audio stream in a supported format. For each device we find, we simply print the deviceName(). - See also - class Mode¶
- Describes the mode of this device. - Constant - Description - QAudioDevice.Null - A null device. - QAudioDevice.Input - An input device. - QAudioDevice.Output - An output device. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property descriptionᅟ: str¶
 - Returns a human readable name of the audio device. - Use this string to present the device to the user. - Access functions:
 - property idᅟ: QByteArray¶
 - Returns an identifier for the audio device. - Device names vary depending on the platform/audio plugin being used. - They are a unique identifier for the audio device. - Access functions:
 - property isDefaultᅟ: bool¶
 - Returns true if this is the default audio device. - Access functions:
 - property modeᅟ: QAudioDevice.Mode¶
 - Returns whether this device is an input or output device. - Access functions:
 - __init__()¶
 - Constructs a null - QAudioDeviceobject.- __init__(other)
- Parameters:
- other – - QAudioDevice
 
 - Constructs a copy of - other.- channelConfiguration()¶
- Return type:
 
 - Returns the channel configuration of the device. - description()¶
- Return type:
- str 
 
 - Getter of property - descriptionᅟ.- id()¶
- Return type:
 
 - Getter of property - idᅟ.- isDefault()¶
- Return type:
- bool 
 
 - Getter of property - isDefaultᅟ.- isFormatSupported(format)¶
- Parameters:
- format – - QAudioFormat
- Return type:
- bool 
 
 - Returns true if the supplied - settingsare supported by the audio device described by this- QAudioDevice.- isNull()¶
- Return type:
- bool 
 
 - Returns whether this - QAudioDeviceobject holds a valid device definition.- maximumChannelCount()¶
- Return type:
- int 
 
 - Returns the maximum number of supported channel counts. - This is typically 1 for mono sound, or 2 for stereo sound. - maximumSampleRate()¶
- Return type:
- int 
 
 - Returns the maximum supported sample rate (in Hertz). - minimumChannelCount()¶
- Return type:
- int 
 
 - Returns the minimum number of supported channel counts. - This is typically 1 for mono sound, or 2 for stereo sound. - minimumSampleRate()¶
- Return type:
- int 
 
 - Returns the minimum supported sample rate (in Hertz). - Getter of property - modeᅟ.- __ne__(other)¶
- Parameters:
- other – - QAudioDevice
- Return type:
- bool 
 
 - Returns true if this - QAudioDeviceclass represents a different audio device than- other- __eq__(other)¶
- Parameters:
- other – - QAudioDevice
- Return type:
- bool 
 
 - Returns true if this - QAudioDeviceclass represents the same audio device as- other.- preferredFormat()¶
- Return type:
 
 - Returns the default audio format settings for this device. - These settings are provided by the platform/audio plugin being used. - They are also dependent on the QtAudio ::Mode being used. - A typical audio system would provide something like: - Input settings: 48000Hz mono 16 bit. 
- Output settings: 48000Hz stereo 16 bit. 
 - supportedSampleFormats()¶
- Return type:
- .list of QAudioFormat.SampleFormat 
 
 - Returns a list of supported sample types. - swap(other)¶
- Parameters:
- other – - QAudioDevice
 
 - Swaps the audio device with the - other.