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. How to record and play an audio file in qml?

How to record and play an audio file in qml?

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

    Hi all,
    I am trying an app to record and play an audio file using QML.

    I had downloaded this API from this link:"https://projects.developer.nokia.com/audiorecorder/changeset/67519324bc6ea96ef956dec1b494eb3a5417402b and tried but i was not able to get the required output.

    I am having an issue in solving this.

    Actually what i am trying is:I am having 3 buttons in the mainPage as RECORD,STOP and PLAY.

    When i click on the RECORD button the voice which i speak should be recorded and when i click on the STOP button the operation should stop and recorded voice should be stored.Finally when i click on PLAY button i should be able to get the recorded voice and play it.

    Can anyone help me this app so that i will able to solve my issue....

    Thanks in advance,
    Harish

    Harish.M

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkhpad
      wrote on last edited by
      #2

      Can anyone help me with this?

      Harish.M

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Patience is a virtue.
        It's unlikely that you attract people to look into your problem if you can't even wait a single hour for some replies.

        So I suggest, you wait a some more days before bumping up the topic and read http://www.catb.org/~esr/faqs/smart-questions.html in the meantime.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkhpad
          wrote on last edited by
          #4

          Hi everyone,
          I have tried to record and play an audio file in QML but i was not able to fix my errors.

          Here is the code what i had tried so far:

          main.qml:

          @import QtQuick 1.0
          import com.nokia.symbian 1.0
          import Qt 4.7

          Page {
          id: mainPage

          Rectangle {
          id: outerRect
          width: 360
          height: 620

          Button{
          id: buttonRecord
          x: 0
          y: 368
          width: outerRect.width/3
          text: "Record"
          anchors.bottomMargin: 210
          anchors.leftMargin: 0
          anchors.bottom: outerRect.bottom; anchors.left: outerRect.left
          MouseArea {
          id: mouseArea4
          x: 0
          y: 0
          anchors.rightMargin: 0
          anchors.bottomMargin: 0
          anchors.leftMargin: 0
          anchors.topMargin: 0
          anchors.fill: parent

          onClicked: {
          StringHelper.record()

          }
          }
          }

          Button{
          id: buttonStop
          x: 120
          y: 368
          width: outerRect.width/3
          text: "Stop"
          anchors.bottomMargin: 210
          anchors.leftMargin: 0
          anchors.bottom: outerRect.bottom; anchors.left: buttonRecord.right

                      MouseArea {
                          id: mouseArea3
                          anchors.fill: parent
          

          onClicked: {
          StringHelper.stop()

          }
          }
          }

          Button{
          id: buttonPlay
          x: 240
          y: 368
          width: outerRect.width/3
          text: "Play"
          anchors.bottomMargin: 210
          anchors.leftMargin: 0
          anchors.bottom: outerRect.bottom; anchors.left: buttonStop.right

          MouseArea {
          id: mouseArea2
          anchors.fill: parent

                          onClicked: {
                              StringHelper.play()
          

          }
          }
          }

          TextInput {
          id: textDisplay
          x: 21
          y: 49
          width: outerRect.width - buttonExit.width
          height: buttonExit.height
          text: "Audio Recorder "
          anchors.leftMargin: 21
          anchors.topMargin: 49
          readOnly: true
          font.bold: true
          horizontalAlignment: TextInput.AlignHCenter
          font.pixelSize: 25
          anchors.top: outerRect.top
          anchors.left: outerRect.left
          MouseArea {
          anchors.fill: parent
          onClicked: textDisplay.showText()
          }
          }

          Button{
          id: buttonExit
          text: "Exit"
          anchors.top: outerRect.top
          anchors.right: outerRect.right

          MouseArea {id: mouseArea6;
          anchors.fill: parent
          onClicked: {Qt.quit();
          }
          }
          }
          }
          }

          @

          Stringhelper.cpp:

          @#include"stringhelper.h"
          #include<QMessageBox>

          #include"QAudioCaptureSource"
          #include<QMediaPlayer>

          void StringHelper::record()
          {

          QAudioCaptureSource *audiosource = new QAudioCaptureSource;
           QMediaRecorder *recorder = new QMediaRecorder(audiosource);
          
           QAudioEncoderSettings audioSettings;
           audioSettings.setCodec("audio/vorbis");
           audioSettings.setQuality(QtMultimediaKit::HighQuality);
          
           recorder->setEncodingSettings(audioSettings);
           recorder->setOutputLocation(QUrl::fromLocalFile&#40;"C:\Kalimba.mp3"&#41;&#41;;
           recorder->record();
          

          }

          void StringHelper::stop()
          {
          QAudioCaptureSource *audiosource = new QAudioCaptureSource;
          QMediaRecorder *recorder = new QMediaRecorder(audiosource);

           QAudioEncoderSettings audioSettings;
           audioSettings.setCodec("audio/vorbis");
           audioSettings.setQuality(QtMultimediaKit::HighQuality);
          
           recorder->setEncodingSettings(audioSettings);
           recorder->setOutputLocation(QUrl::fromLocalFile&#40;"C:\Kalimba.mp3"&#41;);
           recorder->stop();
          

          }

          void StringHelper::play()
          {
          QMediaPlayer *player = new QMediaPlayer;
          player->setMedia(QUrl::fromLocalFile("C:\Kalimba.mp3"));
          player->setVolume(50);
          player->play();
          }
          @

          I am getting the following errors:"DirectShowPlayerService::doSetUrlSource: Unresolved error code 80070020
          QFSFileEngine::open: No file name specified
          QFile::seek: IODevice is not open"

          Can anyone help me with this?

          Harish.M

          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