Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stream audio to http-post in Android

I'm trying to

  1. record voice from an Android device,
  2. have the data encoded as some audio encoding (M4A, FLAC, Ogg)
  3. stream upload it to my server (chunked http post) - while the recording is ongoing.

Any ideas how to achieve these ?


I tried to do use Android's MediaRecorder (which records audio, encodes it and saves to File) and to use Android's HttpClient with InputStreamEntity which allows uploading data from an input stream. I used "StreamingLoop" from https://github.com/Teaonly/android-eye/blob/master/src/teaonly/droideye/StreamingLoop.java to connect the output file descriptor to the inputStream so I could use the MediaRecorder's output for the HttpClient's input.

However this failed - When I stop the recording I get:

06-27 17:58:47.259: A/libc(6759): Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1), thread 6759

which crashes the application, and the file that arrives to the server is unplayable by VLC, so this is twice a failure.

Any ideas for a different method to do requirements 1..3 above or how to debug it?

like image 536
Iftah Avatar asked Jun 27 '13 15:06

Iftah


1 Answers

use Audiorecord class and not mediaRecorder. API for the former gives you direct access to the buffer backing the microphone. You have control over a handler that writes from the buffer to a stream ( as in http chunked-encoding connection ). That will handle your streaming requirement.

Look at a git proj using audioRecord...

https://github.com/Audioboo/audioboo-android?source=c

see class=FLACRecorder.run() where it reads the AudioRecord buffer and writes it to the encoder(FLAC). If you want to stream the flac-encoded bytes, you can use this app , get the bytes downstream of the encoder and write that to the http connection like in this class.

like image 179
Robert Rowntree Avatar answered Sep 24 '22 15:09

Robert Rowntree