我正在 Android 中开发一个应用程序,它必须记录声音并在屏幕上显示一些代表声音频率或强度的值。
为了记录,我使用了这段代码:
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(name);
mRecorder.prepare();
mRecorder.start();
然后我最初试图将存储的文件转换为这样的字节:
DataInputStream dis1 = new DataInputStream ( new FileInputStream (name));
byte[] datainBytes1 = new byte[dis1.available()];
dis1.readFully(datainBytes1);
dis1.close();
但我想将该字节值转换为 short 或 float 以使用绘图方法显示它们:
canvas.drawLine(xini,yini,xfinal,yfinal,paint)
您能否推荐我另一种将音频文件转换为我可以绘制的短值的方法?
非常感谢您的帮助!!