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. QAudioRecorder create file
Forum Updated to NodeBB v4.3 + New Features

QAudioRecorder create file

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

    Hi,
    I use QAudioRecorder to get level of audio input. When I start record, a file "test.wav" is created. At the end of the application, I stop record and I want delete this file. But I can't delete it, it's seems file isn't foud.

    
    #include "testlevelaudio.h"
    #include <QDir>
    #include <QAudioFormat>
    #include <QAudioDeviceInfo>
    #include <QUrl>
    TestLevelAudio::TestLevelAudio(QObject *parent) : QObject(parent), m_microIsOn(false)
    {
        createAudioRecorder();
    }
    
    TestLevelAudio::~TestLevelAudio()
    {
        stopAudio();
        endRecordAudio();
    }
    
    void TestLevelAudio::createAudioRecorder()
    {
        m_audioRecorder = new QAudioRecorder(this);
        m_audioRecorder->setOutputLocation(QUrl::fromLocalFile(("test.wav")));
    	QAudioEncoderSettings settings;
        settings.setSampleRate(8000);
        settings.setChannelCount(1);
        settings.setCodec("audio/PCM");
        m_audioRecorder->setEncodingSettings(settings);
        m_audioRecorder->setContainerFormat("wav");
        qDebug()<<"audio recorder avec settings";
    
        m_audioProbe = new QAudioProbe(this);
        if(m_audioProbe->setSource(m_audioRecorder)) {
            connect(m_audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)),
                    this, SLOT(calculateLevel(QAudioBuffer)));
        }
        m_audioRecorder->record();
    }
    
    void TestLevelAudio::stopAudio()
    {
        qDebug()<<"stop audioInput"<<audioInput->state();
        if(audioInput->state() == QAudio::ActiveState) {
            audioInput->stop();
            outputFile->close();
        }
    }
    
    void TestLevelAudio::endRecordAudio()
    {
        if(m_audioRecorder->state() == QMediaRecorder::RecordingState) {
            qDebug()<<"demande d'arret";
            m_audioRecorder->stop();
            QFile fileToSupp((QUrl("test.wav")).toLocalFile());
            if(fileToSupp.exists())
    			fileToSupp.remove();
            else qDebug()<<"file doesn't exist";
        }
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      Can you try if specifying an absolute path fixes the problem? My guess is that it's a working directory problem.
      Change "test.wav" into something like QDir::tempPath() + "/test.wav" in both createAudioRecorder and endRecordAudio

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3

      • Login

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