I want to record my voice over microphone. I call a c++ function from qml to record my voice. I use AudioRecorder to record.
The problem is that my phone always records mp4 files. I want another encoding, not mp4. For example mp3 or wav.
My code is the following:
audio = new QAudioRecorder(this); QAudioEncoderSettings audioSettings; audioSettings.setQuality(QMultimedia::HighQuality); audioSettings.setCodec("audio/raw"); audioSettings.setSampleRate(96000); audio->setEncodingSettings(audioSettings); audio->setOutputLocation(QUrl::fromLocalFile("/mnt/sdcard/test.wav")); audio->record();
The output file is test.wav.mp4.
@NickV What phone are you recording from? Your options will be limited by what's available on your hardware. Look at the following for information on how to obtain the available codecs for your device
The only available is audio/pcm.
My phone is samsung core prime 2. I figured out that only mp4 i can record. But with QAudioEncoderSettings i set the lower quality in order to have small size files. So everything is ok. Thanks for your reply.
The 'QAudioRecorder::setEncodingSettings' method takes 3 parameters: 'const QAudioEncoderSettings & audio', 'const QVideoEncoderSettings & video', and 'const QString & container'.
The codec you defined does not define the type of file that will recorded. This is done by the 'container' parameter.
If you let it undefined, the OS will choose what ever it wants. My experience is that on iOS it chooses "wav", while on Android it chooses "mp4".
So, I know 3 ways: you can set the value of 'container', and hope it works on your device; you can leave it to the OS, as I said above; you can examine the 'QStringList QAudioRecorder::supportedContainers() const', and choose one.
Oh, the 'video' parameter I use 'QVideoEncoderSettings()' default constructor.