资源简介
用QT写的简单的录音例子,简单易学,可以作为参考.
代码片段和文件信息
#include “audiorecorder.h“
#include
struct HEADER
{
char RIFFNAME[4];
unsigned long nRIFFLength;
char WAVNAME[4];
char FMTNAME[4];
unsigned long nFMTLength;
unsigned short nAudioFormat;
unsigned short nChannleNumber;
//unsigned short nSampleRate;
unsigned long nSampleRate;
unsigned long nBytesPerSecond;
unsigned short nBytesPerSample;
unsigned short nBitsPerSample;
char DATANAME[4];
unsigned long nDataLength;
};
AudioRecorder::AudioRecorder(QWidget *parent)
: QWidget(parent)
{
start = new QPushButton(tr(“start“));
stop = new QPushButton(tr(“stop“));
play = new QPushButton(tr(“play“));
save = new QPushButton(tr(“save“));
stop->setDisabled(true);
play->setDisabled(true);
save->setDisabled(true);
debugInfo = new QTextEdit();
QHBoxLayout *hlayout = new QHBoxLayout();
hlayout->addWidget(start);
hlayout->addWidget(stop);
hlayout->addWidget(play);
hlayout->addWidget(save);
// QHBoxLayout *hlayout1 = new QHBoxLayout();
QVBoxLayout *layout = new QVBoxLayout();
layout->addLayout(hlayout);
layout->addWidget(debugInfo);
this->setLayout(layout);
outputFile = new QFile();
outputFile->setFileName(tr(“record.raw“));
format.setFrequency(8000);
format.setChannels(1);
format.setSampleSize(16);
format.setSampleType(QAudioFormat::SignedInt);
format.setByteOrder(QAudioFormat::LittleEndian);
format.setCodec(“audio/pcm“);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
if (!info.isFormatSupported(format)) {
qWarning(“input default format not supported try to use nearest“);
format = info.nearestFormat(format);
}
QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
if (!info1.isFormatSupported(format)) {
qWarning() << “output default format not supported - trying to use nearest“;
// format = info.nearestFormat(m_format);
qWarning() << “output no support input format.“;
return;
}
if(format.sampleSize() != 16) {
qWarning(“audio device doesn‘t support 16 bit support %d bit samples example cannot run“ format.sampleSize());
audioInput = 0;
return;
}
audioInput = NULL;
audioOutput = NULL;
connect(start SIGNAL(clicked()) thisSLOT(recordStart()));
connect(stop SIGNAL(clicked()) thisSLOT(recordStop()));
connect(play SIGNAL(clicked()) thisSLOT(recordPlay()));
connect(save SIGNAL(clicked()) thisSLOT(recordSave()));
}
AudioRecorder::~AudioRecorder()
{
}
void AudioRecorder::recordStart()
{
outputFile->open(QIODevice::WriteOnly | QIODevice::Truncate);
audioInput = new QAudioInput(format this);
audioInput->start(outputFile);
debugInfo->append(tr(“start record!“));
start->setDisabled(true);
stop->setDisabled(false);
play-
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6998 2010-08-26 11:49 audioRecorder\audiorecorder.cpp
文件 818 2010-08-26 11:30 audioRecorder\audiorecorder.h
文件 578 2010-08-26 17:08 audioRecorder\audioRecorder.pro
文件 14336 2014-07-05 09:51 audioRecorder\audioRecorder.pro.user
文件 255 2010-08-24 15:41 audioRecorder\main.cpp
目录 0 2014-07-05 09:52 audioRecorder
----------- --------- ---------- ----- ----
22985 6
- 上一篇:易语言源码易语言小说在线提取源码.rar
- 下一篇:老男孩运维58期视频.txt
相关资源
- 997783QTableWidget表头添加复选框.zip
- qt_multicast.tar.gz
- QT5 雷达扫描效果代码
- QQLogin.ui
- 数据结构课程设计--校园最短路径
- Qt使用QGraphicsView实现滑动窗体效果
- opencv与qt结合使用的(亲测可用)
- QT实现的五子棋
- VC 可支持声卡输入输出声音同时录音
- Qt 之 实现简单截图功能二
- Qt 之 实现简单截图功能一
- Qt 之 HTTP 请求支持断点续传
- AUTO_CAD.rar
- PyQt5 tutorial PyQt5教程英文版
- qtsoap-2.7_1
- linux Qt局域网聊天
- Qt 多线程及简单 demo
- Qt实现的FlatUI样式
- Qt编写视频监控画面分割界面
- windows平台抓屏源代码
- CSDN-TCP基于数据包通讯框架
- QT5线程QThread使用
- 基于Qt的声波图形界面动态绘制
- Qt单机斗地主
- 智能小车QT远程客户端
- 视频小车QT客户端
- qt实现n皇后问题带界面
- QRGenerator.zip
- STDLIB.H头文件
- WidgetTimeline.zip
评论
共有 条评论