How can I use speech-to-text in Plyer? It's not working.

533 views
Skip to first unread message

Amit Nikhade

unread,
Jun 7, 2020, 1:29:35 AM6/7/20
to Kivy users support
I constructed a simple app to recognize the speech and speak the results. But when i made a APK out of a python file through Buildozer, The tts worked out but the stt i.e the speech recognition didn't worked. The speech-to-text and the TTS library i used here is the Plyer

Here is the code:
import kivy

from kivy.app import App

from kivy.uix.switch import Switch

from kivy.uix.gridlayout import GridLayout

from kivy.uix.label import Label

from kivy.uix.image import Image


class SwitchContainer(GridLayout):

     def __init__(self, **kwargs):

          super(SwitchContainer, self).__init__(**kwargs)

          self.cols = 1


          self.add_widget(Label(text="speech recognizer", pos_hint= {'x': 5, 'y': 
5,"right":5,"top":50},font_size= '90sp'))


          self.settings_sample = Switch(active=False)

          self.add_widget(self.settings_sample)

          self.settings_sample.bind(active=switch_callback)       





def switch_callback(switchObject, switchValue):

     print('Value of sample settings is:', switchValue)
     if(switchValue):
          from plyer import tts
          tts.speak('hello, will you please tell me the port')
          try:
              from plyer import stt
              stt.start()
              sst.stop()
              from plyer import tts
              tts.speak(stt.results)
          except Exception as e:

              from plyer import tts
              tts.speak(' sir,its not working')


     else:
          print("off")

class SwitchExample(App):

     def build(self):

          return SwitchContainer()



# Run the kivy app

if __name__ == '__main__':

     SwitchExample().run()

The GUI of this app consist only a button when switched on the speech is recognized and the results are spoken out through TTS or if any error is found it tell that "sir it's not working. What's wrong am i doing over here.

Robert Flatt

unread,
Jun 7, 2020, 12:47:26 PM6/7/20
to Kivy users support
Any related messages in the logcat?

also in the Exception block add:

     print('>>>>>'+str(e))

This should give you a more specific error message in the logcat
(the '>>>>>>' is just to make the message easy to find)

Robert Flatt

unread,
Jun 7, 2020, 1:13:55 PM6/7/20
to Kivy users support
After figuring out why you get an exception, look at the example 


See you have to tell the recognizer when to stop, the code in the OP assumes the recognizer knows. It doesn't and stops immediately.

alessandro bonvicini

unread,
Mar 22, 2021, 5:52:30 PM3/22/21
to Kivy users support
Hi Robert, 
sorry to  bother you ....please may you give more details about the above request?
I am not fluent in english so , i am not sure to understand your concern ....do you mmean that the online sample is correct and shoud work ? or that it wrong and must be  changed in some way? which way?
Thank  you a lot
Alessandro

Robert

unread,
Mar 22, 2021, 9:33:39 PM3/22/21
to Kivy users support
I tried stt, it didn't work for me.
I did not try to figure out why.
Reply all
Reply to author
Forward
0 new messages