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

79
LINES

< > BotCompany Repo | #1017444 // Try MBrola "us1" voice with FreeTTS [dev.]

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

Download Jar. Uses 13052K of libraries. Click here for Pure Java version (1190L/8K).

!7

p {
  tts("Hello");
}

// 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.*;

static Lock tts_lock = fairLock();

sbool tts_debug, tts_disable, tts_verbose;
static Synthesizer tts_synth;

sS tts(String text) ctex {
  lock tts_lock;
  if (tts_verbose) print("Kevin: " + text);
  if (tts_disable || tts_synth != null && empty(trim(text))) return text;
  
  if (tts_synth == null) {
    System.setProperty("mbrola.base", f2s(userDir("dev/mbrola")));
    String voiceName = "mbrola_us1";
  
    System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
    System.setProperty("freetts.voices", "de.dfki.lt.freetts.en.us.MbrolaVoiceDirectory");
			
    Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");

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

    if (tts_debug) print("Creating synth");
    Synthesizer synth = tts_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 (tts_debug) print("Voice: " + voice);
    synth.getSynthesizerProperties().setVoice(voice);
    synth.resume();
  }
  
  if (tts_debug) print("Speaking...");
  tts_synth.speakPlainText(text, null);
  if (tts_debug) print("Waiting");
  // TODO: We wait later anyway
  long state;
  int n = 0;
  while (((state = tts_synth.getEngineState()) & Synthesizer.QUEUE_EMPTY) != 0) {
    sleep(50);
    if (++n >= 10000/50) {
      print("Engine state: " + state + ", aborting");
      break;
    }
  }
  
  //tts_synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
  if (tts_debug) print("Done");
  
  // keep synth for next time
  //tts_synth.deallocate();
  
  ret text;
}

Author comment

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: 374 / 839
Version history: 4 change(s)
Referenced in: [show references]