QAudioDeviceInfo¶
The
QAudioDeviceInfo
class provides an interface to query audio devices and their functionality. More…
Synopsis¶
Functions¶
def
__eq__
(other)def
__ne__
(other)def
deviceName
()def
isFormatSupported
(format)def
isNull
()def
nearestFormat
(format)def
preferredFormat
()def
realm
()def
supportedByteOrders
()def
supportedChannelCounts
()def
supportedCodecs
()def
supportedSampleRates
()def
supportedSampleSizes
()def
supportedSampleTypes
()
Static functions¶
def
availableDevices
(mode)def
defaultInputDevice
()def
defaultOutputDevice
()
Detailed Description¶
QAudioDeviceInfo
lets you query for audio devices–such as sound cards and USB headsets–that are currently available on the system. The audio devices available are dependent on the platform or audio plugins installed.A
QAudioDeviceInfo
is used by Qt to construct classes that communicate with the device–such asQAudioInput
, andQAudioOutput
.You can also query each device for the formats it supports. A format in this context is a set consisting of a specific byte order, channel, codec, frequency, sample rate, and sample type. A format is represented by the
QAudioFormat
class.The values supported by the device for each of these parameters can be fetched with
supportedByteOrders()
,supportedChannelCounts()
,supportedCodecs()
,supportedSampleRates()
,supportedSampleSizes()
, andsupportedSampleTypes()
. The combinations supported are dependent on the platform, audio plugins installed and the audio device capabilities. If you need a specific format, you can check if the device supports it withisFormatSupported()
, or fetch a supported format that is as close as possible to the format withnearestFormat()
. For instance:QAudioFormat format; format.setSampleRate(44100); // ... other format parameters format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) format = info.nearestFormat(format);The static functions
defaultInputDevice()
,defaultOutputDevice()
, andavailableDevices()
let you get a list of all available devices. Devices are fetched according to the value of mode this is specified by the QAudio ::Mode enum. TheQAudioDeviceInfo
returned are only valid for the QAudio ::Mode.For instance:
const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); for (const QAudioDeviceInfo &deviceInfo : deviceInfos) qDebug() << "Device name: " << deviceInfo.deviceName();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 PySide2.QtMultimedia.QAudioDeviceInfo¶
PySide2.QtMultimedia.QAudioDeviceInfo(other)
- param other:
Constructs an empty
QAudioDeviceInfo
object.Constructs a copy of
other
.
- static PySide2.QtMultimedia.QAudioDeviceInfo.availableDevices(mode)¶
- Parameters:
mode –
Mode
- Return type:
Returns a list of audio devices that support
mode
.
- static PySide2.QtMultimedia.QAudioDeviceInfo.defaultInputDevice()¶
- Return type:
Returns the information for the default input audio device. All platform and audio plugin implementations provide a default audio device to use.
- static PySide2.QtMultimedia.QAudioDeviceInfo.defaultOutputDevice()¶
- Return type:
Returns the information for the default output audio device. All platform and audio plugin implementations provide a default audio device to use.
- PySide2.QtMultimedia.QAudioDeviceInfo.deviceName()¶
- Return type:
str
Returns the human readable name of the audio device.
Device names vary depending on the platform/audio plugin being used.
They are a unique string identifier for the audio device.
eg. default, Intel, U0x46d0x9a4
- PySide2.QtMultimedia.QAudioDeviceInfo.isFormatSupported(format)¶
- Parameters:
format –
PySide2.QtMultimedia.QAudioFormat
- Return type:
bool
Returns true if the supplied
settings
are supported by the audio device described by thisQAudioDeviceInfo
.
- PySide2.QtMultimedia.QAudioDeviceInfo.isNull()¶
- Return type:
bool
Returns whether this
QAudioDeviceInfo
object holds a valid device definition.
- PySide2.QtMultimedia.QAudioDeviceInfo.nearestFormat(format)¶
- Parameters:
format –
PySide2.QtMultimedia.QAudioFormat
- Return type:
Returns the closest
QAudioFormat
to the suppliedsettings
that the system supports.These settings are provided by the platform/audio plugin being used.
They are also dependent on the QAudio ::Mode being used.
- PySide2.QtMultimedia.QAudioDeviceInfo.__ne__(other)¶
- Parameters:
- Return type:
bool
Returns true if this
QAudioDeviceInfo
class represents a different audio device thanother
- PySide2.QtMultimedia.QAudioDeviceInfo.__eq__(other)¶
- Parameters:
- Return type:
bool
Returns true if this
QAudioDeviceInfo
class represents the same audio device asother
.
- PySide2.QtMultimedia.QAudioDeviceInfo.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 QAudio ::Mode being used.
A typical audio system would provide something like:
Input settings: 8000Hz mono 8 bit.
Output settings: 44100Hz stereo 16 bit little endian.
- PySide2.QtMultimedia.QAudioDeviceInfo.realm()¶
- Return type:
str
Returns the key that represents the audio plugin.
See also
QAudioSystemPlugin
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedByteOrders()¶
- Return type:
Returns a list of supported byte orders.
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedChannelCounts()¶
- Return type:
Returns a list of supported channel counts.
This is typically 1 for mono sound, or 2 for stereo sound.
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedCodecs()¶
- Return type:
list of strings
Returns a list of supported codecs.
All platform and plugin implementations should provide support for:
“audio/pcm” - Linear PCM
For writing plugins to support additional codecs refer to:
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedSampleRates()¶
- Return type:
Returns a list of supported sample rates (in Hertz).
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedSampleSizes()¶
- Return type:
Returns a list of supported sample sizes (in bits).
Typically this will include 8 and 16 bit sample sizes.
- PySide2.QtMultimedia.QAudioDeviceInfo.supportedSampleTypes()¶
- Return type:
Returns a list of supported sample types.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.