Unsolved record audio in ios and save as mpeg
-
Hi guys, I'm trying to implement the voice message feature in my app.
I have this issue. When I record the audio, the output file is of type .wav, which is really large (~1MB for only a few seconds)here is my code for the recording part:
mAudioRecorder->setAudioInput(mAudioRecorder->defaultAudioInput()); QAudioEncoderSettings mAudioEncoderSettings; mAudioEncoderSettings.setEncodingMode(QMultimedia::ConstantBitRateEncoding); mAudioEncoderSettings.setChannelCount(1); mAudioEncoderSettings.setCodec("audio/pcm"); // this is the only supported codec for iOS mAudioEncoderSettings.setSampleRate(16000); mAudioEncoderSettings.setBitRate(16000); mAudioRecorder->setEncodingSettings(mAudioEncoderSettings); mAudioRecorder->record();
after calling the
mAudioRecorder->stop();
method, I read the content of the saved audio:
QFile file; file.setFileName(path.toLocalFile()); // this is a .wav file if (!file.open(QIODevice::ReadOnly)) { return; } QByteArray fileContent(file.readAll()); qDebug() << fileContent.size(); if (fileContent.size() > 300 * 1024) { qDebug() << error file content out of limit"; }
I only want the file to be 1MB the largest. is there anyway I can convert the .wav to .mp4/aac/m4a output (which are smaller)?