0
我正在嘗試使用Qt
c++
來錄製和保存音頻文件,這裏是我爲此目的的代碼。如何在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"
。 如何保存音頻文件?
感謝@trivelt,您提供的源代碼非常難以開始。你能建議任何初學者級別的資源嗎? –
嗯,你使用哪種操作系統和Qt版本? – trivelt
我使用的是Ubuntu 16.04,QT版本是5.7。 @trivelt –