Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1000721 // Say "Hello JavaX" using software speech synthesizer

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 13052K of libraries. Click here for Pure Java version (62L/1K/3K).

1  
!636 (modern)
2  
3  
// speech libraries!
4  
!1000722 1000723 1000724
5  
!1000730 1000731 1000732
6  
!1000726 1000727
7  
8  
import javax.speech.*;
9  
import javax.speech.synthesis.*;
10  
11  
main {
12  
  psvm {
13  
    speech("Hello Java X!");
14  
  }
15  
  
16  
  public static void speech(String text) {
17  
    if (text == null || text.trim().isEmpty()) return;
18  
19  
    String voiceName = "kevin16";
20  
21  
    try {
22  
      System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
23  
      System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
24  
      Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
25  
26  
      SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null);
27  
28  
      Synthesizer synth = Central.createSynthesizer(desc);
29  
      synth.allocate();
30  
      desc = (SynthesizerModeDesc) synth.getEngineModeDesc();
31  
      Voice[] voices = desc.getVoices();
32  
      Voice voice = null;
33  
      for (Voice entry : voices) {
34  
          if(entry.getName().equals(voiceName)) {
35  
              voice = entry;
36  
              break;
37  
          }
38  
      }
39  
      synth.getSynthesizerProperties().setVoice(voice);
40  
      synth.resume();
41  
      synth.speakPlainText(text, null);
42  
      synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
43  
      synth.deallocate();
44  
45  
    } catch(Exception ex) {
46  
      String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
47  
      System.out.println("" + ex);
48  
      System.out.println(message);
49  
      ex.printStackTrace();
50  
  }
51  
  }
52  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000721
Snippet name: Say "Hello JavaX" using software speech synthesizer
Eternal ID of this version: #1000721/1
Text MD5: 355a898b9935860edcb56c44052c4b5e
Transpilation MD5: d0ea814cb70d0321fdbacd58ac1a4714
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-24 01:59:58
Source code size: 1612 bytes / 52 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 686 / 676
Referenced in: [show references]