Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

Can I use MediaRecorder to record audio with capture silence detection in Android?

I use MediaRecorder to record audio, is it possible to detect the silence and stop recording voice when the user hasn't spoken for some seconds and record again automatically when the user recover to speak?

question from:https://stackoverflow.com/questions/65929741/can-i-use-mediarecorder-to-record-audio-with-capture-silence-detection-in-androi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No, in order to detect silence you need to inspect the audio data.

MediaRecorder just writes the audio to a file as can be seen in MediaRecorder's state machine diagram.

The solution would be to use AudioRecord and analyze the data before writing the bytes to a file. Since you want to resume recording, you'll need to the keep the mic open and process the incoming audio for the user speaking.

The subject of analyzing digital audio data is known as signal processing where you can find a number of resources:

Simplest way of detecting where audio envelopes start and stop

What dBFS threshold should I set for differentiation between silence and NOT silence

But for a first attempt, I would use Audio record in android and FFT and assume a quiet room. You'll have to come up with an appropriate trigger level (see above links).

Be aware that processing does add some lag and you'll have to compensate, i.e. buffer 0 has silence, buffer 1 the user starts to speak but doesn't trigger threshold, buffer 2 user is speaking and threshold is triggered. You may want to save buffer 1 in addition to buffer 2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...