How to record and play an audio file in qml?



  • 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



  • Can anyone help me with this?



  • 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.



  • 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?


Log in to reply
 

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