-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase Inference Frequency (Android) #48
Comments
HI Brett, Would it be possible to share the swift code for sliding window? Perhaps I can provide a suggestion once I get an idea how it is implemented. Michael |
Here is the code that implements a sliding window to read to store audio. `
` https://www.tensorflow.org/lite/android/tutorials/audio_classification by modifying the "interval" executor = ScheduledThreadPoolExecutor(1) code in the tutorial, I was able to increase inference speed without implementing a sliding window buffer, however, I was not able to figure out how to do this in the Plugin code |
Oh I see how it is implemented. Though compared with Swift/Kotlin, manipulating arrays in Java is such a pain. 😆 To achieve window sliding, simply replace the following below with your own code. For example: Modify the For example: public void splice(){
if (record.getState() != AudioRecord.STATE_INITIALIZED) {
Log.e(LOG_TAG, "Audio Record can't initialize!");
return;
}
while (shouldContinue) {
short[] shortData = new short [bufferSize];
record.read(shortData, 0, shortData.length);
recordingBufferLock.lock();
try {
//Add window spliding function here
//When array fills up, call the function `recordingData.emit(<ADD ARRAY HERE>);` to emit the data for recognition
//Clear out array once it’s been emitted, and repeat window sliding
//If you wish stop the recording, call the `stop()` function
} finally {
recordingBufferLock.unlock();
}
}
let me know if this helps. |
Ok yeah I'll see if I can piece something together. If not, I may use the kotlin code to put together a new android plugin. Would be happy to share that if so. |
No problems. If you do have a solution, the Flutter community and I would appreciate your contribution very much :) |
Hey man, thanks for this awesome plugin. I was looking to increase the number of times per second I run my model. I was able to implement a sliding window in the swift code, but I'm not super familiar with Java or Android development. I was wondering if you could provide some suggestions on how to accomplish this?
Thanks,
Brett
The text was updated successfully, but these errors were encountered: