Created
December 8, 2020 04:31
-
-
Save farmaker47/76fbd4a55874c5d4ee39592e37dc2f5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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