Skip to content

Commit 6768c2b

Browse files
authored
Merge pull request #484 from kivy/speech2stt
Change 'Speech' to 'STT'
2 parents a825572 + 07fe752 commit 6768c2b

File tree

6 files changed

+85
-61
lines changed

6 files changed

+85
-61
lines changed
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,42 @@
44
from kivy.properties import StringProperty
55
from kivy.uix.boxlayout import BoxLayout
66

7-
from plyer import speech
7+
from plyer import stt
88

99
Builder.load_string('''
10-
#:import speech plyer.speech
10+
#:import stt plyer.stt
1111
1212
<SpeechInterface>:
1313
orientation: 'vertical'
1414
Label:
1515
size_hint_y: None
1616
height: sp(40)
17-
text: 'Is supported: %s' % speech.exist()
17+
text: 'Is supported: %s' % stt.exist()
1818
Label:
1919
size_hint_y: None
2020
height: sp(40)
2121
text: 'Possible Matches'
2222
TextInput:
2323
id: results
2424
hint_text: 'results (auto stop)'
25-
size_hint_y: 0.3
2625
TextInput:
2726
id: partial
2827
hint_text: 'partial results (manual stop)'
29-
size_hint_y: 0.3
3028
TextInput:
3129
id: errors
32-
size_hint_y: None
33-
height: sp(20)
30+
hint_text: 'errors'
3431
Button:
3532
id: start_button
3633
text: 'Start Listening'
37-
on_release:
38-
root.start_listening()
39-
34+
on_release: root.start_listening()
4035
''')
4136

4237

4338
class SpeechInterface(BoxLayout):
4439
'''Root Widget.'''
4540

4641
def start_listening(self):
47-
if speech.listening:
42+
if stt.listening:
4843
self.stop_listening()
4944
return
5045

@@ -54,27 +49,27 @@ def start_listening(self):
5449
self.ids.results.text = ''
5550
self.ids.partial.text = ''
5651

57-
speech.start()
52+
stt.start()
5853

5954
Clock.schedule_interval(self.check_state, 1 / 5)
6055

6156
def stop_listening(self):
6257
start_button = self.ids.start_button
6358
start_button.text = 'Start Listening'
6459

65-
speech.stop()
60+
stt.stop()
6661
self.update()
6762

6863
Clock.unschedule(self.check_state)
6964

7065
def check_state(self, dt):
7166
# if the recognizer service stops, change UI
72-
if not speech.listening:
67+
if not stt.listening:
7368
self.stop_listening()
7469

7570
def update(self):
76-
self.ids.partial.text = '\n'.join(speech.partial_results)
77-
self.ids.results.text = '\n'.join(speech.results)
71+
self.ids.partial.text = '\n'.join(stt.partial_results)
72+
self.ids.results.text = '\n'.join(stt.results)
7873

7974

8075
class SpeechApp(App):

plyer/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
'brightness', 'call', 'camera', 'compass', 'cpu', 'email', 'filechooser',
1010
'flash', 'gps', 'gravity', 'gyroscope', 'humidity', 'irblaster',
1111
'keystore', 'light', 'notification', 'orientation', 'processors',
12-
'proximity', 'screenshot', 'sms', 'spatialorientation', 'speech',
13-
'storagepath', 'temperature', 'tts', 'uniqueid', 'vibrator', 'wifi'
12+
'proximity', 'screenshot', 'sms', 'spatialorientation', 'storagepath',
13+
'stt', 'temperature', 'tts', 'uniqueid', 'vibrator', 'wifi'
1414
)
1515

1616
__version__ = '1.3.3.dev0'
@@ -77,8 +77,8 @@
7777
#: Sms proxy to :class:`plyer.facades.Sms`
7878
sms = Proxy('sms', facades.Sms)
7979

80-
#: Speech proxy to :class:`plyer.facades.Speech`
81-
speech = Proxy('speech', facades.Speech)
80+
#: Speech proxy to :class:`plyer.facades.STT`
81+
stt = Proxy('stt', facades.STT)
8282

8383
#: TTS proxy to :class:`plyer.facades.TTS`
8484
tts = Proxy('tts', facades.TTS)

plyer/facades/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'Sms', 'TTS', 'UniqueID', 'Vibrator', 'Wifi', 'Flash', 'CPU',
1313
'Temperature', 'Humidity', 'SpatialOrientation', 'Brightness',
1414
'Processors', 'StoragePath', 'keystore', 'Bluetooth', 'Screenshot',
15-
'Speech')
15+
'STT')
1616

