Skip to content
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

Java support ? #247

Open
eix128 opened this issue Oct 21, 2023 · 19 comments
Open

Java support ? #247

eix128 opened this issue Oct 21, 2023 · 19 comments

Comments

@eix128
Copy link

eix128 commented Oct 21, 2023

How can we implement it in java ?
its onnx ,
there is some sample example:
https://github.com/snakers4/silero-vad/tree/master/examples/java-example

I think it wont be too hard to make piper avalible to use in java because of onnx?

@synesthesiam
Copy link
Contributor

Using ONNX from Java would be straightforward. The harder part would be using piper-phonemize to convert text to phonemes.

@beqabeqa473
Copy link

We will need to make piper as a library and wrap it as a java native interface and also piper_phonemize should expose c-api functions. However for jni it is not strictly necessary, as it can work with c++ sources directly, there might be problems for example with other possible wrappers like swift-pm, so it would be good to have a native library with c-api exports.

@eix128
Copy link
Author

eix128 commented Oct 27, 2023

i already did java version.I will release it

@gregko
Copy link

gregko commented Nov 13, 2023

I'm also interested in Java interface and native Piper library. I'd like to make it into an installable TTS Engine for Android system, licensed under open source of course, and free. It could be then used in apps like my @voice Aloud Reader on Android to read articles, books etc. Or in many other such apps available in Google Play. Actually if someone would be interested in creating an Android APK or AAB package for installing Piper TTS on Android, I'd pay for the work within my humble means...

I could do this job myself, if I could find time for it. However I would need a list of all the source files and libraries (and source files within them) that needs to be compiled into a Piper TTS library, so that it could be compiled for Android (ARM and Intel processors) and the Java or Kotlin TTS API wrapper could then be added...

Greg

@csukuangfj
Copy link

@gregko
Please have a look at #257

sherpa-onnx is fully open-sourced and it is free. It provides jni interface and kotlin APIs.

@gregko
Copy link

gregko commented Nov 14, 2023 via email

@eix128
Copy link
Author

eix128 commented Nov 14, 2023

Well so i will release it asap...
Whats your favorite platform ?
You need on rasberrypi first ?

@gregko
Copy link

gregko commented Nov 14, 2023

I'm interested in Android platform (Intel and ARM processors), not rasberrypi... I imagine compiling Piper as a shared library (.so) for Android, then creating Java or Kotlin interfaces for it, where needed. @csukuangfj mentions another project, sherpa-onnx, which seems to be much bigger (includes also speech to text conversion, which I don't need), and can use Piper voices after some conversion. For now I don't know much more. Maybe converting Piper to Android shared library would be simpler.

Greg

@beqabeqa473
Copy link

sherpa is good of course and thanks to @csukuangfj but it contains unnecesary things unrelated to tts and i don't like an idea of lexicon stuff.

I almost finished a C-library for piper, and jni should not be hard to do after that.

However, @eix128, If you already have it, please open a pr or give us the link where we could download your wrapper and adapt to android tts api.

Thanks

@csukuangfj
Copy link

By the way, you can try different voices at https://huggingface.co/spaces/k2-fsa/text-to-speech
For each model at https://huggingface.co/spaces/k2-fsa/text-to-speech, there is a corresponding APK for you to download.

@gregko
Copy link

gregko commented Nov 14, 2023 via email

@beqabeqa473
Copy link

@gregko do you know another way of using a shared lib without JNI? I know there is fma, but i am not sure android supports it

@gregko
Copy link

gregko commented Nov 15, 2023

Do you mean using such library from Java? Or using it on Android system, which would be the same thing? I don't know about anything else but JNI, that is declaring C or C++ functions in a special way, to make them callable from Java. I don't know what fma is.

@csukuangfj
Copy link

Interesting, thank you! I see that they created separate apps (APK files) for several voices, just to try them by typing/pasting a text into their window and then pressing Play to listen. It could be a start for a true Android TTS engine, which would let the user download any pre-built voices (e.g. from GitHub) and then use them a high quality TTS, generated locally, therefore free, in any app that needs TTS service. Time permitting I’ll try to learn more and see if I could create such Piper TTS Engine for Android, and if it works well – upload to Google Play. This would be a real help to many users – currently the really high quality “neural” voices are available only at network voices – send text to some servers, obtain speech data to make sounds. It’s free for Google TTS packages, you have to pay $$$ if you want to use other services (e.g. Microsoft Azure TTS, Amazon Polly…) And still the inconvenience of having to have a very good net connection to listen. Greg From: Fangjun Kuang @.) @.> Sent: Monday, November 13, 2023 10:31 PM To: rhasspy/piper @.> Cc: Greg Kochaniak @.>; Mention @.> Subject: Re: [rhasspy/piper] Java support ? (Issue #247) @gregko https://github.com/gregko Please have a look at #257 <#257> sherpa-onnx is fully open-sourced and it is free. It provides jni interface and kotlin APIs. — Reply to this email directly, view it on GitHub <#247 (comment)> , or unsubscribe https://github.com/notifications/unsubscribe-auth/AANKO7HROJUH2DMMLDC7ZT3YELQYBAVCNFSM6AAAAAA6KLE2GOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBZGQ4DSMZYG4 . You are receiving this because you were mentioned.Message ID: @.>

@gregko
We have supported using sherpa-onnx to replace the Android system TTS engine in
k2-fsa/sherpa-onnx#508

You can find a YouTube video below:
https://www.youtube.com/watch?v=33QYuVzDORA

@eix128
Copy link
Author

eix128 commented Dec 31, 2023

Well , i have finished windows and linux x64 versions on java.
But i need some time for android.
I will release windows and linux asap.
And i have optimized it for java without copying data.
It works flawlessly and fast

@gregko
Copy link

gregko commented Dec 31, 2023

Sounds good. Is your code for Windows and Linux, or from calling from Java, available somewhere to play with?

@beqabeqa473
Copy link

@eix128 what do you mean without copying? Could you open this? It would be interesting to see.

@csukuangfj
Copy link

i don't like an idea of lexicon stuff.

@gregko

We don't need a lexicon.txt anymore. We also support piper-phonemize in sherpa-onnx for models from piper.

All models from piper are supported in sherpa-onnx.

@csukuangfj
Copy link

FYI: Now we also provide Java APIs for piper TTS models. You don't need to know Kotlin to use it. It is pure Java.

Please see
https://github.com/k2-fsa/sherpa-onnx/blob/master/java-api-examples/run-non-streaming-tts-piper-en.sh

https://github.com/k2-fsa/sherpa-onnx/blob/master/java-api-examples/NonStreamingTtsPiperEn.java

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

No branches or pull requests

5 participants