我想创建一个小工具来录制音频,在录制过程中,录制过程中有很多额外的噪音



谢谢你看到: 开发环境:QT、视窗 问题:我想创建一个小工具来录制音频,在录制过程中,录制过程中有很多额外的噪音。为什么?你可以帮我吗?

function: init()
{
outputFile.setFileName("test.raw");
outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
QAudioFormat format;
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(8);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
if (!info.isFormatSupported(format))
{
qWarning()<<"default format not supported try to use nearest";
format = info.nearestFormat(format);
}
audio = new QAudioInput(info, format, this);
QTimer::singleShot(10000, this, SLOT(stopRecording()));
audio->start(&outputFile);
qDebug() <<"record begin!";
}
function: stopRecording()
{
audio->stop();
outputFile.close();
delete audio;
qDebug() <<"record end!";
}

录制音频,您必须确保QT设置与您的系统设置相同。

首先:你需要记录什么? 麦克风或系统声音。 其次:设置它的格式

喜欢:

QAudioFormat format;
format.setSampleRate(8000);
format.setChannelCount(1);
format.setSampleSize(16);

最新更新