Recording audio from android device
-
Hi,
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.
-
Thanks,
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 ?
-
What is
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:
QAudioInput *m_audioInput;
QIODevice *m_input;
QByteArray buffer(262144,0);m_audioInput = new QAudioInput(m_format);
m_audioInput->setBufferSize(262144);
m_input = m_audioInput->start();qint64 bytes_ready;
qint16 *ptr = new qint16[262144];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());
-
-
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.
-
IIRC with the defaults you get a pretty regular number of samples.