February 13, 2012

Naufal Naufal
Lab Rat
28 posts

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

 

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

 Signature 

Regards,
Naufal.A

6 replies

February 13, 2012

koahnig koahnig
Area 51 Engineer
2888 posts

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.

February 13, 2012

batosai batosai
Lab Rat
7 posts

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

February 13, 2012

Naufal Naufal
Lab Rat
28 posts

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…

 Signature 

Regards,
Naufal.A

February 15, 2012

Naufal Naufal
Lab Rat
28 posts

Hi All,

I cannot Understand spectrum properly batosai..so i am trying this I have checked this link [qtforum.org] 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

  1. #include "AudioBuffer.h"
  2. #include <QAudio>
  3. #include <QMediaPlayer>
  4. #include <QAudioCaptureSource>
  5. #include <QAudioInput>
  6. #include <QAudiooutput>
  7. #include <QAudioCaptureSource>
  8. #include <QMediaRecorder>
  9.  
  10.  
  11. AudioBuffer::AudioBuffer()
  12. {
  13.     audioSource = new QAudioCaptureSource();
  14.     capture = new QMediaRecorder(audioSource);
  15.  
  16.     QAudioEncoderSettings es;
  17.     es.setCodec("audio/mp3");
  18.     es.setSampleRate(96000);
  19.     capture->setEncodingSettings(es);
  20.     capture->setOutputLocation(QUrl("C:/Kalimba.mp3"));
  21.  
  22. //    active = false;
  23. }
  24.  
  25. AudioBuffer::~AudioBuffer()
  26. {
  27.     delete audioSource;
  28.     delete capture;
  29. }
  30.  
  31. void AudioBuffer::record()
  32. {
  33.       ???
  34.     capture->record();
  35.       ???
  36. }
  37.  
  38. void AudioBuffer::stop()
  39. {
  40.          ????
  41.      QMediaPlayer *player = new QMediaPlayer;
  42.      capture->stop();
  43.      qDebug()<<"Player Stopped";
  44.         ????
  45.  
  46. }
  47.  
  48.  
  49. void AudioBuffer::play()
  50. {
  51.  QMediaPlayer *player = new QMediaPlayer;
  52.  QUrl url = QUrl::fromLocalFile("F:\Vennira Iravugal.mp3");
  53.  player->setMedia(url);
  54.  qDebug()<< url;
  55.  player->setVolume(100);
  56.  qDebug()<<"Player: "<< player->errorString();
  57.  player->play();
  58.  qDebug()<<"Player: "<< player->errorString();
  59. }

AudioBuffer.h

  1. #include <QUrl>
  2. #include <QObject>
  3. #include <QAudioFormat>
  4. #include <QAudioCaptureSource>
  5. #include <QMediaRecorder>
  6.  
  7. class AudioBuffer : public QObject
  8. {
  9.     Q_OBJECT
  10.  
  11. public:
  12.      AudioBuffer();
  13.     ~AudioBuffer();
  14.  
  15. public slots:
  16.     void stop();
  17.     void play();
  18.     void record();
  19.  
  20. private:
  21.     QAudioCaptureSource *audioSource;
  22.     QMediaRecorder *capture;
  23. };

MainPage.Qml

  1. Page {
  2.     id: mainPage
  3.  
  4.     Button {
  5.         id: button1
  6.         x: 16
  7.         y: 324
  8.         width: 100
  9.         height: 42
  10.         text: "Play"
  11.         onClicked:
  12.             AudioBuffer.play()
  13.     }
  14.  
  15.     Button {
  16.         id: button2
  17.         x: 126
  18.         y: 324
  19.         width: 100
  20.         height: 42
  21.         text: "Stop"
  22.         onClicked:
  23.             AudioBuffer.stop()
  24.     }
  25.  
  26.     Button {
  27.         id: button3
  28.         x: 247
  29.         y: 324
  30.         width: 100
  31.         height: 42
  32.         text: "Record"
  33.         onClicked:
  34.             AudioBuffer.record()
  35.     }
  36.  
  37. }

 Signature 

Regards,
Naufal.A

February 17, 2012

Naufal Naufal
Lab Rat
28 posts

SOLVED:
Hi All, I finally found the solution on my own.. I would like to share with you all !!!!

  1. #include "AudioBuffer.h"
  2. #include <QAudio>
  3. #include <QMediaPlayer>
  4. #include <QAudioCaptureSource>
  5. #include <QMediaRecorder>
  6. #include <QFileDialog>
  7. #include <QFile>
  8. #include <QAudioEncoderSettings>
  9.  
  10. AudioBuffer::AudioBuffer()
  11. {
  12.     audioSource = new QAudioCaptureSource();
  13.     capture = new QMediaRecorder(audioSource);
  14.  
  15.         QAudioEncoderSettings audioSettings;
  16.         audioSettings.setCodec("audio/vorbis");
  17.         audioSettings.setQuality(QtMultimediaKit::HighQuality);
  18.         capture->setEncodingSettings(audioSettings);
  19.         capture->setOutputLocation(QUrl::fromLocalFile(":\\test.wav"));
  20. }
  21.  
  22. AudioBuffer::~AudioBuffer()
  23. {
  24.     delete audioSource;
  25.     delete capture;
  26. }
  27.  
  28. void AudioBuffer::record()
  29. {
  30.     capture->record();
  31. }
  32.  
  33. void AudioBuffer::stop()
  34. {
  35.     capture->stop();
  36. }
  37. void AudioBuffer::pause()
  38. {
  39.     capture->pause();
  40. }
  41.  
  42. void AudioBuffer::play()
  43. {
  44.     QMediaPlayer *player = new QMediaPlayer;
  45.     QUrl url = QUrl::fromLocalFile(":\\test.wav");
  46.     player->setMedia(url);
  47.     player->setVolume(100);
  48.     player->play();
  49. }

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

 Signature 

Regards,
Naufal.A

February 17, 2012

mlong mlong
Robot Herder
1551 posts

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

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

 
  ‹‹ ftp and qt      Qt5 QML & Image element. Everything converted to openGL textures? ››

You must log in to post a reply. Not a member yet? Register here!