Results 1 to 7 of 7

Thread: Recording audio stream

  1. #1
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Recording audio stream

    I want to use QT to record an internet audio stream. So far I can play the stream:

    Qt Code:
    1. player = new QMediaPlayer();
    2. //connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
    3. player->setMedia(QUrl("http://idobiradio.idobi.com/;stream.mp3"));
    4. player->setVolume(50);
    5. player->play();
    To copy to clipboard, switch view to plain text mode 

    However, I want to take that data and record it to an MP3. How would I do that? I've been looking at using QIODevice but can't quite work out how to extract the data stream from the media player.

    Thanks

  2. #2
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Recording audio stream

    Please check QAudioProbe class. The example in the documentation is using QAudioRecorder but it works the same way for QMediaPlayer.

  3. #3
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Recording audio stream

    I tried that however:

    Qt Code:
    1. QAudioProbe *probe = new QAudioProbe;
    2. connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(streamStarted(QAudioBuffer)));
    3.  
    4. probe->setSource(player);
    To copy to clipboard, switch view to plain text mode 

    Setting the probe's source returns false. Using the above code as the source.

  4. #4
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Recording audio stream

    The correct way is calling setSource() before calling play(). From what you have posted I can't guess the order that you use.
    If still it does not work then as mentioned in the documentation of QAudioProbe "If the media object does not support monitoring audio, this function will return false." but I hope that this is not the issue.

  5. #5
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Recording audio stream

    That's what I was doing.

    Qt Code:
    1. player = new QMediaPlayer();
    2. player->setMedia(QUrl("http://idobiradio.idobi.com/;stream.mp3"));
    3.  
    4. QAudioProbe *probe = new QAudioProbe;
    5. connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(streamStarted(QAudioBuffer)));
    6.  
    7. if(probe->setSource(player)) {
    8. qDebug() << "set";
    9. } else {
    10. qDebug() << "couldn't set";
    11. }
    12.  
    13. player->setVolume(50);
    14. player->play();
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Aug 2007
    Posts
    166
    Thanks
    16
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Recording audio stream

    Yes, that's the correct way. I'm sorry then. I don't have other clue.

  7. #7
    Join Date
    Oct 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Recording audio stream

    So I was thinking another way of doing this would be to use the NetworkAccessManager, however I can't seem to work out what I need to do.

    Qt Code:
    1. QNetworkRequest request(QUrl(QString("http://idobiradio.idobi.com/;stream.mp3")));
    2.  
    3.  
    4. QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
    5.  
    6. connect(networkManager, SIGNAL(readyRead), this, SLOT(streamStarted()));
    7.  
    8. request.setRawHeader(QByteArray("Icy-MetaData"), "8192");
    9. request.setRawHeader(QByteArray("Accept"), "*/*");
    10. request.setRawHeader(QByteArray("Connection"), "Keep-Alive");
    11. request.setHeader(QNetworkRequest::UserAgentHeader, "WinampMPEG/5.09");
    12.  
    13. networkManager->get(request);
    To copy to clipboard, switch view to plain text mode 

    I'm not entirely sure what I need to put in the slot.

Similar Threads

  1. Audio Recording from microphone in Qt
    By Sergex in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2013, 10:46
  2. mp3 audio recording
    By dhe in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2012, 10:00
  3. Audio Recording in qt
    By BalaQT in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2009, 09:01
  4. Audio Recording with Phonon
    By Nemo in forum Qt Programming
    Replies: 4
    Last Post: 12th June 2008, 06:31
  5. Is there an audio *recording* facility in Qt?
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 21:51

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.