我发现这个Android代码在他/她开始讲话时记录用户声音并在他/她停止时停止录制.但问题是录音停止很快.如果想说两个单词,它只记录第一个单词.
如何更改以下代码以使录制过程对瞬间沉默不那么敏感?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final int RECORDER_BPP = 16;
int RECORDER_SAMPLERATE = 8000;
int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
// Get the minimum buffer size required for the successful creation of
// an AudioRecord object.
int bufferSizeInBytes = AudioRecord
.getMinBufferSize(RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING);
// Initialize Audio Recorder.
AudioRecord audioRecorder = new AudioRecord(
MediaRecorder.AudioSource.MIC, RECORDER_SAMPLERATE,
RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSizeInBytes);
// Start Recording.
audioRecorder.startRecording();
int numberOfReadBytes = 0;
byte audioBuffer[] = new byte[bufferSizeInBytes];
boolean recording = false; …Run Code Online (Sandbox Code Playgroud)