首页 > 代码库 > Qt录音机
Qt录音机
最近做项目, 需要一个麦克风音量监听的功能:
找了好多这方面的资料, 不知道为什么 总之很少,
在此总结一下, 发贴一枚..
\
不啰嗦了, 直接上代码了:
#ifndef AUDIORECORDER_H #define AUDIORECORDER_H #include <QFile> #include <QWidget> #include <QPushButton> #include <QAudioInput> #include <QAudioOutput> #include <QAudioDeviceInfo> #include "ui_AudioRecorder.h" class AudioRecorder : public QWidget { Q_OBJECT public: AudioRecorder(QWidget *parent = 0); ~AudioRecorder(); private: int AddWavHeader(char *); int ApplyVolumeToSample(short iSample); void InitMonitor(); void CreateAudioInput(); void CreateAudioOutput(); private slots: void OnRecordStart(); void OnRecordStop(); void OnRecordPlay(); void OnRecordSave(); void OnStateChange(QAudio::State s); void OnReadMore(); void OnSliderValueChanged(int); void OnTimeOut(); private: Ui::Recorder ui; int miVolume; int miMaxValue; private: QAudioFormat mFormatFile; QFile *mpOutputFile; QAudioInput *mpAudioInputFile; // 负责读写文件 QAudioOutput *mpAudioOutputFile; QAudioFormat mFormatSound; QAudioInput *mpAudioInputSound; // 负责监听声音 QAudioOutput *mpAudioOutputSound; QIODevice *mpInputDevSound; QIODevice *mpOutputDevSound; }; #endif // AUDIORECORDER_H
#include "AudioRecorder.h" #include <QLayout> #include <QDebug> #include <QTimer> #include <QFileDialog> #include <QMessageBox> #define BufferSize 14096 struct HEADER { char RIFFNAME[4]; unsigned long nRIFFLength; char WAVNAME[4]; char FMTNAME[4]; unsigned long nFMTLength; unsigned short nAudioFormat; unsigned short nChannleNumber; unsigned long nSampleRate; unsigned long nBytesPerSecond; unsigned short nBytesPerSample; unsigned short nBitsPerSample; char DATANAME[4]; unsigned long nDataLength; }; AudioRecorder::AudioRecorder(QWidget *parent) : QWidget(parent) { ui.setupUi(this); miMaxValue = http://www.mamicode.com/0;>
代码已上传: http://download.csdn.net/detail/robertkun/7421767
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。