Problem with QAudioRecorder



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • @SGaist
    i use Qt 5.2.1 under Ubuntu 14.04


  • Lifetime Qt Champion

    Can you test that with a more recent version of Qt e.g. 5.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

  • Lifetime Qt Champion

    Then you should check the bug report system


Log in to reply