android中采集音频的apiandroid.media.AudioRecord

其中构造器的几个参数就是标准的声音采集参数

以下是参数的含义解释

public AudioRecord (int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)

Since: API Level 3

Class constructor.

Parameters

audioSource

the recording source. See MediaRecorder.AudioSource for recording source definitions.

音频源:指的是从哪里采集音频。这里我们当然是从麦克风采集音频,所以此参数的值为MIC

sampleRateInHz

the sample rate expressed in Hertz. Examples of rates are (but not limited to) 44100, 22050 and 11025.

采样率:音频的采样频率,每秒钟能够采样的次数,采样率越高,音质越高。给出的实例是441002205011025但不限于这几个参数。例如要采集低质量的音频就可以使用40008000等低采样率。

channelConfig

describes the configuration of the audio channels. SeeCHANNEL_IN_MONO and CHANNEL_IN_STEREO

声道设置:android支持双声道立体声和单声道。MONO单声道,STEREO立体声

audioFormat

the format in which the audio data is represented. SeeENCODING_PCM_16BIT and ENCODING_PCM_8BIT

编码制式和采样大小:采集来的数据当然使用PCM编码(脉冲代码调制编码,即PCM编码。PCM通过抽样、量化、编码三个步骤将连续变化的模拟信号转换为数字编码。) android支持的采样大小16bit 或者8bit。当然采样大小越大,那么信息量越多,音质也越高,现在主流的采样大小都是16bit,在低质量的语音传输的时候8bit 足够了。

bufferSizeInBytes

the total size (in bytes) of the buffer where audio data is written to during the recording. New audio data can be read from this buffer in smaller chunks than this size. See getMinBufferSize(int, int, int) to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Using values smaller than getMinBufferSize() will result in an initialization failure.

采集数据需要的缓冲区的大小,如果不知道最小需要的大小可以在getMinBufferSize()查看。

采集到的数据保存在一个byteBuffer中,可以使用流将其读出。亦可保存成为文件的形式。

注意:
1、AudioSource:这里可以是MediaRecorder.AudioSource.MIC
2、SampleRateInHz:录制频率,可以为8000hz或者11025hz等,不同的硬件设备这个值不同
3、ChannelConfig:录制通道,可以为AudioFormat.CHANNEL_CONFIGURATION_MONO和 AudioFormat.CHANNEL_CONFIGURATION_STEREO
4、AudioFormat:录制编码格式,可以为AudioFormat.ENCODING_16BIT和8BIT,其中16BIT的仿真性比8BIT好,但是需要消耗更多的电量和存储空间
5、BufferSize:录制缓冲大小:可以通过getMinBufferSize来获取

这样我们就可以实例化一个AudioRecord对象了

更多相关文章

  1. Fragment 和 Activity 全通讯
  2. Android(安卓)UI设计--新闻或信息条数的实现
  3. android第一天(小有成就,散分)
  4. 我的android——OpenGL(2)——gl10方法解析
  5. Android(安卓)友盟快速集成 社会化分享 移动统计
  6. Android(安卓)关于lambda 的下划线
  7. Android(安卓)Activity界面切换添加动画特效 (修改)
  8. Android(安卓)SDCard的容量大小
  9. RK3288 android 7.1.2屏蔽开机音频

随机推荐

  1. Android(安卓)Animation 动画的使用方法
  2. Android开发指南--0 总览
  3. android处理键盘事件之物理按键 (一)
  4. 自定义ListView背景(解决了拖动变黑的效果
  5. HTML5移动Web应用程序的JavaScript 框架
  6. Android Studio 出现 Gradle's dependenc
  7. 深度揭秘android摄像头的autoFocus-----
  8. Android平台架构简介
  9. Android开发中的autocomplete控件
  10. 开始学习android