咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

Android 录音简单示例

1
requestPermissions(new String[]{"android.permission.RECORD_AUDIO"},1009);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class RecordAudioThread extends Thread{

AudioRecord recorder;

@Override
public void run() {
super.run();
int minBufferSize = AudioRecord.getMinBufferSize(
8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
recorder = new AudioRecord(
MediaRecorder.AudioSource.MIC,
8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);
recorder.startRecording();

byte[] audio = new byte[1024];

int readLength = 0;
while (!isInterrupted()){
readLength = recorder.read(audio,0,audio.length);

if(readLength > 0){
Log.d(TAG, "录音长度:" + readLength);
}
}
recorder.stop();
recorder.release();
Log.i(Thread.currentThread().getName() , "录音结束");
}
}