Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can one use Qt Media Player to record user utterances and play it back?

How can one use Qt Media Player to record user utterances and play it back?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 336 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sabbyg
    wrote on last edited by
    #1

    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?

    B 1 Reply Last reply
    0
    • S sabbyg

      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?

      B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      @sabbyg Use QMediaRecorder to record and QMediaPlayer to play.
      Just read the documetations and examples.

      S 1 Reply Last reply
      0
      • B Bonnie

        @sabbyg Use QMediaRecorder to record and QMediaPlayer to play.
        Just read the documetations and examples.

        S Offline
        S Offline
        sabbyg
        wrote on last edited by
        #3

        @Bonnie : Thanks for the recommendations I will go through the documentation and see if I am able to get the recording and playback to work

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved