Results 1 to 2 of 2

Thread: How to access audio recording volume in PyQt 5.9?

  1. #1
    Join Date
    Jul 2017
    Posts
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default 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.

    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.

    Qt Code:
    1. import PyQt5.QtCore
    2. from PyQt5 import QtMultimedia
    3.  
    4. PyQt5.QtCore.PYQT_VERSION_STR # '5.9'
    5.  
    6. audioFormat = QtMultimedia.QAudioFormat()
    7. audioFormat.setChannelCount(1)
    8. audioFormat.setSampleRate(16000)
    9. audioFormat.setSampleSize(16)
    10. audioFormat.setCodec("audio/pcm")
    11. audioFormat.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
    12. audioFormat.setSampleType(QtMultimedia.QAudioFormat.SignedInt)
    13.  
    14. info = QtMultimedia.QAudioDeviceInfo.defaultInputDevice()
    15.  
    16. info.deviceName() # 'Default Input Device'
    17. audio = QtMultimedia.QAudioInput(info, audioFormat)
    18. audio.volume() # 0.0
    19.  
    20. info.isFormatSupported(audioFormat) # True
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2017
    Posts
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: How to access audio recording volume in PyQt 5.9?

    It looks like this change in behavior was introduced with this commit.

    To restore the old behavior in new Qt versions (5.8+): get the list of all input devices and take the first one. 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.

Similar Threads

  1. Recording audio stream
    By c1223 in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2013, 21:23
  2. Audio Recording from microphone in Qt
    By Sergex in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2013, 10:46
  3. mp3 audio recording
    By dhe in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2012, 10:00
  4. Audio Recording in qt
    By BalaQT in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2009, 09:01
  5. Audio Recording with Phonon
    By Nemo in forum Qt Programming
    Replies: 4
    Last Post: 12th June 2008, 06:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.