Android AudioRecord 与 MediaRecorder 录制音频

发布于 2024-11-05 16:35:06 字数 533 浏览 1 评论 0原文

我想在我的 Android 手机上录制人声。我注意到 Android 有两个类可以执行此操作: AudioRecordMediaRecorder。有人可以告诉我两者之间有什么区别以及两者的合适用例是什么?

我希望能够实时分析人类语音以测量幅度等。我是否正确理解 AudioRecord 更适合此任务?

我在官方 Android 录制音频的指南网页上注意到,他们使用 MediaRecorder没有提到 AudioRecord。

I want to record human voice on my Android phone. I noticed that Android has two classes to do this: AudioRecord and MediaRecorder. Can someone tell me what's the difference between the two and what are appropriate use cases for each?

I want to be able to analyse human speech in real-time to measure amplitude, etc. Am I correct in understanding that AudioRecord is better suited for this task?

I noticed on the official Android guide webpage for recording audio, they use MediaRecorder with no mention of AudioRecord.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别把无礼当个性 2024-11-12 16:35:06

如果您想在录制过程中进行分析,则需要使用 AudioRecord,因为 MediaRecorder 会自动录制到文件中。 AudioRecord 的缺点是,在调用 startRecording() 后,您需要自己从 AudioRecord 实例中轮询数据。另外,您必须足够快地读取和处理数据,以便内部缓冲区不会溢出(查看 logcat 输出,AudioRecord 会告诉您何时发生这种情况)。

If you want to do your analysis while recording is still in progress, you need to use AudioRecord, as MediaRecorder automatically records into a file. AudioRecord has the disadvantage, that after calling startRecording() you need to poll the data yourself from the AudioRecord instance. Also, you must read and process the data fast enough such that the internal buffer is not overrun (look in the logcat output, AudioRecord will tell you when that happens).

自此以后,行同陌路 2024-11-12 16:35:06

据我了解 MediaRecorder 是一个黑匣子,它在输出上提供压缩的音频文件,而 AudioRecorder 只为您提供原始声音流,您必须自己压缩它。

MediaRecorder 为您提供上次调用 getMaxAmplitude() 方法的最大振幅,以便您可以实现声音可视化工具。

因此,在大多数情况下,MediaRecorder 是最佳选择,除非您需要进行一些复杂的声音处理并且需要访问原始音频流。

As I understand MediaRecorder is a black box which gives compressed audio file on the output and AudioRecorder gives you just raw sound stream and you have to compress it by yourself.

MediaRecorder gives you the max amptitude from last call of getMaxAmplitude() method so you can implement a sound visualizer for example.

So in most cases MediaRecorder is the best choice except those in which you should make some complicated sound processing and you need access to the raw audio stream.

凉城 2024-11-12 16:35:06

AudioRecorderer 首先将数据保存在 minBuffer 中,然后将其从那里复制到临时缓冲区,在 MediaRecorder 中将其复制到文件。
在 AudioRecorder 中,我们需要 api setRecordPosition() 将保存的数据复制到所需位置,而在 MediaRecorder 中,文件指针完成此工作来设置标记的位置。
AudioRecorder 可用于在模拟器上运行的应用程序,这可以通过提供低采样率(例如 8000)来完成,而使用 MediaRecorder 时无法使用模拟器录制音频。
在 AudioRecord 中,屏幕会在一段时间后休眠,而在 MediaRecorder 中,屏幕不会休眠。

AudioRecorderer first saves data in minBuffer then it is copied from there to the temporary buffer, in MediaRecorder it is copied to files.
In AudioRecorder we need the api setRecordPosition() to copy the saved data at required position, whereas in MediaRecorder the file pointer is does this job to set the position of the marker.
AudioRecorder can be used to those apps which run on an emulator this can be done by providing low sample rate such as 8000, while using MediaRecorder the audio cannot be recorded using emulator.
In AudioRecord the screen sleep after sometime, while in MediaRecorder the screen does not sleep.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文