Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

How choose file? #6

Open
michoael opened this issue Jun 7, 2023 · 8 comments
Open

How choose file? #6

michoael opened this issue Jun 7, 2023 · 8 comments

Comments

@michoael
Copy link

michoael commented Jun 7, 2023

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.

@Digipom
Copy link
Owner

Digipom commented Jun 7, 2023

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 Digipom closed this as completed Jun 7, 2023
@michoael
Copy link
Author

michoael commented Jun 7, 2023

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?

@Digipom
Copy link
Owner

Digipom commented Jun 7, 2023

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 Digipom reopened this Jun 7, 2023
@michoael
Copy link
Author

michoael commented Jun 7, 2023

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?

@Digipom
Copy link
Owner

Digipom commented Jun 8, 2023

@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

@michoael
Copy link
Author

michoael commented Jun 8, 2023

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?

@Digipom
Copy link
Owner

Digipom commented Jun 8, 2023

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.

@michoael
Copy link
Author

michoael commented Jun 8, 2023

Okay, thank you very much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants