如何使用Android上的麦克风

人气:1,251 发布:2022-09-10 标签: android

问题描述

我刚刚开始发展自己的第一款Android应用程序,我有一个很难搞清楚如何启动麦克风并让它听着,这是我的应用程序的一个主要特征。

I have just started to develop my first Android app, and I am having a hard time figuring out how to start the microphone and have it listen, which is a main feature of my app.

我已经搜查了Android文档,我不能找到这么多的信息。

I've searched the Android docs and I can't find much info on this.

在此先感谢。

推荐答案

这也许可以帮助(实际上从Android文档): 音频捕获

Maybe this can help (actually from the Android docs): Audio Capture

创建的新实例 android.media.MediaRecorder 。 设置使用音频源 MediaRecorder.setAudioSource()。你可能会想用 MediaRecorder.AudioSource.MIC 。 在使用设置输出文件格式 MediaRecorder.setOutputFormat()。 设置使用的输出文件名 MediaRecorder.setOutputFile()。 使用设置音频连接codeR MediaRecorder.setAudioEn codeR()。 呼叫 MediaRecorder。prepare() MediaRecorder 实例。 要启动音频采集,呼叫 MediaRecorder.start()。 要停止音频采集,呼叫 MediaRecorder.stop()。 当你用 MediaRecorder 情况下完成的,叫 MediaRecorder.release()就可以了。呼叫 MediaRecorder.release()总是建议立即释放资源。 Create a new instance of android.media.MediaRecorder. Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC. Set output file format using MediaRecorder.setOutputFormat(). Set output file name using MediaRecorder.setOutputFile(). Set the audio encoder using MediaRecorder.setAudioEncoder(). Call MediaRecorder.prepare() on the MediaRecorder instance. To start audio capture, call MediaRecorder.start(). To stop audio capture, call MediaRecorder.stop(). When you are done with the MediaRecorder instance, call MediaRecorder.release() on it. Calling MediaRecorder.release() is always recommended to free the resource immediately.

或: Android的音频录制教程

167