Download Jar. Uses 13052K of libraries. Click here for Pure Java version (1190L/8K).
1 | !7 |
2 | |
3 | p { |
4 | tts("Hello"); |
5 | } |
6 | |
7 | // speech libraries! |
8 | lib 1000722 |
9 | lib 1000723 |
10 | lib 1000724 |
11 | lib 1000730 |
12 | lib 1000731 |
13 | lib 1000732 |
14 | lib 1000726 |
15 | lib 1000727 |
16 | |
17 | import javax.speech.*; |
18 | import javax.speech.synthesis.*; |
19 | |
20 | static Lock tts_lock = fairLock(); |
21 | |
22 | sbool tts_debug, tts_disable, tts_verbose; |
23 | static Synthesizer tts_synth; |
24 | |
25 | sS tts(String text) ctex { |
26 | lock tts_lock; |
27 | if (tts_verbose) print("Kevin: " + text); |
28 | if (tts_disable || tts_synth != null && empty(trim(text))) return text; |
29 | |
30 | if (tts_synth == null) { |
31 | System.setProperty("mbrola.base", f2s(userDir("dev/mbrola"))); |
32 | String voiceName = "mbrola_us1"; |
33 | |
34 | System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral"); |
35 | System.setProperty("freetts.voices", "de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory"); |
36 | |
37 | Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral"); |
38 | |
39 | SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null); |
40 | |
41 | if (tts_debug) print("Creating synth"); |
42 | Synthesizer synth = tts_synth = Central.createSynthesizer(desc); |
43 | synth.allocate(); |
44 | desc = (SynthesizerModeDesc) synth.getEngineModeDesc(); |
45 | Voice[] voices = desc.getVoices(); |
46 | Voice voice = null; |
47 | for (Voice entry : voices) { |
48 | if(entry.getName().equals(voiceName)) { |
49 | voice = entry; |
50 | break; |
51 | } |
52 | } |
53 | if (tts_debug) print("Voice: " + voice); |
54 | synth.getSynthesizerProperties().setVoice(voice); |
55 | synth.resume(); |
56 | } |
57 | |
58 | if (tts_debug) print("Speaking..."); |
59 | tts_synth.speakPlainText(text, null); |
60 | if (tts_debug) print("Waiting"); |
61 | // TODO: We wait later anyway |
62 | long state; |
63 | int n = 0; |
64 | while (((state = tts_synth.getEngineState()) & Synthesizer.QUEUE_EMPTY) != 0) { |
65 | sleep(50); |
66 | if (++n >= 10000/50) { |
67 | print("Engine state: " + state + ", aborting"); |
68 | break; |
69 | } |
70 | } |
71 | |
72 | //tts_synth.waitEngineState(Synthesizer.QUEUE_EMPTY); |
73 | if (tts_debug) print("Done"); |
74 | |
75 | // keep synth for next time |
76 | //tts_synth.deallocate(); |
77 | |
78 | ret text; |
79 | } |
Began life as a copy of #1000737
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017444 |
Snippet name: | Try MBrola "us1" voice with FreeTTS [dev.] |
Eternal ID of this version: | #1017444/5 |
Text MD5: | ee5949bdaa3712989a486eaec4f19947 |
Transpilation MD5: | 2515dc8d8bb75128c78bd36b45069348 |
Author: | stefan |
Category: | javax / speech |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-07-22 10:24:59 |
Source code size: | 2145 bytes / 79 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 532 / 1161 |
Version history: | 4 change(s) |
Referenced in: | [show references] |