我正在尝试使用Qt
c++
录制和保存音频文件,这是我的代码。
QAudioRecorder * audioRecorder = new QAudioRecorder();
if(audioRecorder->state() == audioRecorder->StoppedState)
{
// Set recording Settings
QAudioEncoderSettings settings;
settings.setCodec("audio/pcm"); // Not sure what to put here
settings.setSampleRate(16000);
settings.setBitRate(32);
settings.setQuality(QMultimedia::HighQuality);
settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);
audioRecorder->setEncodingSettings(settings);
//Set Audio Input
audioRecorder->setAudioInput(audioRecorder->defaultAudioInput());
// Sets Output location where to store the file
QUrl url("hello.wav");
audioRecorder->setOutputLocation(QUrl::fromLocalFile("hello.wav"));
audioRecorder->setContainerFormat("mp3");
audioRecorder->record();
qDebug()<<audioRecorder->state();
}
else
{
qDebug()<<"stopped";
}
但它不保存任何文件而是显示消息no service found for - "org.qt-project.qt.audiosource"
。
如何保存音频文件?