其他分享
首页 > 其他分享> > qt实现录音和播放录音

qt实现录音和播放录音

作者:互联网

代码


    QAudioProbe *audioProbe;
    QAudioRecorder *audioRecorder;
    QMediaPlayer *audioPlayer;

    QString m_location;

    m_location = "/tmp/t.wav";
    audioRecorder = new QAudioRecorder(this);
    qDebug() << "support codecs:" << audioRecorder->supportedAudioCodecs();
    qDebug() << "support containers:" << audioRecorder->supportedContainers();

    QAudioEncoderSettings audioSettings;
    audioSettings.setQuality(QMultimedia::HighQuality);

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
    audioRecorder->setAudioSettings(audioSettings);
    audioRecorder->setContainerFormat("audio/x-wav");
#else
    audioSettings.setCodec("audio/PCM");
    audioRecorder->setAudioSettings(audioSettings);
    audioRecorder->setContainerFormat("wav");
#endif

    audioProbe = new QAudioProbe(this);
    audioProbe->setSource(audioRecorder);
    audioPlayer = new QMediaPlayer();

// 开始录音
	audioRecorder->pause();
// 结束录音
	audioRecorder->stop();
// 播放录音
	
    QMediaPlayer *audioPlayer;
    audioPlayer->setMedia(QUrl::fromLocalFile(m_location));
    audioPlayer->play();

标签:audioRecorder,qt,audioPlayer,QMediaPlayer,录音,location,audioSettings,播放
来源: https://blog.csdn.net/qq_32768743/article/details/89047902