Libraryless. Click here for Pure Java version (145L/2K/5K).
1 | !747 |
2 | |
3 | import android.app.Activity; |
4 | import android.speech.tts.*; |
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 | int result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() { |
27 | @Override |
28 | public void onDone(String utteranceId) |
29 | { |
30 | print("onDone"); |
31 | done(); |
32 | } |
33 | |
34 | @Override |
35 | public void onError(String utteranceId) { |
36 | print("onError"); |
37 | } |
38 | |
39 | @Override |
40 | public void onStart(String utteranceId) { |
41 | print("onStart"); |
42 | } |
43 | }); |
44 | if (result != TextToSpeech.SUCCESS) |
45 | print("Could not set listener"); |
46 | |
47 | speak(); |
48 | /*thread { |
49 | sleepSeconds(20); // to be improved :) (OnUtteranceListener) |
50 | androidContext.runOnUiThread(runnable { |
51 | done(); |
52 | }); |
53 | }*/ |
54 | } catch (Throwable e) { e.printStackTrace(); } |
55 | } |
56 | }); |
57 | } |
58 | |
59 | static void speak() { |
60 | print(text); |
61 | new HashMap params; |
62 | params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID"); |
63 | tts.speak(text, TextToSpeech.QUEUE_FLUSH, params); |
64 | } |
65 | |
66 | static void done() { |
67 | print("Closing TTS"); |
68 | tts.stop(); |
69 | tts.shutdown(); |
70 | tts = null; |
71 | } |
72 | } |
Began life as a copy of #1001175
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, ufhdzwgrioxs, vouqrxazstgt
ID | Author/Program | Comment | Date |
---|---|---|---|
1114 | stefan | Now it is! :) | 2015-10-05 14:53:19 |
1113 | stefan | Listener is not called... | 2015-10-05 14:48:17 |
Snippet ID: | #1001253 |
Snippet name: | Android speech output (good version) |
Eternal ID of this version: | #1001253/1 |
Text MD5: | 0694e187190b593f5f7a52a941e8749d |
Transpilation MD5: | 9f42f3b1d9dc7bf708a1072df7fbdd85 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-07 21:07:26 |
Source code size: | 1939 bytes / 72 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 924 / 911 |
Referenced in: | [show references] |