简体   繁体   English

如何在PyQt 5.9中访问录音音量?

[英]How to access audio recording volume in PyQt 5.9?

I'm on Windows 7 and I want to be able to access (read/write) the recording volume of the default audio input device. 我在Windows 7上,并且希望能够访问(读/写)默认音频输入设备的录制音量。

In PyQt 5.7 the code below worked and audio.volume() returned the actual recording level (eg 0.8). 在PyQt 5.7中,下面的代码有效,并且audio.volume()返回了实际的录音电平(例如0.8)。 In PyQt 5.8.2 and 5.9 the approach below does not work anymore and it always returns 0.0 (and I'm also not able to change the level). 在PyQt 5.8.2和5.9中,以下方法不再起作用,并且始终返回0.0(并且我也无法更改该级别)。 One difference I noticed is that 5.8 and 5.9 have the audio input device name "Default Input Device", while in 5.7 it was the actual (truncated) device name (eg "Microphone (Logitech USB Headse"). It makes sense to me that it returns "Default Input Device" as I asked for the default device. 我注意到的一个区别是5.8和5.9的音频输入设备名称为“ Default Input Device”(默认输入设备),而在5.7中,它是实际的(被截断的)设备名称(例如“ Microphone(Logitech USB Headse)”)。当我要求默认设备时,它将返回“默认输入设备”。

import PyQt5.QtCore
from PyQt5 import QtMultimedia

PyQt5.QtCore.PYQT_VERSION_STR  # '5.9'

audioFormat = QtMultimedia.QAudioFormat()
audioFormat.setChannelCount(1)
audioFormat.setSampleRate(16000)
audioFormat.setSampleSize(16)
audioFormat.setCodec("audio/pcm")
audioFormat.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
audioFormat.setSampleType(QtMultimedia.QAudioFormat.SignedInt)

info = QtMultimedia.QAudioDeviceInfo.defaultInputDevice()

info.deviceName()  # 'Default Input Device'
audio = QtMultimedia.QAudioInput(info, audioFormat)
audio.volume()  # 0.0

info.isFormatSupported(audioFormat)  # True

Questions I have: 我有问题:

  • Is this a bug? 这是错误吗? If so, where can I report it? 如果是这样,我可以在哪里报告?
  • How should I be accessing the audio input volume level? 我应该如何访问音频输入音量?

It looks like this change in behavior was introduced with this commit . 看起来这种行为更改是通过此commit引入的。

To restore the old behavior in new Qt versions (5.8+): get the list of all input devices and take the first one. 要在新的Qt版本(5.8+)中恢复旧的行为,请执行以下操作:获取所有输入设备的列表,并获取第一个。 This is the exact same as what the previous implementation of the default device function did. 这与默认设备功能的先前实现完全相同。 On Windows 7 the first device in the list is always the default device. 在Windows 7上,列表中的第一个设备始终是默认设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM