I'm on Windows 7 and I want to be able to access (read/write) the recording volume of the default audio input device.
In PyQt 5.7 the code below worked and audio.volume() returned the actual recording level (e.g. 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). 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 (e.g. "Microphone (Logitech USB Headse"). It makes sense to me that it returns "Default Input Device" as I asked for the default device.
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
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
To copy to clipboard, switch view to plain text mode
Bookmarks