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.
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,
_
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?
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:
Code:
QByteArray byteData
(buffer.
constData<char>
(), buffer.
byteCount());
Cheers,
_
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.
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,
_