Digipom/WhisperCppAndroidDemo

How choose file?

Opened this issue ยท 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.

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

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?

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.

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 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

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?

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.

Okay, thank you very much.