Using QAudioOutput as Input
-
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?
-
Seems like I have to change the input device via pavucontrol:
Audio Loopback Recording with PulseAudioBut I don't want to do this every time manually for my application. There must be some way to do this in QT.......
-
Seems like I have to change the input device via pavucontrol:
Audio Loopback Recording with PulseAudioBut I don't want to do this every time manually for my application. There must be some way to do this in QT.......
@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.
-
@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.
@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_micSo, 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!
-
W Wolfspirit has marked this topic as solved on
-
N Nhan Nguyen moved this topic from General and Desktop on