QAudioRecorder detect user not speaking and stop



  • I want to use QAudioRecorder to record audio from user and then use audio file for speech to text. I could successfully run and record audio from this example, http://doc.qt.io/qt-5/qtmultimedia-multimedia-audiorecorder-example.html

    But my problem is, I want to while QAudioRecorder is actively recording audio, I need to detect if user stopped speaking audio. So QAudioRecorder should only stop when user is not speaking.

    I could stop QAudioRecorder for fixed seconds using QTimer as below,

    void AudioRecorder::toggleRecord()
    {
        if (audioRecorder->state() == QMediaRecorder::StoppedState) {
            audioRecorder->setAudioInput(boxValue(ui->audioDeviceBox).toString());
    
            QAudioEncoderSettings settings;
            settings.setCodec(boxValue(ui->audioCodecBox).toString());
            settings.setSampleRate(boxValue(ui->sampleRateBox).toInt());
            settings.setBitRate(boxValue(ui->bitrateBox).toInt());
            settings.setChannelCount(boxValue(ui->channelsBox).toInt());
            settings.setQuality(QMultimedia::EncodingQuality(ui->qualitySlider->value()));
            settings.setEncodingMode(ui->constantQualityRadioButton->isChecked() ?
                                     QMultimedia::ConstantQualityEncoding :
                                     QMultimedia::ConstantBitRateEncoding);
    
            QString container = boxValue(ui->containerBox).toString();
    
            audioRecorder->setEncodingSettings(settings, QVideoEncoderSettings(), container);
            audioRecorder->record();
            this->recordTimeout();
        }
        else {
            this->stopRecording();
        }
    }
    
    void AudioRecorder::recordTimeout()
    {
        QTimer* mTimer = new QTimer(this);
        mTimer->setSingleShot(true);
        connect(mTimer, SIGNAL(timeout()), SLOT(stopRecording()));
        mTimer->start(6000);
    }
    
    void AudioRecorder::stopRecording()
    {
        audioRecorder->stop();
    }
    
    

    But instead of this it should stop recording when user is not speaking. As per my guessing, QAudioProbe class has this signal audioBufferProbed(QAudioBuffer) which may be helpful to check level of audio but I don't know how to use it and what level can be used to detect user is not speaking.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You have an example on how to use QAudioProbe in the detailed documentation of the class. As for measuring the level of a silent user, it's a completely other topic, you'll have to take into account the noise of the environment of the user.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.