如何实现以byteArray形式接收的语音信号的语音活动检测。如何检查收到的信号是否有语音? 以字节数组形式接收音频的android代码的当前实现是:
公共类AudioRecordActivity扩展了AppCompatActivity {
private static final int RECORDER_BPP = 16;
private static final int RECORDER_SAMPLERATE = 8000;
private static final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
private static final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
short[] audioData;
/*Complex[] fftTempArray;
Complex[] fftArray;*/
int[] bufferData;
int bytesRecorded;
private AudioRecord recorder = null;
private int bufferSize = 0;
private Thread recordingThread = null;
private boolean isRecording = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio_record);
ActivityCompat.requestPermissions(AudioRecordActivity.this,
new String[]{Manifest.permission.RECORD_AUDIO},
1);
Button startRecording = (Button) findViewById(R.id.startRecording);
bufferSize = AudioRecord.getMinBufferSize
(RECORDER_SAMPLERATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING) * 3;
audioData = new short[bufferSize]; //short array that pcm data is put into.
Toast.makeText(this, "buffer size"+bufferSize, Toast.LENGTH_SHORT).show();
}
public void startRecording(View view) {
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE,
RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING,
bufferSize);
int i = recorder.getState();
if (i == 1)
recorder.startRecording();
isRecording = true;
recordingThread = new Thread(new Runnable() {
@Override
public void run() {
writeAudioDataToFile();
}
}, "AudioRecorder Thread");
recordingThread.start();
}
public void stopRecording(View view) {
if (null != recorder) {
isRecording = false;
int i = recorder.getState();
if (i == 1)
recorder.stop();
recorder.release();
recorder = null;
recordingThread = null;
}
}
private void writeAudioDataToFile() {
byte data[] = new byte[bufferSize];
int read = 0;
while (isRecording) {
read = recorder.read(data, 0, bufferSize);
/* if (read > 0) {
}
if (AudioRecord.ERROR_INVALID_OPERATION != read) {
try {
os.write(data);
} catch (IOException e) {
e.printStackTrace();
}
}*/
Log.d("buffersize", bufferSize + "");
Log.d("data", Arrays.toString(data));
}
}
}
}
如何在android中实现VAD?