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

70
LINES

< > BotCompany Repo | #1004756 // Test MBrola Voice (mbrola_us1)

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

Uses 13052K of libraries. Click here for Pure Java version (506L/4K/15K).

!752

// speech libraries!
lib 1000722
lib 1000723
lib 1000724
lib 1000730
lib 1000731
lib 1000732
lib 1000726
lib 1000727

import javax.speech.*;
import javax.speech.synthesis.*;

p {
  mbrola_debug = true;
  mbrola("hello");
}

sbool mbrola_debug;
static Synthesizer mbrola_synth;
public static void mbrola(String text) ctex {
  if (mbrola_synth != null && empty(trim(text))) return;
  
  if (mbrola_synth == null) {
    String voiceName = "mbrola_us1";
  
    System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
    System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
    Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");

    SynthesizerModeDesc desc = new SynthesizerModeDesc(null, "general", Locale.US, null, null);

    if (mbrola_debug) print("Creating synth");
    Synthesizer synth = mbrola_synth = Central.createSynthesizer(desc);
    synth.allocate();
    desc = (SynthesizerModeDesc) synth.getEngineModeDesc();
    Voice[] voices = desc.getVoices();
    Voice voice = null;
    for (Voice entry : voices) {
        if(entry.getName().equals(voiceName)) {
            voice = entry;
            break;
        }
    }
    if (mbrola_debug) print("Voice: " + voice);
    synth.getSynthesizerProperties().setVoice(voice);
    synth.resume();
  }
  
  if (mbrola_debug) print("Speaking...");
  mbrola_synth.speakPlainText(text, null);
  if (mbrola_debug) print("Waiting");
  long state;
  int n = 0;
  while (((state = mbrola_synth.getEngineState()) & Synthesizer.QUEUE_EMPTY) != 0) {
    sleep(50);
    if (++n >= 10000/50) {
      print("Engine state: " + state + ", aborting");
      break;
    }
  }
  
  //mbrola_synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
  if (mbrola_debug) print("Done");
  
  // keep synth for next time
  //mbrola_synth.deallocate();
}

Author comment

Began life as a copy of #1000737

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004756
Snippet name: Test MBrola Voice (mbrola_us1)
Eternal ID of this version: #1004756/1
Text MD5: a9d29687b3a2ac6cf0bb387bab13ad57
Transpilation MD5: 025fb1d0c271ef16f7eaa88e42e9b581
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-09 02:15:55
Source code size: 1977 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 582
Referenced in: [show references]