Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Record Audio in Qt6
Forum Updated to NodeBB v4.3 + New Features

Record Audio in Qt6

Scheduled Pinned Locked Moved Solved Qt 6
20 Posts 5 Posters 3.2k Views 2 Watching
  • 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.
  • QtAndrewQ QtAndrew

    @jsulm Thanks --> i didn't understand this LOC from the examples you suggest.

    connect(mediaRecorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
        [=](QMediaRecorder::Error error){ /* ... */ });
    

    getting an error, what did "of" mean? sorry

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #7

    @QtAndrew
    The QOverload<...>::of is to pick out a particular overload. The docs explain:

    Note: Signal error is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

    See also https://doc.qt.io/qt-5/qtglobal.html#qOverload.

    You should show the error message.

    QtAndrewQ 1 Reply Last reply
    2
    • JonBJ JonB

      @QtAndrew
      The QOverload<...>::of is to pick out a particular overload. The docs explain:

      Note: Signal error is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

      See also https://doc.qt.io/qt-5/qtglobal.html#qOverload.

      You should show the error message.

      QtAndrewQ Offline
      QtAndrewQ Offline
      QtAndrew
      wrote on last edited by QtAndrew
      #8

      @JonB the examples are full of spelling mistakes. QOverload vs. qOverload. By the way, i am not able to put it into my example. Could it be that macos does not support the recording function?

      JonBJ 1 Reply Last reply
      0
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @QtAndrew said in Record Audio in Qt6:

        the examples are full of spelling mistakes. QOverload vs. qOverload.

        Why not read the docs instead complaining for no reason? Both versions are valid and it's perfectly explained why there are two version. But looks like you're too lazy to read.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        0
        • QtAndrewQ QtAndrew

          @JonB the examples are full of spelling mistakes. QOverload vs. qOverload. By the way, i am not able to put it into my example. Could it be that macos does not support the recording function?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #10

          @QtAndrew
          There are no spelling mistakes. qOverload is not the same as QOverload. The page I referred you to shows that, and shows examples.

          By the way, i am not able to put it into my example.

          Twice you have said "it doesn't work" or "getting an error". I have asked you to show your code and paste the error you get. How can we answer without those details?

          QtAndrewQ 1 Reply Last reply
          2
          • JonBJ JonB

            @QtAndrew
            There are no spelling mistakes. qOverload is not the same as QOverload. The page I referred you to shows that, and shows examples.

            By the way, i am not able to put it into my example.

            Twice you have said "it doesn't work" or "getting an error". I have asked you to show your code and paste the error you get. How can we answer without those details?

            QtAndrewQ Offline
            QtAndrewQ Offline
            QtAndrew
            wrote on last edited by QtAndrew
            #11

            @JonB

                // RECORD
                QMediaCaptureSession* session = new QMediaCaptureSession();
                QAudioInput* audioInput = new QAudioInput();
                QMediaRecorder* recorder = new QMediaRecorder();
                session->setAudioInput(audioInput);
                session->setRecorder(recorder);
                recorder->setMediaFormat(QMediaFormat::Wave);
                recorder->setOutputLocation(QUrl::fromLocalFile("test"));
                recorder->setAudioSampleRate(48000);
                recorder->setAudioChannelCount(1);
                recorder->record();
            
                connect(recorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
                    [=](QMediaRecorder::Error error){ /* ... */ });
            
                QTimer *timer = new QTimer(this);
                connect(timer, SIGNAL(timeout()), recorder, SLOT(stop()));
                timer->start(3500);
            

            ERROR: 1.) Does not Record any audio but the file is created (macos ARM64)
            ERROR: 2.)

            /Users/christoph/Documents/DEVELOPMENT/Impulse-Response-Extractor/IRExtractor/irextractor.cpp:44: Fehler: no matching function for call to 'of'
            ../IRExtractor/irextractor.cpp:44:23: error: no matching function for call to 'of'
            connect(recorder, QOverloadQMediaRecorder::Error::of(&QMediaRecorder::error),
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

            /Volumes/Externe-SSD/Development/Qt/6.2.0/macos/lib/QtCore.framework/Headers/qglobal.h:1345:27: note: candidate template ignored: failed template argument deduction
            static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
            ^

            jsulmJ 1 Reply Last reply
            0
            • QtAndrewQ QtAndrew

              @JonB

                  // RECORD
                  QMediaCaptureSession* session = new QMediaCaptureSession();
                  QAudioInput* audioInput = new QAudioInput();
                  QMediaRecorder* recorder = new QMediaRecorder();
                  session->setAudioInput(audioInput);
                  session->setRecorder(recorder);
                  recorder->setMediaFormat(QMediaFormat::Wave);
                  recorder->setOutputLocation(QUrl::fromLocalFile("test"));
                  recorder->setAudioSampleRate(48000);
                  recorder->setAudioChannelCount(1);
                  recorder->record();
              
                  connect(recorder, QOverload<QMediaRecorder::Error>::of(&QMediaRecorder::error),
                      [=](QMediaRecorder::Error error){ /* ... */ });
              
                  QTimer *timer = new QTimer(this);
                  connect(timer, SIGNAL(timeout()), recorder, SLOT(stop()));
                  timer->start(3500);
              

              ERROR: 1.) Does not Record any audio but the file is created (macos ARM64)
              ERROR: 2.)

              /Users/christoph/Documents/DEVELOPMENT/Impulse-Response-Extractor/IRExtractor/irextractor.cpp:44: Fehler: no matching function for call to 'of'
              ../IRExtractor/irextractor.cpp:44:23: error: no matching function for call to 'of'
              connect(recorder, QOverloadQMediaRecorder::Error::of(&QMediaRecorder::error),
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

              /Volumes/Externe-SSD/Development/Qt/6.2.0/macos/lib/QtCore.framework/Headers/qglobal.h:1345:27: note: candidate template ignored: failed template argument deduction
              static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
              ^

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @QtAndrew Since you're on Qt6 you should use https://doc-snapshots.qt.io/qt6-dev/qmediarecorder.html#errorOccurred
              And don't forget to print the error in the slot you connect to this signal.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              QtAndrewQ 2 Replies Last reply
              3
              • jsulmJ jsulm

                @QtAndrew Since you're on Qt6 you should use https://doc-snapshots.qt.io/qt6-dev/qmediarecorder.html#errorOccurred
                And don't forget to print the error in the slot you connect to this signal.

                QtAndrewQ Offline
                QtAndrewQ Offline
                QtAndrew
                wrote on last edited by QtAndrew
                #13
                This post is deleted!
                jsulmJ Christian EhrlicherC 2 Replies Last reply
                0
                • QtAndrewQ QtAndrew

                  This post is deleted!

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  @QtAndrew said in Record Audio in Qt6:

                  why does this code sniplet stand on 6.2 QMediaRecorder ?

                  It does not. This code snippet is in Qt5 documentation, not in Qt6. I noticed from your compile log that you're using Qt6.2 and provided you the link to Qt6 documentation.
                  Don't know what is unclear in the documentation...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • QtAndrewQ QtAndrew

                    This post is deleted!

                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #15

                    @QtAndrew said in Record Audio in Qt6:

                    I think i change the platorform.

                    Please do so. Maybe you find a toolkit where the version is automatically guessed by your browser when you search for help.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • QtAndrewQ Offline
                      QtAndrewQ Offline
                      QtAndrew
                      wrote on last edited by
                      #16
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • QtAndrewQ Offline
                        QtAndrewQ Offline
                        QtAndrew
                        wrote on last edited by QtAndrew
                        #17

                        I tried:

                        1.) Threads
                        2.) Timers
                        3.) start the recording and connect the stop() to the player end of media slot.

                        no success...

                        void IRExtractor::on_sweepButton_clicked()
                        {
                            // PLAY
                            MyThread* t = new MyThread();
                            t->start();
                        
                            // RECORD
                            QMediaCaptureSession* session = new QMediaCaptureSession();
                            QAudioInput* audioInput = new QAudioInput();
                            QMediaRecorder* recorder = new QMediaRecorder();
                            session->setAudioInput(audioInput);
                            session->setRecorder(recorder);
                            recorder->setMediaFormat(QMediaFormat::Wave);
                            recorder->setOutputLocation(QUrl::fromLocalFile("test"));
                            recorder->setAudioSampleRate(48000);
                            recorder->setAudioChannelCount(1);
                            recorder->record();
                            QThread::msleep(3250);
                            recorder->stop();
                        }
                        
                        void MyThread::run()
                        {
                            QMediaPlayer* player = new QMediaPlayer();
                            QAudioOutput* audioOutput = new QAudioOutput;
                            audioOutput->setVolume(0.1);
                            player->setAudioOutput(audioOutput);
                            player->setSource(QUrl("qrc:/res/sweep.wav"));
                            player->play();
                        
                        }
                        

                        This version didn't play the audio.

                        The Project is now on GitHub: https://github.com/Christoph-Lauer/Impulse-Response-Extractor

                        JonBJ 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @QtAndrew Since you're on Qt6 you should use https://doc-snapshots.qt.io/qt6-dev/qmediarecorder.html#errorOccurred
                          And don't forget to print the error in the slot you connect to this signal.

                          QtAndrewQ Offline
                          QtAndrewQ Offline
                          QtAndrew
                          wrote on last edited by
                          #18
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • QtAndrewQ QtAndrew

                            I tried:

                            1.) Threads
                            2.) Timers
                            3.) start the recording and connect the stop() to the player end of media slot.

                            no success...

                            void IRExtractor::on_sweepButton_clicked()
                            {
                                // PLAY
                                MyThread* t = new MyThread();
                                t->start();
                            
                                // RECORD
                                QMediaCaptureSession* session = new QMediaCaptureSession();
                                QAudioInput* audioInput = new QAudioInput();
                                QMediaRecorder* recorder = new QMediaRecorder();
                                session->setAudioInput(audioInput);
                                session->setRecorder(recorder);
                                recorder->setMediaFormat(QMediaFormat::Wave);
                                recorder->setOutputLocation(QUrl::fromLocalFile("test"));
                                recorder->setAudioSampleRate(48000);
                                recorder->setAudioChannelCount(1);
                                recorder->record();
                                QThread::msleep(3250);
                                recorder->stop();
                            }
                            
                            void MyThread::run()
                            {
                                QMediaPlayer* player = new QMediaPlayer();
                                QAudioOutput* audioOutput = new QAudioOutput;
                                audioOutput->setVolume(0.1);
                                player->setAudioOutput(audioOutput);
                                player->setSource(QUrl("qrc:/res/sweep.wav"));
                                player->play();
                            
                            }
                            

                            This version didn't play the audio.

                            The Project is now on GitHub: https://github.com/Christoph-Lauer/Impulse-Response-Extractor

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #19

                            @QtAndrew
                            I do not know know anything about this, so no point asking me any further! But from your code are you supposed to some error checking as per https://forum.qt.io/topic/130588/qmediaplay-stream-does-not-wokk/2 ?

                            1 Reply Last reply
                            0
                            • QtAndrewQ Offline
                              QtAndrewQ Offline
                              QtAndrew
                              wrote on last edited by
                              #20

                              changed to matlab --> https://github.com/Christoph-Lauer/Transfer-Function-Extractor-Matlab

                              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