Setting encoding format [solved]

  • Hi everyone,

    I'm trying to save in a file my microphone output in a certain format (to be used by the speech recognition library CMU sphinx). The format has to be a single-channel (monaural), little-endian, unheadered 16-bit signed PCM audio file sampled at 16000 Hz.

    I'm currently using these parameters:
    @ QAudioEncoderSettings settings;

    The only thing I managed so far is setting it in 16 kHz.
    I thought that using settings.setBitRate(16) would produce a 16bit file but audacity tells me that the file is 32bit and stereo.
    And about the other parameters, I don't even know how to check them (is it single-channel ? monaural ? PCM ?...)

    Can somebody help me to understand these QAudioEncoderSettings methods ?

    Thank you !

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You don't seem to set the channelCount to 1

    Hope it helps

  • Ah !! Yes indeed, now I get a monaural format. Thank you !

    I still have a sample size of 32 bit instead of 16.
    By playing with the audiorecorder example I noticed that the codecs
    audio/vorbis and audio/FLAC produce 16bit sample sizes while audio/PCM produce 32bit sample sizes.
    Is it something fixed for each codec or can it be changed ?

  • Lifetime Qt Champion

    AFAIK, it should not be fixed, what OS/Qt Version are you on ?

  • I am running under Lubuntu 64 bit with Qt 5.1.1
    I finally solved the problem by using QAudioInput instead of an QAudioRecorder object. This allowed me to set my settings via QAudioFormat instead of QAudioEncoderSettings. A difference between the two classes is that the latest has a method setSampleSize. I posted a sample code here:

  • Lifetime Qt Champion

    I have overlooked QAudioRecorderSettings, the sample size is indeed not there. I don't know if it's missing on purpose or not. You could ask on the interest mailing list if you would like to know more

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.