WhisperCppAndroidDemo icon indicating copy to clipboard operation
WhisperCppAndroidDemo copied to clipboard

How choose file?

Open michoael opened this issue 2 years ago • 8 comments

I want choose file from storage, i don't need add sounds in resource. How i can do that? I hope answer to me, Thanks.

michoael avatar Jun 07 '23 07:06 michoael

Hi @michoael, for that you can use Storage Access Framework or Media Storage. Please see: https://developer.android.com/training/data-storage/shared/media

Digipom avatar Jun 07 '23 12:06 Digipom

I know this, but how connect it with cpp? I don't use side by side before this time 😁 I thing need add something in cpp right?

michoael avatar Jun 07 '23 14:06 michoael

Oh, hmm... no you don't really need anything in CPP for this that is different than the current code. In function suspend fun transcribeData(data: FloatArray) you could pass in data from audio file. There's two approaches you could use: 1) MediaExtractor + MediaCodec, 2) FFMPEG.

Using FFMPEG might be simpler depending on what you're doing with the application. https://github.com/arthenica/ffmpeg-kit

or https://github.com/bravobit/FFmpeg-Android

Then you can use FFMPEG to convert to 16000Hz for transcriptions and then read the file into memory.

I would recommend using FFMPEG as MediaCodec + MediaExtractor is low level and it's hard to find good sample code for it. However, one source is the Android CTS: https://android.googlesource.com/platform/cts/+/d04da01/tests/tests/media/src/android/media/cts/DecoderTest.java

With either approach, you may also want to read in only, say, 64MB at a time to avoid the app getting killed for using too much memory.

Digipom avatar Jun 07 '23 15:06 Digipom

Yes, i have old project i used ffmpeg and i already convert file to 16000Hz. I added result wav file on my phone. I use xml and java 😁 For this i have some difficulty to convert your code with kotlin and theme to xml and java. I hope bear me 😣 You can tell me what exactly i need convert classes?

michoael avatar Jun 07 '23 16:06 michoael

@michoael Ah, I don't have any experience going in the reverse direction (from Kotlin + compose to Java + xml). What I can say is that Google is putting all their efforts into Kotlin + compose going forward so it might be a good time to learn. :P

Digipom avatar Jun 08 '23 14:06 Digipom

Imm, i iasked because i have already app on google play created with java and xml. I think not convert it easy. I created xml 😅 Now i want know what any function kotlin connect with cpp to load model I think need convert libWhisper class to java But what more?

michoael avatar Jun 08 '23 15:06 michoael

You shouldn't have to do any changes on the C / JNI side (except function signatures, i.e. JNIEXPORT jlong JNICALL Java_com_example_whisper_WhisperLib_00024Companion_initContextFromFile). I think just converting libWhisper to Java would work. Instead of anything to do with coroutines, you can also use synchronized methods and just ensure you call it on a worker thread.

Digipom avatar Jun 08 '23 16:06 Digipom

Okay, thank you very much.

michoael avatar Jun 08 '23 17:06 michoael