I posted this question on the Qt forum, but got no answers. That's why I am posting it here.
I wanted to know is there any way to record and play sound at the same time in Qt. I want to record sound from a microphone and at the same time I want to play it in the speaker/headphone.
Is there any way to do this in Qt? Or do I need to use any other library?
It would be great if the solution is cross-platform (I need to cover windows, linux and mac). If it isn't possible, then a linux solution will do.
I am using Qt 4.7 by the way.
Edit
My latest implementation is given here. I have created a sub-class of the QIODevice and re-implemented its writeData and readData method so that reading and writing can be done with a circular buffer. I have done this as per this suggestion. This code also doesn't work because the QAudioOutput instance faces Underrun Error
, which according to this documentation means -
Audio data is not being fed to the audio device at a fast enough rate
I have applied a hack to solve this problem temporarily. In the outputStateChanged
method, I am checking to see if the state of the output has changed to IDLE
and if it has, I am again calling start()
method, specifying the common buffer. I don't want to use this as a permanent solution because it feels really hacky and because I am swallowing an error without properly investigating its reasons.
What should I do to solve this problem?
I also tried to solve this using Phonon but failed because I do not have sufficient knowledge of this module.
I don't see why there would be a problem using the classes you mention in your comment. Neither are restricted to just using files.
Take the QIODevice
returned from the start()
method of QAudioInput
and give it to the start()
method of QAudioOutput
:
QIODevice *myDevice = myQAudioInput->start();
myQAudioOutput->start( myDevice );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With