PySide6.QtMultimedia.QAudioDevice¶
- class QAudioDevice¶
QAudioDevice类提供了关于音频设备及其功能的信息。更多…概要¶
属性¶
方法¶
def
__init__()def
description()def
id()def
isDefault()def
isNull()def
mode()def
__ne__()def
__eq__()def
swap()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
警告
本节包含从C++自动翻译到Python的代码片段,可能包含错误。
QAudioDevice描述了系统中可用的音频设备,无论是用于输入还是播放。Qt 使用
QAudioDevice来构建与设备通信的类,例如QAudioSource和QAudioSink。它还用于确定在捕获会话或媒体播放期间使用的输入或输出设备。您还可以查询每个设备支持的格式。在这种情况下,格式是由通道数、采样率和采样类型组成的一组。格式由
QAudioFormat类表示。设备支持的每个参数的值可以通过
minimumChannelCount()、maximumChannelCount()、minimumSampleRate()、maximumSampleRate()和supportedSampleFormats()获取。支持的组合取决于音频设备的能力。如果你需要特定的格式,你可以使用isFormatSupported()检查设备是否支持它。例如: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)
可以从
QMediaDevices类中检索可用的设备集。例如:
devices = QMediaDevices.audioOutputs() for device in devices: print("Device: ", device.description())
在此代码示例中,我们遍历所有能够输出声音的设备,即播放支持格式的音频流。对于找到的每个设备,我们只需打印deviceName()。
- class Mode¶
描述此设备的模式。
常量
描述
QAudioDevice.Null
一个空设备。
QAudioDevice.Input
一个输入设备。
QAudioDevice.Output
一个输出设备。
注意
当使用
from __feature__ import true_property时,属性可以直接使用,否则通过访问器函数使用。- property descriptionᅟ: str¶
返回音频设备的人类可读名称。
使用此字符串向用户展示设备。
- Access functions:
- property idᅟ: QByteArray¶
返回音频设备的标识符。
设备名称根据所使用的平台/音频插件而有所不同。
它们是音频设备的唯一标识符。
- Access functions:
- property isDefaultᅟ: bool¶
如果这是默认的音频设备,则返回 true。
- Access functions:
- property modeᅟ: QAudioDevice.Mode¶
返回此设备是输入设备还是输出设备。
- Access functions:
- __init__()¶
构造一个空的
QAudioDevice对象。- __init__(other)
- Parameters:
其他 –
QAudioDevice
构造
other的副本。- channelConfiguration()¶
- Return type:
返回设备的通道配置。
- description()¶
- Return type:
字符串
属性
descriptionᅟ的获取器。- id()¶
- Return type:
属性
idᅟ的获取器。- isDefault()¶
- Return type:
布尔
属性
isDefaultᅟ的获取器。- isFormatSupported(format)¶
- Parameters:
格式 –
QAudioFormat- Return type:
布尔
如果此
QAudioDevice描述的音频设备支持提供的settings,则返回true。- isNull()¶
- Return type:
布尔
返回此
QAudioDevice对象是否包含有效的设备定义。- maximumChannelCount()¶
- Return type:
整数
返回支持的最大通道数。
这通常是1表示单声道,或2表示立体声。
- maximumSampleRate()¶
- Return type:
整数
返回支持的最大采样率(以赫兹为单位)。
- minimumChannelCount()¶
- Return type:
整数
返回支持的最小通道数。
这通常是1表示单声道,或2表示立体声。
- minimumSampleRate()¶
- Return type:
整数
返回支持的最小采样率(以赫兹为单位)。
属性
modeᅟ的获取器。- __ne__(other)¶
- Parameters:
其他 –
QAudioDevice- Return type:
布尔
如果此
QAudioDevice类表示与other不同的音频设备,则返回true- __eq__(other)¶
- Parameters:
其他 –
QAudioDevice- Return type:
布尔
如果此
QAudioDevice类表示与other相同的音频设备,则返回true。- preferredFormat()¶
- Return type:
返回此设备的默认音频格式设置。
这些设置由所使用的平台/音频插件提供。
它们也依赖于使用的QtAudio ::Mode。
一个典型的音频系统会提供类似以下内容:
输入设置:48000Hz 单声道 16 位。
输出设置:48000Hz 立体声 16 位。
- supportedSampleFormats()¶
- Return type:
返回支持的样本类型列表。
- swap(other)¶
- Parameters:
其他 –
QAudioDevice
将音频设备与
other交换。