Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Visualizer while recording audio in android

I know Visualizer to show some wave while playing audio using android Media Player.

But i want to show Visualizer while recording audio means while recording i want to show linear wave which changes based on user voice beat.

Is it possible to do in android.

like image 251
koti Avatar asked Nov 26 '12 05:11

koti


2 Answers

You may need to use AudioRecorder class instead of MediaRecorder.

Check AudioRecorder#read(...) methods which put audio data to byte[] instead of putting it directly to a file.

To show changes on the graph you will have to analyze the data (which is encoded in PCM 8 or 16 bit - link) and update the graph in real time.

like image 50
MeTTeO Avatar answered Sep 24 '22 15:09

MeTTeO


by calling every x milliseconds your MediaRecorder.getMaxAmplitude(), you gonna have (from official documentation) :

the maximum absolute amplitude that was sampled since the last call to this method.

then, you can process this value in real time to draw a graph or change some view properties.
not perfect, but I hope it helps =)

edit: just so you know, the retrieved value will be the same across all android devices : between 0 and 32767. (I have more than 10k user's reports giving me this value when they blow in the mic).

like image 21
elgui Avatar answered Sep 25 '22 15:09

elgui