Results 1 to 3 of 3

Thread: How to record and play an audio file in qml?

  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default 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...94eb3a5417402b and tried but i was not able to get the required output.I was not able to run the example project from the given link.

    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

    Edit / Delete Edit Post Quick reply to this message Reply Reply With Quote Reply With Quote Multi-Quote This Message
    Last edited by harish; 8th February 2012 at 10:43.

  2. #2
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Re: How to record and play an audio file in qml?

    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::HighQual ity);

    recorder->setEncodingSettings(audioSettings);
    recorder->setOutputLocation(QUrl::fromLocalFile("C:\Kalimba .mp3"));
    recorder->record();



    }

    void StringHelper::stop()
    {

    QAudioCaptureSource *audiosource = new QAudioCaptureSource;
    QMediaRecorder *recorder = new QMediaRecorder(audiosource);

    QAudioEncoderSettings audioSettings;
    audioSettings.setCodec("audio/vorbis");
    audioSettings.setQuality(QtMultimediaKit::HighQual ity);

    recorder->setEncodingSettings(audioSettings);
    recorder->setOutputLocation(QUrl::fromLocalFile("C:\Kalimba .mp3"));
    recorder->stop();


    }


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

    I am getting the following errors:“DirectShowPlayerService::doSetUrlSou rce: Unresolved error code 80070020
    QFSFileEngine:pen: No file name specified
    QFile::seek: IODevice is not open”

    Can anyone help me with this?

    Harish.M
    Last edited by harish; 9th February 2012 at 12:50.

  3. #3
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to record and play an audio file in qml?

    i may say something stupod but you need to double the backslashes in c++ strings
    player->setMedia(QUrl::fromLocalFile("C:\Kalimba.mp3")) ;
    or just use slashes to avoid this problem

Similar Threads

  1. OpenCV Record Webcam And Audio ???
    By Thành Viên Mới in forum Qt Programming
    Replies: 0
    Last Post: 25th December 2011, 05:18
  2. How to record and play audio on N8
    By doubleti in forum Newbie
    Replies: 0
    Last Post: 1st December 2011, 12:46
  3. play audio file
    By hema in forum Qt Quick
    Replies: 1
    Last Post: 11th August 2011, 06:27
  4. how to play audio file in qml
    By hema in forum Newbie
    Replies: 0
    Last Post: 10th August 2011, 11:57
  5. Phonon won't play audio file
    By kar in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2010, 02:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.