How can one use Qt Media Player to record user utterances and play it back?
-
I am a QT beginner and trying to find my way forward in accomplishing a task that tries to record audio from a user and then plays it back. I have been able to install Qt framework as .dylibs and been able to link all the necessary Media modules to my project as can be seen from the following CMake command in CMakeLists.txt of my project :
# link the necessary Qt component libraries with the target target_link_libraries(ApplicationTarget Qt5::Core Qt5::Multimedia Qt5::Widgets)I am basically now stuck at how to use Qt media player and write a simple application to record user audio and play it back, here is some sample code I wrote to analyze the list of recording devices available using Qt :
/// Standard library includes #include <iostream> /// Qt component includes #include <QApplication> #include <QAudioDeviceInfo> #include <QAudioFormat> #include <QAudioInput> #include <QBuffer> #include <QIODevice> #include <QMediaPlayer> #include <QMediaContent> #include <QFile> #include <QThread> #include <QTimer> void setRecordingFormat(QAudioFormat* recordingFormat) { recordingFormat->setSampleRate(16000); recordingFormat->setChannelCount(2); recordingFormat->setSampleSize(16); recordingFormat->setCodec("audio/pcm"); recordingFormat->setByteOrder(QAudioFormat::LittleEndian); recordingFormat->setSampleType(QAudioFormat::SignedInt); } int main(int argc, char *argv[]) { /// main Qt application object QApplication qApplication(argc, argv); /// the format we will use for recording audio /// all information is set in the setRecordingFormat function QAudioFormat recordingFormat; setRecordingFormat(&recordingFormat); /// Get a list of all available audio input devices available for /// getting audio input QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for (const QAudioDeviceInfo& deviceInfo : devices) { qInfo() << "The device name is : " << deviceInfo.deviceName(); } return qApplication.exec(); }Can someone help me identify how the recording of audio will write to an mp3 file and then how can one go about writing the logic to play it back?
-
I am a QT beginner and trying to find my way forward in accomplishing a task that tries to record audio from a user and then plays it back. I have been able to install Qt framework as .dylibs and been able to link all the necessary Media modules to my project as can be seen from the following CMake command in CMakeLists.txt of my project :
# link the necessary Qt component libraries with the target target_link_libraries(ApplicationTarget Qt5::Core Qt5::Multimedia Qt5::Widgets)I am basically now stuck at how to use Qt media player and write a simple application to record user audio and play it back, here is some sample code I wrote to analyze the list of recording devices available using Qt :
/// Standard library includes #include <iostream> /// Qt component includes #include <QApplication> #include <QAudioDeviceInfo> #include <QAudioFormat> #include <QAudioInput> #include <QBuffer> #include <QIODevice> #include <QMediaPlayer> #include <QMediaContent> #include <QFile> #include <QThread> #include <QTimer> void setRecordingFormat(QAudioFormat* recordingFormat) { recordingFormat->setSampleRate(16000); recordingFormat->setChannelCount(2); recordingFormat->setSampleSize(16); recordingFormat->setCodec("audio/pcm"); recordingFormat->setByteOrder(QAudioFormat::LittleEndian); recordingFormat->setSampleType(QAudioFormat::SignedInt); } int main(int argc, char *argv[]) { /// main Qt application object QApplication qApplication(argc, argv); /// the format we will use for recording audio /// all information is set in the setRecordingFormat function QAudioFormat recordingFormat; setRecordingFormat(&recordingFormat); /// Get a list of all available audio input devices available for /// getting audio input QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for (const QAudioDeviceInfo& deviceInfo : devices) { qInfo() << "The device name is : " << deviceInfo.deviceName(); } return qApplication.exec(); }Can someone help me identify how the recording of audio will write to an mp3 file and then how can one go about writing the logic to play it back?
-
@sabbyg Use
QMediaRecorderto record andQMediaPlayerto play.
Just read the documetations and examples.