Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QAudioRecorder
QtWS25 Last Chance

Problem with QAudioRecorder

Scheduled Pinned Locked Moved General and Desktop
qt 5.2.1audio
6 Posts 2 Posters 3.0k Views
  • 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.
  • H Offline
    H Offline
    helenebro
    wrote on last edited by helenebro
    #1

    Hi,
    I have an app where I record sound when I press a button. When I release the button, record must stop.
    Behavior of QAudioRecorder seems to be an errors.
    If I have understood,

    • when I execute QAudioRecorder::record(), QAudioRecorder go from LoadedStatus to StartingStatus and automatically to RecordingStatus
    • when I execute QAudioRecorder::stop() (and QAudioRecorder is during recording process) , QAudioRecorder go from RecordingStatus to FinalizingStatus and automatically to LoadedStatus.

    But sometimes, when I start record, QAudioRecorder stay on StartingStatus and when I stop record, QAudioRecorder stay on FinalizingStatus.
    Have you an idea of the problem ?

    #include "voicerecorder.h"
    
    #include <QAudioDeviceInfo>
    
    VoiceRecorder::VoiceRecorder(QObject *parent) :
        QObject(parent),
        myAudioRecorder(0),
        b_recording(false),
        pathAudioFile("")
    {
    	createAudioRecorder();
    }
    
    VoiceRecorder::~VoiceRecorder()
    {
        delete myAudioRecorder;
    }
    
    void VoiceRecorder::createAudioRecorder()
    {
        qDebug()<<"createAudioRecorder";
        myAudioRecorder= new QAudioRecorder(this);
        connect(myAudioRecorder, SIGNAL(statusChanged(QMediaRecorder::Status)), this, SLOT(displayStatus(QMediaRecorder::Status)));
        pathAudioFile = QDir::currentPath();
        pathAudioFile+="/audio.flac";
        myAudioRecorder -> setOutputLocation ( QUrl(pathAudioFile));
        QAudioEncoderSettings audioSettings;
        audioSettings.setCodec("audio/FLAC");
        myAudioRecorder->setEncodingSettings(audioSettings);
    }
    
    void VoiceRecorder::switchStateMicro()
    {
        qDebug()<<"switchStateMicro()"<<b_recording;
        if(b_recording) {
    	stopAudio();
        }
        else {
    	recordAudio();
        }
    }
    
    void VoiceRecorder::recordAudio()
    {
        qDebug()<<"recordAudio"<<myAudioRecorder->status();
        if(myAudioRecorder->status() ==  QMediaRecorder::LoadedStatus) {
    	myAudioRecorder->record();
        }
    }
    
    
    void VoiceRecorder::stopAudio()
    {
        qDebug()<<"stopAudio"<<myAudioRecorder->status();
        if(myAudioRecorder->status() ==  QMediaRecorder::RecordingStatus) {
    	myAudioRecorder->stop();
          //Do something
        }
    }
    
    void VoiceRecorder::displayStatus(QMediaRecorder::Status status)
    {
        qDebug()<<" myAudioRecorder status"<<status;
        if(myAudioRecorder->status()==QMediaRecorder::RecordingStatus){
    	b_recording= true;
        }else {
    	b_recording= false;
        }
        emit recordingChanged(b_recording);
    }
    
    #ifndef VOICERECORDER_H
    #define VOICERECORDER_H
    
    #include <QObject>
    #include <QUrl>
    #include <QDebug>
    #include <QAudioRecorder>
    
    class VoiceRecorder : public QObject
    {
      Q_OBJECT
    public:
      explicit VoiceRecorder(QObject *parent = 0);
        ~VoiceRecorder();
        void createAudioRecorder();
    
    signals:
        void recordingChanged (bool );
    
    public slots:
        void switchStateMicro();
        void recordAudio( );
        void stopAudio( );
        void displayStatus(QMediaRecorder::Status status);
    private:
        QAudioRecorder *myAudioRecorder;
        bool b_recording;
        QString pathAudioFile;
    };
    
    #endif // VOICERECORDER_H
    

    Thank you for your help

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

      Hi,

      You should also add which version of Qt you are using as well as OS

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

      H 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should also add which version of Qt you are using as well as OS

        H Offline
        H Offline
        helenebro
        wrote on last edited by
        #3

        @SGaist
        i use Qt 5.2.1 under Ubuntu 14.04

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

          Can you test that with a more recent version of Qt e.g. 5.5 ?

          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
          • H Offline
            H Offline
            helenebro
            wrote on last edited by helenebro
            #5

            I have tried with Qt 5.5.0 and I have the same problem :

            -> request record 
            new status QMediaRecorder  QMediaRecorder::StartingStatus
            new status QMediaRecorder  QMediaRecorder::RecordingStatus
            ->  request stop record 
            new status QMediaRecorder  QMediaRecorder::FinalizingStatus
            new status QMediaRecorder  QMediaRecorder::LoadedStatus
            
            -> request record 
            new status QMediaRecorder  QMediaRecorder::StartingStatus
            new status QMediaRecorder  QMediaRecorder::RecordingStatus
            -> request stop record 
            new status QMediaRecorder  QMediaRecorder::FinalizingStatus
            
            -> request record but problem
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then you should check the bug report system

              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