Kivy sample app with speech recognition

2,769 views
Skip to first unread message

Andreas Jung

unread,
Apr 25, 2015, 10:35:18 AM4/25/15
to kivy-...@googlegroups.com
Hi there,

my plan is to write an iOS application with Kivy providing speech recognition (using the Speech-to-Text API of Google) in order to speak to my home :-) ..means my home automation should listen to me.


seems to do the job.

I am current primarily looking for some sample (Kivy) code for recording a command through the microphone (iOS) and storing it as WAV.

Any hint for the Kivy clueless?

Thanks
Andreas

Leonardo Rodriguez

unread,
Aug 8, 2018, 6:30:40 PM8/8/18
to Kivy users support
Hi, here is mine.

main.py

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock, mainthread
import speech_recognition as sr
 
class Principal(Screen):
    def BtnEscuchar(self):
        self.ids.lblMensaje.text = "Say something!"
        Clock.schedule_once(lambda d: self.GetAudio(), 0)
 
    def GetAudio(self):
        r = sr.Recognizer()
        with sr.Microphone() as source:
            audio = r.listen(source)
        self.audio = audio
        try:
            self.ids.lblMensaje.text = "Google Speech Recognition thinks you said " + r.recognize_google(audio, language = 'es')
        except sr.UnknownValueError:
            print("Google Speech Recognition could not understand audio")
        except sr.RequestError as e:
            print("Could not request results from Google Speech Recognition service; {0}".format(e))
 
class testspkApp(App):
 
    def build(self):
        sm = ScreenManager()
        self.sm = sm
        sm.add_widget(Principal(name='Principal'))
        return sm
 
    def on_pause(self):
        return False
 
 
main = testspkApp()
main.run()



testspk.kv

<Principal>:
    id: HomeScreen
    BoxLayout:
        orientation: 'vertical'
        Button:
            text:'escuchar'
            on_release: root.BtnEscuchar()
        Label:
            id: lblMensaje
            text: 'Hola'

Reply all
Reply to author
Forward
0 new messages