Raw audio packets to WAV/GSM_MS compliant file on Android - android

I'm looking for the logic/code-snippet which can convert my raw audio packets to WAV/GSM_MS complaint audio file. I'm able to capture data from android device mic and store it in buffer or file.

Assuming your raw data is already in interleaved, All you need is to prepend wave header in the beginning. The wave header format is given here https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
When you create a new wave file always write the header (with data length field set to zero as you dont know the entire size of data you wish to write at the at beginning of recording) then start writing your data immediately after the header, once you are done writing the data to it seek to the beginning and update the data length field.
here http://www.codeproject.com/Articles/129173/Writing-a-Proper-Wave-File is a code for the same.

Related

Play audio from array of bytes in android?

I want to stream live audio from one device to many devices . I am recording my voice in android and while its recording i am sending bytes to server and again receiving those bytes on different devices what i am getting is array of bytes and i am getting so many array of bytes every second . Now want to play those bytes as audio . media player require file to play but i cant save it into file because data is still coming i am very confused either i am doing it in wrong way . Actua i want to made two apps in one app we speak something and in another app we can listen what is someone speaking at that side in real time .
The AudioTrack class allows streaming of PCM audio buffers, via write (byte[] audioData, int offsetInBytes, int sizeInBytes) (among other methods).

Convert raw bytes to audio in Matlab

Here's the problem: I send a small audio file (~10Kb) from android to matlab through tcp socket. The matlab script get the file, but android's outputstream sends raw byte. How can I reconstruct the original audio file in matlab?
The problem that you have here is of the variables type.
Over TCP most probably the audio data are sent as 16int or 16uint (assuming that there are functions/methods that properly transform 16int or 16uint to bytes in order to be written to the buffer to be sent over TCP).
First of all you will have to check:
The endian that the data are sent
The type that the audio data have in android (most probably 16int but check it just in case)
Then, you will have to read these data from a file and transform it in doubles. For that purpose there are quite a few examples out there. A most simple approach will be to map the values into a new range after you just convert them to doubles with the double function of MATLAB.
For mapping values there is the mapminmax method

How to correctly stream data via Bluetooth to Android

I'm in the process of developing an application which reads data from a DAQ that streams its data over Bluetooth. The packet sizes can change, as can the sampling rate (1Hz - 512Hz), and I'm able to loop through and read the data off the device using a buffer.
My question is, how do I correctly process the data when there is such a variable of packet size and sampling rate? How do I determine the buffer size?
Currently I'm simply opening a socket, opening an input stream, and then using a while loop (while the socket is open == true) to read from the stream, and process the data (simple decoding, not an extraneous task).
As an example, there are 23 bytes in a packet, and I have the sampling rate very low at the moment at 1Hz. I have a buffer of 256 bytes, which means that it wont accommodate a full packet at the end of the buffer, and I've written code for it to run over onto the next buffer. Once the data is read grab one packet from the buffer, decode and store it, do the next one, etc.
How should I be streaming, and manipulating the data correctly? Eventually I'll be grabbing something in the region of 44 packets at 512Hz, right at Bluetooths transfer limit, and I want to be able to process it as effective as possible, and display errors when a packet is dropped in the process, etc.
TL;DR: how do I correctly stream data using buffers and/or interrupts.

Extracting Raw Voice Data from AndroidSmart Phone Microphone

I need to know how to extract raw voice data from android real time. The data should be in time domain.
You can try http://eagle.phys.utk.edu/guidry/android/index.html
or
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html

CallBack for the recorded block in MediaRecorder

I am trying to record a voice from Mic using Media Recorder class. in the mentioned class we have just setOutputFile method to set the output file, but I need to get a buffer of some certain recorded voice, I mean i need something like a CallBack method that return a block of recorded byte at that time and i am going to send the mentioned bytes to another device...
Actually I want to stream and send the recorded voice through socket to another device simultaneously not saving the recorded voice and then read the file and send it, due to it results an unexpected delay...
Alireza,
This can be done pretty easily. All you have to do is set up a socket, from that socket you create a ParcelFileDescriptor, then set this file descriptor in setOutputFile. This will set up the streaming part, but then you will have some formatting issues with the file afterwards. This is because MediaRecorder reserves the header space of the file, but only writes it after the stream has finished. In order to have a functional file on the server-side, you will have to parse the header, and write it to the beginning of the file (or buffer).
Good luck,
B-Rad

Categories

Resources