Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. To Record audio and store it in a location and play it again?
Forum Updated to NodeBB v4.3 + New Features

To Record audio and store it in a location and play it again?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 3.9k 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.
  • N Offline
    N Offline
    Naufal
    wrote on last edited by
    #1

    Hi All,
    I am trying to work out a prog with 3 buttons in qml,one for recording an audio,another for stopping and another for playing it. I need to record the audio and store them in a location(path) and retrieve it for playing it again.
    I have seen these links but could not find any solution from it.

    Link 1":http://doc.qt.nokia.com/qtmobility-1.2/multimedia.html "
    using this link i am not able to get any idea to proceed..

    I have seen this similar forum":http://developer.qt.nokia.com/forums/viewthread/14278/ "

    But none replied i guess. I am expecting some solutions regarding this !!!
    Can anyone help me in sorting out..

    Regards,
    Naufal.A

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      I have fixed the links in your post. They were borken. Apparently, you have typed/pasted the link and then marked it before pressing the link button. This is meant for explanatory text handling. The link should be introduced in the link message box.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        batosai
        wrote on last edited by
        #3

        check out the qt example "spectrum analyser" what u r asking for is a part of that example

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Naufal
          wrote on last edited by
          #4

          Hi, Thanks for your reply..I will check that out and tell you in sometime as i am new to qml,needs some time to go through and tell you...

          Regards,
          Naufal.A

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Naufal
            wrote on last edited by
            #5

            Hi All,

               I cannot Understand spectrum properly batosai..so i am trying this
              I have checked this "link":http://www.qtforum.org/article/35565/audio-recorder.html?s=e744e7b5ed0e159046adc10a548aa194cd2349c6 and tried some functions from those. Now i am able to play the song.. I cannot able to stop and also cannot record the song or voice on my own.Here is my code.
            

            AudioBuffer.cpp
            @
            #include "AudioBuffer.h"
            #include <QAudio>
            #include <QMediaPlayer>
            #include <QAudioCaptureSource>
            #include <QAudioInput>
            #include <QAudiooutput>
            #include <QAudioCaptureSource>
            #include <QMediaRecorder>

            AudioBuffer::AudioBuffer()
            {
            audioSource = new QAudioCaptureSource();
            capture = new QMediaRecorder(audioSource);

            QAudioEncoderSettings es;
            es.setCodec("audio/mp3");
            es.setSampleRate(96000);
            capture->setEncodingSettings(es);
            capture->setOutputLocation(QUrl("C:/Kalimba.mp3"));
            

            // active = false;
            }

            AudioBuffer::~AudioBuffer()
            {
            delete audioSource;
            delete capture;
            }

            void AudioBuffer::record()
            {
            ???
            capture->record();
            ???
            }

            void AudioBuffer::stop()
            {
            ????
            QMediaPlayer *player = new QMediaPlayer;
            capture->stop();
            qDebug()<<"Player Stopped";
            ????

            }

            void AudioBuffer::play()
            {
            QMediaPlayer *player = new QMediaPlayer;
            QUrl url = QUrl::fromLocalFile("F:\Vennira Iravugal.mp3");
            player->setMedia(url);
            qDebug()<< url;
            player->setVolume(100);
            qDebug()<<"Player: "<< player->errorString();
            player->play();
            qDebug()<<"Player: "<< player->errorString();
            }
            @

            AudioBuffer.h
            @
            #include <QUrl>
            #include <QObject>
            #include <QAudioFormat>
            #include <QAudioCaptureSource>
            #include <QMediaRecorder>

            class AudioBuffer : public QObject
            {
            Q_OBJECT

            public:
            AudioBuffer();
            ~AudioBuffer();

            public slots:
            void stop();
            void play();
            void record();

            private:
            QAudioCaptureSource *audioSource;
            QMediaRecorder *capture;
            };@

            MainPage.Qml
            @

            Page {
            id: mainPage

            Button {
                id: button1
                x: 16
                y: 324
                width: 100
                height: 42
                text: "Play"
                onClicked:
                    AudioBuffer.play()
            }
            
            Button {
                id: button2
                x: 126
                y: 324
                width: 100
                height: 42
                text: "Stop"
                onClicked:
                    AudioBuffer.stop()
            }
            
            Button {
                id: button3
                x: 247
                y: 324
                width: 100
                height: 42
                text: "Record"
                onClicked:
                    AudioBuffer.record()
            }
            

            }@

            Regards,
            Naufal.A

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Naufal
              wrote on last edited by
              #6

              SOLVED:
              Hi All,
              I finally found the solution on my own.. I would like to share with you all !!!!
              @#include "AudioBuffer.h"
              #include <QAudio>
              #include <QMediaPlayer>
              #include <QAudioCaptureSource>
              #include <QMediaRecorder>
              #include <QFileDialog>
              #include <QFile>
              #include <QAudioEncoderSettings>

              AudioBuffer::AudioBuffer()
              {
              audioSource = new QAudioCaptureSource();
              capture = new QMediaRecorder(audioSource);

                  QAudioEncoderSettings audioSettings;
                  audioSettings.setCodec("audio/vorbis");
                  audioSettings.setQuality(QtMultimediaKit::HighQuality);
                  capture->setEncodingSettings(audioSettings);
                  capture->setOutputLocation(QUrl::fromLocalFile&#40;":\\test.wav"&#41;&#41;;
              

              }

              AudioBuffer::~AudioBuffer()
              {
              delete audioSource;
              delete capture;
              }

              void AudioBuffer::record()
              {
              capture->record();
              }

              void AudioBuffer::stop()
              {
              capture->stop();
              }
              void AudioBuffer::pause()
              {
              capture->pause();
              }

              void AudioBuffer::play()
              {
              QMediaPlayer *player = new QMediaPlayer;
              QUrl url = QUrl::fromLocalFile(":\test.wav");
              player->setMedia(url);
              player->setVolume(100);
              player->play();
              }@

              Thanks a Lot!!!!
              I hope this works well

              Regards,
              Naufal.A

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                Be sure and add [Solved] to the thread title if you have it working. Thanks!

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                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