Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Recording audio from android device
I have a little problem. I am programming application which will record audio from android device via microphone. I tried QAudioRecorder but this class have output as file. But I just need output to memory. Someone told me QAudioInput is better for me. So my question is how I can work with buffer. If I will have buffer I copy data to another array. I must know size of buffer, type of data (int, float, short, etc.) and how/where i can access to buffer.
I am sorry, my English is not good.
Hi and welcome to devnet,
You can use QBuffer as output for your QAudioInput recording.
fkop last edited by fkop
but i have another problem. I am trying open a device for Read mode, because i need to read data from device to buffer and then write them to file. I want to check that buffer really record audio.
e.g. - qio->read(buffer.data(), size); - i hope this command is ok
but - idk what have to be in bracket - if (qio->open(...) == true) - qio is name of QIODevice object
Then why not write directly to the file ?
Because I need do fft from the audio signal and I don't want do it from file, but from memory.
qiosupposed to be ?
Depending on your needs you can also simply work with the QIODevice created when calling start. You can then connect the readyRead signal from said device to your processing function and write the result to the file you want to create.
qio is QIODevice object,
I guess my problem is, that I don't know which "openMode" is used. I tried print number of mode, but i don't know, how to print it :-).. I tried qWarning, but it just print text and std::cout not run.
My command was: qWarning << qio->openMode(); In documentation is written, that method returns which device is opened.
Here is similar example:
m_audioInput = new QAudioInput(m_format);
m_input = m_audioInput->start();
qint16 *ptr = new qint16;
bytes_ready = m_audioInput->bytesReady();
m_input->read(buffer.data(), bytes_ready); - - My problem. In my opinion, here is device sets as Not opened.
ptr = reinterpret_cast<qint16*>(buffer.data());
My situation is, that I need record audio signal from device to buffer. Then i must do 50% overlay of signal for FFT. After I do FFT, I must count MFCC and send it somewhere. For FFT and MFCC I have prepare libraries. So I just need arrays with 50% overlay.
From your code it seems that you are trying to read from the input directly after opening it. That's not how it works. Connect the readyRead signal from the device you received to a slot from your class where you'll read the content that is available and then you can further process it to your needs.
Is there any option, that i get same count of samples in every calling of slot. I need 50 % overlap, so if count of samples were pretty aligned, it would be nice of Qt.
IIRC with the defaults you get a pretty regular number of samples.