From fdb785e516c59e0576baa5cc49238e34a703308c Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Sun, 18 Nov 2012 23:00:38 +0100 Subject: [PATCH] add an example of TTS --- docs/source/android.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/source/android.rst b/docs/source/android.rst index c5db217..60eefca 100644 --- a/docs/source/android.rst +++ b/docs/source/android.rst @@ -209,3 +209,25 @@ You'll obtain something like this:: [-0.0095768067985773087, 9.4235782623291016, 2.2122423648834229] ... + +Using TextToSpeech +------------------ + +Same as the audio capture, by looking at the +By looking at the `An introduction to Text-To-Speech in Android +`_ blog post, it's easy to do it with Pyjnius:: + + from jnius import autoclass + Locale = autoclass('java.util.Locale') + PythonActivity = autoclass('org.renpy.android.PythonActivity') + TextToSpeech = autoclass('android.speech.tts.TextToSpeech') + tts = TextToSpeech(PythonActivity.mActivity, None) + + # Play something in english + tts.setLanguage(Locale.US) + tts.speak('Hello World.', TextToSpeech.QUEUE_FLUSH, None) + + # Queue something in french + tts.setLanguage(Locale.FRANCE) + tts.speak('Bonjour tout le monde.', TextToSpeech.QUEUE_ADD, None) +