No sound with "tts.speak" command

48 views
Skip to first unread message

Luke Nukem

unread,
May 27, 2020, 10:41:31 AM5/27/20
to Kivy users support
Hello,

I start learning on Kivy. In the attachment, you will found my basic application for android. For the moment, I use Kivy Launcher for start script on Android.

My code :

from kivy.app import App
from kivy.properties import ObjectProperty

from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout

from jnius import autoclass

class MyGrid(GridLayout):
   
def __init__(self, **kwargs):
       
super(MyGrid, self).__init__(**kwargs)

       
self.Locale = autoclass('java.util.Locale')
       
PythonActivity = autoclass('org.renpy.android.PythonActivity')
       
self.TextToSpeech = autoclass('android.speech.tts.TextToSpeech')
       
self.tts = self.TextToSpeech(PythonActivity.mActivity, None)

       
self.cols = 1

        self.inside = GridLayout()
       
self.inside.cols = 2

        self.inside.add_widget(Label(text="label: "))
       
self.name = TextInput(multiline=False)
       
self.inside.add_widget(self.name)

       
self.inside.add_widget(Label(text="label2: "))
       
self.name2 = TextInput(multiline=False)
       
self.inside.add_widget(self.name2)

       
self.add_widget(self.inside)

       
self.button3 = Button(text='Hello world', font_size=40)
       
self.button3.bind(on_press=self.pressed)
       
self.add_widget(self.button3)

   
def pressed(self, instance):
       
print("Pressed")
       
self.tts.setLanguage(self.Locale.US)
       
self.tts.speak('blender', self.TextToSpeech.QUEUE_FLUSH, None)

class TestApp(App):
   
def build(self):
       
return MyGrid()

TestApp().run()


There is no crash after launched or after having pressed the button, but "tts.speak" command generate no sound.

Is there a trick or a error ? Do you have this problem on your phone ?
kivy_test.zip

Robert Flatt

unread,
May 27, 2020, 3:26:50 PM5/27/20
to Kivy users support
Probably a Launcher issue, build an apk it will work.

Robert Flatt

unread,
May 27, 2020, 3:49:05 PM5/27/20
to Kivy users support
and renpy is depreciated, replace 'org.renpy.android.PythonActivity'  with 'org.kivy.android.PythonActivity'
Reply all
Reply to author
Forward
0 new messages