Results 1 to 6 of 6

Thread: Save QAudioRecorder to QByteArray

  1. #1

    Default Save QAudioRecorder to QByteArray

    I am trying to record from a microphone using QAudioRecorder. I do not want to save the file locally and then read it into a QByteArray. How can I save from the audio recorder to a QByteArray? I tried using QAudioProbe with the audioBufferProbed(QAudioBuffer) signal, but I don't know if it is possible to save the QAudioBuffer as a QByteArray.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Save QAudioRecorder to QByteArray

    QAudioBuffer has accessors for data and byte count.
    Looks sufficient to either directly create a QByteArray for the buffer's data or for writing into a QBuffer.

    Cheers,
    _

  3. #3

    Default Re: Save QAudioRecorder to QByteArray

    Thanks for the reply. Is the QAudioBuffer.data() the actual microphone data or only formatting data (channels, bit rate, etc)? If not, how do I convert the const void* from data() to a QByteArray?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Save QAudioRecorder to QByteArray

    Well, the QAudioBuffer has a QAudioFormat so the data must be the actual audio data.

    Without trying the API would suggest that this should be possible:
    Qt Code:
    1. QByteArray byteData(buffer.constData<char>(), buffer.byteCount());
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5

    Default Re: Save QAudioRecorder to QByteArray

    I tried using the code you posted to save the QByteArray to a file. I get an error, "Windows Media Player cannot play this file."
    edit: I did some testing and it saves the microphone data, but it didn't use the codec from the QAudioRecorder.
    Last edited by vanillac; 27th March 2015 at 20:39.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Save QAudioRecorder to QByteArray

    If you want to write to a file, then converting into a byte array is just an unnecessary step, you can directly write the "const char*" data into the file.

    Cheers,
    _

Similar Threads

  1. Replies: 6
    Last Post: 14th May 2014, 12:14
  2. Replies: 4
    Last Post: 29th May 2012, 23:37
  3. Save and restore QByteArray in mysql database
    By ruben.rodrigues in forum Newbie
    Replies: 0
    Last Post: 9th August 2010, 09:43
  4. Save 4 Integers in a QByteArray without memcpy
    By GonzoFist in forum Newbie
    Replies: 3
    Last Post: 17th May 2010, 23:15
  5. Replies: 9
    Last Post: 25th July 2009, 13:27

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.