This commit is contained in:
isp
2024-09-10 19:30:49 -07:00
parent c04123ea84
commit 32b41a6b0e

View File

@@ -52,6 +52,12 @@ class SoundRecorder(
val thread = Thread { val thread = Thread {
while (true) { while (true) {
if (Thread.interrupted()) {
// check for the interrupted flag, reset it, and throw exception
Log.w(TAG,"Finished thread");
break;
}
Log.w(TAG,"Loop");
val out = audioRecord.read( val out = audioRecord.read(
/* audioData = */ audio_bytes_array, /* audioData = */ audio_bytes_array,
/* offsetInBytes = */ 0, /* offsetInBytes = */ 0,
@@ -64,13 +70,20 @@ class SoundRecorder(
// Log.w(TAG, audio_bytes_array.size.toString()); // Log.w(TAG, audio_bytes_array.size.toString());
val str_beg = audio_bytes_array[0].toString() val str_beg = audio_bytes_array[0].toString()
val str_end = audio_bytes_array[bufferSizeInBytes-1].toString() val str_end = audio_bytes_array[bufferSizeInBytes-1].toString()
Log.w(TAG, str_beg + ", " + str_end); // Log.w(TAG, str_beg + ", " + str_end);
// MessageSender.sendMessage("/audio",audio_bytes_array, context) // MessageSender.sendMessage("/audio",audio_bytes_array, context)
} }
}; };
thread.start(); thread.start();
cont.invokeOnCancellation {
audioRecord.stop();
audioRecord.release()
thread.interrupt();
state = State.IDLE
}
} }
} }