1717
from plyer.facades.accelerometer import Accelerometer
1818
from plyer.facades.audio import Audio
@@ -33,7 +33,7 @@
3333
from plyer.facades.orientation import Orientation
3434
from plyer.facades.notification import Notification
3535
from plyer.facades.sms import Sms
36-
from plyer.facades.speech import Speech
36+
from plyer.facades.stt import STT
3737
from plyer.facades.tts import TTS
3838
from plyer.facades.uniqueid import UniqueID
3939
from plyer.facades.vibrator import Vibrator
Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,81 @@
1-
class Speech(object):
2-
'''
3-
.. versionadded:: 1.3.3
1+
'''
2+
Speech to Text
3+
==============
4+
5+
.. versionadded:: 1.3.3
6+
7+
Speech Recognition facade.
8+
9+
In order to check that your device supports voice recognition use method
10+
`exist`.
11+
12+
Variable `language` indicates which language will be used to match words from
13+
voice.
14+
15+
Use `start` to start voice recognition immediately and `stop` to stop.
16+
17+
.. note::
18+
Needed permissions for Android: `RECORD_AUDIO` (and `INTERNET` if you want
19+
online voice recognition API to be used)
420
5-
Speech Recognition facade.
21+
.. note::
22+
On Android platform, after execute `start` method you can hear BEEP!
23+
Mute sound in order to disable it.
624
7-
In order to check that your device supports voice recognition use method
8-
`exist`.
25+
.. note::
26+
For Android implementation to work there has to be an application with
27+
`android.speech.RecognitionService` implementation present in the system.
28+
Mostly it's `com.google.android.googlequicksearchbox` or "Google"
29+
application (the search bar with the launcher widget).
930
10-
Variable `language` indicates which language will be used to match words
11-
from voice.
31+
Offline Speech Recognition on Android
32+
-------------------------------------
1233
13-
Use `start` to start voice recognition immediately and `stop` to stop.
34+
Requires any application that provides an
35+
`android.speech.RecognitionService` implementation to the other apps. One of
36+
such applications is on a lot of devices preinstalled Google (quick search
37+
box).
1438
15-
.. note::
16-
Needed permissions for Android: `RECORD_AUDIO` (and `INTERNET` if you
17-
want online voice recognition API to be used)
39+
The API prefers offline recognition, but should be able to switch to online
40+
alternative in case you don't have a language package installed (`INTERNET`
41+
permission necessary).
1842
19-
.. note::
20-
On Android platform, after execute `start` method you can hear BEEP!
21-
Mute sound in order to disable it.
43+
You can enable offline speech recognition this way (Android 8.1):
2244
23-
.. note::
24-
For Android implementation to work there has to be an application
25-
with `android.speech.RecognitionService` implementation present
26-
in the system. Mostly it's `com.google.android.googlequicksearchbox`
27-
or "Google" application (the search bar with the launcher widget).
45+
* open the `Settings` app
46+
* choose `Language & Input` / `Language & Keyboard` (Samsung might include it
47+
in the `General` category)
48+
* choose `On-Screen keyboard` or `Voice search`
49+
* choose `Google Keyboard`
50+
* choose `Offline Speech recognition`
51+
* download language package if you don't have one already
2852
29-
Offline Speech Recognition on Android
30-
-------------------------------------
53+
Simple Examples
54+
---------------
3155
32-
Requires any application that provides an
33-
`android.speech.RecognitionService` implementation to the other apps. One
34-
of such applications is on a lot of devices preinstalled Google (quick
35-
search box).
56+
To start listening::
3657
37-
The API prefers offline recognition, but should be able to switch to online
38-
alternative in case you don't have a language package installed (`INTERNET`
39-
permission necessary).
58+
>>> from plyer import stt
59+
>>> stt.start()
4060
41-
You can enable offline speech recognition this way (Android 8.1):
61+
To retrieve partial results while listening::
4262
43-
* open the `Settings` app
44-
* choose `Language & Input` / `Language & Keyboard` (Samsung might include
45-
it in the `General` category)
46-
* choose `On-Screen keyboard` or `Voice search`
47-
* choose `Google Keyboard`
48-
* choose `Offline Speech recognition`
49-
* download language package if you don't have one already
63+
>>> assert stt.listening
64+
>>> print(stt.partial_results)
65+
66+
To stop listening::
67+
68+
>>> stt.stop()
69+
70+
To retrieve results after the listening stopped::
71+
72+
>>> print(stt.results)
73+
'''
74+
75+
76+
class STT(object):
77+
'''
78+
Speech to text facade.
5079
'''
5180

5281
_language = 'en-US'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jnius import java_method
55
from jnius import PythonJavaClass
66

7-
from plyer.facades import Speech
7+
from plyer.facades import STT
88
from plyer.platforms.android import activity
99

1010
ArrayList = autoclass('java.util.ArrayList')
@@ -174,7 +174,7 @@ def onRmsChanged(self, rmsdB):
174174
self.volume_callback(rmsdB)
175175

176176

177-
class AndroidSpeech(Speech):
177+
class AndroidSpeech(STT):
178178
'''
179179
Android Speech Implementation.
180180

0 commit comments

Comments
 (0)