Pergunta

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.

Foi útil?

Solução

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).

Outras dicas

Two important things:

  • you need to convert live bytes (from mic) to numeric values inorder to plot them.
  • Since you use a real-time graph, to plot those points use SurfaceView.

    Convert recording bytes to numeric values refer: Android: Listener to record sound if any sound occurs where you will see the variable "temp" holds the numerical value of your audio.

    Plot points These numeric values which indicates your Y values is plotted against increasing X (time interval) values (0,1,2..) as graph. Using SurfaceView eg..,

//canvas.drawLine(previous X value,previous Y value,X,Y, paint);
canvas.drawPoint(X,Y,paint);
SurfaceHolder.unlockCanvasAndPost(canvas);

You need not plot all values, for efficiency you can filter those values with your conditions and plot for certain intervals of time.

Hope this helps :)

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top