Record Audio in Qt6
-
@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.
-
@QtAndrew
There are no spelling mistakes.qOverload
is not the same asQOverload
. 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?
-
// 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)
^ -
@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. -
@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... -
@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.
-
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
-
changed to matlab --> https://github.com/Christoph-Lauer/Transfer-Function-Extractor-Matlab