Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to record the voice in qt 4.8
Qt 6.11 is out! See what's new in the release blog

How to record the voice in qt 4.8

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imanpakii
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        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

        I Offline
        I Offline
        imanpakii
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Qt's documentation about signals and slots is a good starting point

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved