Libraryless. Click here for Pure Java version (138L/2K/5K).
1 | !747 |
2 | |
3 | import android.app.Activity; |
4 | import android.speech.tts.TextToSpeech; |
5 | |
6 | m {
|
7 | static Activity androidContext; |
8 | static TextToSpeech tts; |
9 | static S text = "Hello Android"; |
10 | |
11 | p {
|
12 | if (args.length != 0 && args[0].length() != 0) text = join(" ", args);
|
13 | |
14 | tts = new TextToSpeech(androidContext, new TextToSpeech.OnInitListener() {
|
15 | public void onInit(int status) {
|
16 | try {
|
17 | if (status != TextToSpeech.SUCCESS) |
18 | fail("Speech engine initialization failed");
|
19 | |
20 | /* int result = tts.setLanguage(Locale.US); |
21 | if (result == TextToSpeech.LANG_MISSING_DATA |
22 | || result == TextToSpeech.LANG_NOT_SUPPORTED) |
23 | fail("English is not supported");
|
24 | */ |
25 | |
26 | speak(); |
27 | thread {
|
28 | sleepSeconds(20); // to be improved :) (OnUtteranceListener) |
29 | androidContext.runOnUiThread(runnable {
|
30 | done(); |
31 | }); |
32 | } |
33 | } catch (Throwable e) { e.printStackTrace(); }
|
34 | } |
35 | }); |
36 | } |
37 | |
38 | static void speak() {
|
39 | print(text); |
40 | tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); |
41 | } |
42 | |
43 | static void done() {
|
44 | print("Closing TTS");
|
45 | tts.stop(); |
46 | tts.shutdown(); |
47 | tts = null; |
48 | } |
49 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, ufhdzwgrioxs, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1001175 |
| Snippet name: | Android speech output (internal engine) |
| Eternal ID of this version: | #1001175/1 |
| Text MD5: | fe6a8280a8e0a4448468d37100158468 |
| Transpilation MD5: | 3c44d6aec9efeade5268c7ea9a202d07 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-10-06 13:19:34 |
| Source code size: | 1264 bytes / 49 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 893 / 964 |
| Referenced in: | [show references] |