Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Multimedia
  4. Using QAudioOutput as Input
Qt 6.11 is out! See what's new in the release blog

Using QAudioOutput as Input

Scheduled Pinned Locked Moved Solved Qt Multimedia
4 Posts 2 Posters 1.2k Views 1 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.
  • W Offline
    W Offline
    Wolfspirit
    wrote on last edited by
    #1

    Hello. I want to record audiooutput into a .wav-file. All I got is a empty file. Here is my code:

    QAudioOutput *my_audioOutput = new QAudioOutput();
    QMediaCaptureSession *my_session = new QMediaCaptureSession();
    QMediaRecorder *my_recorder = new QMediaRecorder();
    bool recording = false;
    ...
    ...
    ...
    void MainWindow::on_pushButtonRecord_clicked()
    {
        if(recording == true) {
            my_recorder->stop();
            recording = false;
        }
        else {
            // RECORD
            my_audioInput = new QAudioInput();
            my_audioInput->setDevice(my_audioOutput->device());    // <-- This does not work
            my_session->setAudioInput(my_audioInput);
            my_session->setRecorder(my_recorder);
            my_recorder->setMediaFormat(QMediaFormat::Wave);
            my_recorder->setOutputLocation(QUrl::fromLocalFile("/home/thomas/Projects/mymp3player/test"));
            my_recorder->setAudioSampleRate(48000);
            my_recorder->setAudioChannelCount(2);
            my_recorder->record();
            recording = true;
        }
    }
    

    Can someone help me on this?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      Wolfspirit
      wrote on last edited by
      #2

      Seems like I have to change the input device via pavucontrol:
      Audio Loopback Recording with PulseAudio

      But I don't want to do this every time manually for my application. There must be some way to do this in QT.......

      B 1 Reply Last reply
      0
      • W Wolfspirit

        Seems like I have to change the input device via pavucontrol:
        Audio Loopback Recording with PulseAudio

        But I don't want to do this every time manually for my application. There must be some way to do this in QT.......

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

        @Wolfspirit said in Using QAudioOutput as Input:

        There must be some way to do this in QT.......

        What Qt can do is to just open and read your existing audio input devices.
        If your system has a loopback input device, then Qt can open it. If not then Qt can't.

        I don't use linux often but I remember having loopback-like ones when printing the names of all the audio input devices using Qt, not sure this is soundcard-related or not. So maybe you can first try listing the input devices using Qt to see if there's one.

        If there's not, as I googled, this loopback thing can be set by command line (reference: https://forums.debian.net/viewtopic.php?t=110440 or https://huma.id/pa-loopback/). But that has nothing to do with Qt. You can make Qt to run a command script before opening the device if you find out how to set that by script.

        W 1 Reply Last reply
        3
        • B Bonnie

          @Wolfspirit said in Using QAudioOutput as Input:

          There must be some way to do this in QT.......

          What Qt can do is to just open and read your existing audio input devices.
          If your system has a loopback input device, then Qt can open it. If not then Qt can't.

          I don't use linux often but I remember having loopback-like ones when printing the names of all the audio input devices using Qt, not sure this is soundcard-related or not. So maybe you can first try listing the input devices using Qt to see if there's one.

          If there's not, as I googled, this loopback thing can be set by command line (reference: https://forums.debian.net/viewtopic.php?t=110440 or https://huma.id/pa-loopback/). But that has nothing to do with Qt. You can make Qt to run a command script before opening the device if you find out how to set that by script.

          W Offline
          W Offline
          Wolfspirit
          wrote on last edited by Wolfspirit
          #4

          @Bonnie This... is... great! Thank you very much.
          I came up with following commands:

          pactl load-module module-null-sink sink_name=my_sink_mix sink_properties=device.description=my_sink_mix
          pactl load-module module-loopback latency_msec=60 adjust_time=6 source=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor sink=my_sink_mix
          pactl load-module module-remap-source master=my_sink_mix.monitor source_name=vmic source_properties=device.description=virtual_mic
          

          So, all I have to do is to write something with QProcess with these commands. And then use "vmic" as QAudioInput and "my_sink_mix" as QAudioOutput and voila! I can hear the audiostream and save it to disc simultaneously.

          Again: Thank you very much!

          1 Reply Last reply
          0
          • W Wolfspirit has marked this topic as solved on
          • Nhan NguyenN Nhan Nguyen moved this topic from General and Desktop on

          • Login

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