Audio Recording from microphone to wav file in Qt
-
Hello, I am trying to do an application with the purpose of being able to record phrases and have them automatically saved in a chosen directory as wav files. For this I am trying to use the QAudioRecorder class. When I hit the record button I speak something into the microphone and .wav file gets saved into the directory that I chose with the name that I want but when I playback the file it is just noise. I don't think I am using the recording class properly.
What I have so far is :
@
void RecordingWidget::startRecording()
{
if(audioRecorder->state() == QMediaRecorder::StoppedState)
{//Set Audio Input audioRecorder->setAudioInput(audioRecorder->defaultAudioInput()); // Sets Output location where to store the file if(!m_outputLocationSet) setOutputLocation(); // Set recording Settings QAudioEncoderSettings settings; settings.setCodec("audio/amr"); // Not sure what to put here settings.setSampleRate(16000); settings.setBitRate(32); settings.setQuality(QMultimedia::HighQuality); settings.setEncodingMode(QMultimedia::ConstantQualityEncoding); audioRecorder->setEncodingSettings(settings); audioRecorder->record(); } else { stopRecording(); }
}
@
Any guidance greatly appreciated! Thanks.
-
Hi sergex.
Use "QAudioEncoderControl::supportedAudioCodecs":http://doc.qt.digia.com/qtmobility-1.2/qaudioencodercontrol.html first to find out which codec your system support.
One of this codec is responsible for wav.
Take this string an add with setCodec()Also check QAudioEncoderControl::supportedEncodingOptions for this codec to be sure the everything is set correctly.