How to record the voice in qt 4.8
-
Hi
I'm trying to record the voice with Qt in BBB.
I'm wondering How can I do that I use this code :#include <QApplication> #include <QtGui> #include <QTextEdit> #include <QtMultimedia/qaudioinput.h> QFile outputFile; QAudioInput *audioInput; void StartRecording(); int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *textEdit=new QTextEdit; QPushButton *quitButton=new QPushButton("&Quit"); QObject::connect(quitButton,SIGNAL(clicked()),qApp,SLOT(quit())); QVBoxLayout *layout=new QVBoxLayout; layout->addWidget(textEdit); layout->addWidget(quitButton); QWidget window; window.setLayout(layout); window.show(); StartRecording(); return app.exec(); } void StartRecording() { outputFile.setFileName("/tmp/test.raw"); outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate); QAudioFormat format; format.setFrequency(8000); format.setChannels(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); } audioInput=new QAudioInput(format,this); QTimer::singleShot(3000,this,SLOT(stopRecording())); audioInput->start(&outputFile); } void stopRecording() { audioInput->stop(); outputFile.close(); delete audioInput; }
I'm calling
startRecording();
in my main.
but I have these error:
1-invalid use of "this" in none-member function
audioInput=new QAudioInput(format,this);
2-invalid use of "this" in none-member function
QTimer::singleshot(3000,this,SLOT(stopRecording()));if I remove these two lines,+ audioInput ->start(&outputFile);
I get this warning:
Default format not supported try to use nearest
and the file test.raw in tmp folder is seems empty and nothing there.
Please tell me which part of my code is wrong
Thank you
Iman -
Hi,
Start and stop recording are not slots nor objects, they are static functions. You need write a QObject based class to encapsulate these functionalities
-
@SGaist
Thank you for your reply.
Since I'm new in C++ and Qt could you give a good tutorial and link to show how can I do that ?
Thank you in advance
Iman -
Qt's documentation about signals and slots is a good starting point