1. 程式人生 > >學習音訊之android中AudioRecord採集音訊的引數說明

學習音訊之android中AudioRecord採集音訊的引數說明

android中採集音訊的apiandroid.media.AudioRecord

其中構造器的幾個引數就是標準的聲音採集引數

以下是引數的含義解釋

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

Class constructor.

Parameters

audioSource

the recording source. See  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. See and 

聲道設定:android支援雙聲道立體聲和單聲道。MONO單聲道,STEREO立體聲

audioFormat

編碼制式和取樣大小:採集來的資料當然使用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  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物件了

來自IT小小鳥的分享