在android中采集音频的api是android.media.AudioRecord类
在android中播放音频也是从api中的类分析
其中构造器的几个参数就是标准的声音采集参数
以下是参数的含义解释
1. 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. 采样率:音频的采样频率,每秒钟能够采样的次数,采样率越高,音质越高。给出的实例是44100、22050、11025但不限于这几个参数。例如要采集低质量的音频就可以使用4000、8000等低采样率。 |
channelConfig |
describes the configuration of the audio channels. See 声道设置:android支持双声道立体声和单声道。MONO单声道,STEREO立体声 |
audioFormat |
the format in which the audio data is represented. See 编码制式和采样大小:采集来的数据当然使用PCM编码(脉冲代码调制编码,即PCM编码。PCM通过抽样、量化、编码三个步骤将连续变化的模拟信号转换为数字编码。) |
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. SeegetMinBufferSize(int, 采集数据需要的缓冲区的大小,如果不知道最小需要的大小可以在getMinBufferSize()查看。 |
采集到的数据保存在一个byteBuffer中,可以使用流将其读出。亦可保存成为文件的形式。
android.media.AudioTrack.AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode) throws
IllegalArgumentException
2. public AudioTrack (int streamType, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, int mode)
streamType | the type of the audio stream. See STREAM_VOICE_CALL ,STREAM_SYSTEM ,STREAM_RING ,STREAM_MUSIC andSTREAM_ALARM |
---|---|
sampleRateInHz | the sample rate expressed in Hertz. Examples of rates are (but not limited to) 44100, 22050 and 11025. |
channelConfig | describes the configuration of the audio channels. See CHANNEL_OUT_MONO andCHANNEL_OUT_STEREO |
audioFormat | the format in which the audio data is represented. See ENCODING_PCM_16BIT andENCODING_PCM_8BIT |
bufferSizeInBytes | the total size (in bytes) of the buffer where audio data is read from for playback. If using the AudioTrack in streaming mode, you can write data into this buffer in smaller chunks than this size. If using the AudioTrack in static mode, this is the maximum size of the sound that will be played for this instance. See getMinBufferSize(int, int, int) to determine the minimum required buffersize for the successful creation of an AudioTrack instance in streaming mode. Using values smaller than getMinBufferSize() will result in an initialization failure. |
mode | streaming or static buffer. See MODE_STATIC andMODE_STREAM |
Throws
IllegalArgumentException |
---|