Making an Android device speak a text input
In this recipe, we will see how an Android device generates sound from the supplied text. That is, the device will speak the specified text.
How to do it...
In this recipe, we will be making use of the ttsSpeak()
method, which activates the speech synthesis application on an Android device and the device will generate sound for the supplied text.
Let's take a look at the following steps:
- Type the following code in the Python script
demoTextToSpeach.py
in the current folder of your computer:
import androidapp = android.Android() message = "Let us count from 1 to 10" app.ttsSpeak(message) for i in range(1,11): app.ttsSpeak(str(i))
- Copy or push this Python script into the Android device by using the following command line:
C:\Users\Bintu\QPython\Scripts>adb push demoTextToSpeach.py /sdcard/qpython/bintuscripts
How it works...
An object called app
is created by invoking the Android()
method of the android
module. A message, Let us count from 1 to 10...