Skip to content

Instantly share code, notes, and snippets.

@farmaker47
Created December 8, 2020 04:31
Show Gist options
  • Save farmaker47/76fbd4a55874c5d4ee39592e37dc2f5d to your computer and use it in GitHub Desktop.
Save farmaker47/76fbd4a55874c5d4ee39592e37dc2f5d to your computer and use it in GitHub Desktop.
private val readAudio = Runnable {
var readBytes: Int
buffer = ShortArray(BUFFER_SIZE)
while (mRecording) {
readBytes = mRecorder!!.read(buffer, 0, BUFFER_SIZE)
//Higher volume of microphone
//https://stackoverflow.com/questions/25441166/how-to-adjust-microphone-sensitivity-while-recording-audio-in-android
if (readBytes > 0) {
for (i in 0 until readBytes) {
buffer[i] = Math.min(
(buffer[i] * 6.7).toInt(),
Short.MAX_VALUE.toInt()
).toShort()
}
}
if (readBytes != AudioRecord.ERROR_INVALID_OPERATION) {
for (s in buffer) {
// Add all values to arraylist
bufferForInference.add(s)
writeShort(mPcmStream, s)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment