Recording Audio Using QtAudioRecorder
-
Hi everyone,
im trying to use the QtAudioRecorder to record some simple soundfiles. But I've discovered a few problems.
First if I'm trying to use it like in the example it keeps showing an error like:
"Could not create a media muxer element: "" "
It's always the same error even if i switch the codec.
However there's a workaround for that error. It dissapears when im not using
@audioSettings.setCodec("audio/wav");@If i dont use the codec im able to take up to 3 records stored correctly in a .wav file (Sometimes i can take only 1 record, then again it's 2 or 3... I can't discover any regularity in it). But then the programm freezes when I'm using:
@audioRecorder->stop();@My Code:
@
QAudioRecorder *audioRecorder; //Class memberaudioRecorder = new QAudioRecorder(this);
audioRecorder->setAudioInput(audioRecorder->defaultAudioInput());
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/wav");
audioSettings.setSampleRate(16000);
audioSettings.setBitRate(32);
audioSettings.setQuality(QMultimedia::HighQuality);
audioSettings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
audioRecorder->setEncodingSettings(audioSettings);
audioRecorder->setOutputLocation(QUrl::fromLocalFile("Test.wav"));//start Recording
if (audioRecorder->state() == QMediaRecorder::StoppedState)
{
audioRecorder->record();
}//stop Recording
if (audioRecorder->state() == QMediaRecorder::RecordingState)
{
audioRecorder->stop();
}
@My OS is Debian 7.
Any help is appreciated! Thanks in advance.
Lucas
-
This post is quite old, but I had a similar problem and solved it, so here is what I did. The problem was that I had to define both the codec and the container. The latter is necessary to create the muxer element, and the former has to be a string as defined in the Qt code (so I had to use "audio/PCM"; it did not work with "audio/wav" or "audio/pcm"):
audioSettings.setCodec("audio/PCM"); ... audioRecorder->setContainerFormat("wav");
I could then record into a WAV file.
-
Absolutely!