|
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) |
4 | 20 |
|
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. |
6 | 24 |
|
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). |
9 | 30 |
|
10 | | - Variable `language` indicates which language will be used to match words |
11 | | - from voice. |
| 31 | +Offline Speech Recognition on Android |
| 32 | +------------------------------------- |
12 | 33 |
|
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). |
14 | 38 |
|
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). |
18 | 42 |
|
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): |
22 | 44 |
|
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 |
28 | 52 |
|
29 | | - Offline Speech Recognition on Android |
30 | | - ------------------------------------- |
| 53 | +Simple Examples |
| 54 | +--------------- |
31 | 55 |
|
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:: |
36 | 57 |
|
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() |
40 | 60 |
|
41 | | - You can enable offline speech recognition this way (Android 8.1): |
| 61 | +To retrieve partial results while listening:: |
42 | 62 |
|
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. |
50 | 79 | ''' |
51 | 80 |
|
52 | 81 | _language = 'en-US' |
|
0 commit comments