STT: Improve example, add fields for partials and errors
@@ -7,21 +7,30 @@ from kivy.uix.boxlayout import BoxLayout
from plyer import speech
Builder.load_string('''
+#:import speech plyer.speech
+
<SpeechInterface>:
orientation: 'vertical'
Label:
size_hint_y: None
height: sp(40)
- text: 'Is supported: %s' % root.speech.exist()
+ text: 'Is supported: %s' % speech.exist()
Label:
size_hint_y: None
height: sp(40)
text: 'Possible Matches'
- Label:
+ TextInput:
id: results
- size_hint_y: 0.7
- height: sp(40)
- text: ''
+ hint_text: 'results (auto stop)'
+ size_hint_y: 0.3
+ TextInput:
+ id: partial
+ hint_text: 'partial results (manual stop)'
+ size_hint_y: 0.3
+ TextInput:
+ id: errors
+ size_hint_y: None
+ height: sp(20)
Button:
id: start_button
text: 'Start Listening'
@@ -34,41 +43,38 @@ Builder.load_string('''
class SpeechInterface(BoxLayout):
'''Root Widget.'''
- speech = speech
- state = StringProperty()
-
def start_listening(self):
- if self.speech.state == 'listening':
+ if speech.listening:
self.stop_listening()
return
- start_button = self.ids['start_button']
+ start_button = self.ids.start_button
start_button.text = 'Stop'
- label_results = self.ids['results']
- label_results.text = ''
+ self.ids.results.text = ''
+ self.ids.partial.text = ''
- self.speech.start()
- self.state = self.speech.state
+ speech.start()
Clock.schedule_interval(self.check_state, 1/5)
def stop_listening(self):
- start_button = self.ids['start_button']
+ start_button = self.ids.start_button
start_button.text = 'Start Listening'
- self.speech.stop()
+ speech.stop()
self.update()
Clock.unschedule(self.check_state)
def check_state(self, dt):
- if self.state != self.speech.state:
+ # if the recognizer service stops, change UI
+ if not speech.listening:
self.stop_listening()
def update(self):
- label_results = self.ids['results']
- label_results.text = '\n'.join(set(self.speech.results))
+ self.ids.partial.text = '\n'.join(speech.partial_results)
+ self.ids.results.text = '\n'.join(speech.results)
class SpeechApp(App):
