android:在模拟器上使用 MediaPlayer 录制音频
我正在尝试使用以下代码从 Android 模拟器上的麦克风录制音频:
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(Environment.getExternalStorageDirectory() + "/test/test.3gp");
try {
recorder.prepare();
}
catch (IOException io) {
Log.v(LOG_TAG, "Could not prepare the audio " + io.getMessage());
}
recorder.start();
为了停止音频,这是代码:
recorder.stop();
recorder.reset();
recorder.release();
录制过程工作正常,但生成的音频失真。当我录制 60 秒的音频并播放它时,它的持续时间显示为 120 秒。测量并不准确,但这只是为了给您一个想法。
只有 AMR_NB 编码器在我的模拟器上运行。我尝试过不同的输出格式,但结果总是相同的。
这是模拟器的限制还是我在这里做错了什么?
编辑1: 我也尝试过 AudioRecord 类,结果是相同的拖动音频。
谢谢。
I am trying to record audio from the microphone on the Android emulator with this code:
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(Environment.getExternalStorageDirectory() + "/test/test.3gp");
try {
recorder.prepare();
}
catch (IOException io) {
Log.v(LOG_TAG, "Could not prepare the audio " + io.getMessage());
}
recorder.start();
For stopping the audio, this is the code:
recorder.stop();
recorder.reset();
recorder.release();
The recording process works fine but the resulting audio that is distorted. When I record an audio for 60 seconds duration and play it, it's duration is being shown as 120 seconds. The measurement is not exact but the this is just to give you an idea.
Only the AMR_NB encoder is working on my emulator. I have tried different output formats but the result is always the same.
Is it a limitation of the emulator or am I doing something wrong here?
Edit 1:
I have tried the AudioRecord class too and the result is the same dragging audio.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一直在为同样的事情工作并找到了解决方案,尝试使用以下代码:
这工作正常。希望对你有帮助:)
I have been working for the same and found the solution, Try using the following code:
This is working perfactly. Hope it helps you :)