11 package ai.picovoice.rhino;
13 import android.content.Context;
14 import android.media.AudioFormat;
15 import android.media.AudioRecord;
16 import android.media.MediaRecorder;
17 import android.os.Handler;
18 import android.os.Looper;
19 import android.os.Process;
20 import android.util.Log;
22 import java.util.concurrent.Callable;
23 import java.util.concurrent.Executors;
59 Executors.newSingleThreadExecutor().submit(
new Callable<Void>() {
62 android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
63 final int minBufferSize = AudioRecord.getMinBufferSize(
65 AudioFormat.CHANNEL_IN_MONO,
66 AudioFormat.ENCODING_PCM_16BIT);
69 AudioRecord audioRecord =
null;
73 boolean isFinalized =
false;
75 audioRecord =
new AudioRecord(
76 MediaRecorder.AudioSource.MIC,
78 AudioFormat.CHANNEL_IN_MONO,
79 AudioFormat.ENCODING_PCM_16BIT,
81 audioRecord.startRecording();
83 while (!isFinalized) {
84 if (audioRecord.read(buffer, 0, buffer.length) == buffer.length) {
89 }
catch (
final Exception e) {
98 Log.e(
"RhinoManager", e.toString());
101 if (audioRecord !=
null) {
102 audioRecord.release();
123 Log.e(
"RhinoManager", e.toString());
136 public void delete() {