com.sun.speech.freetts.Voice类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中com.sun.speech.freetts.Voice类的一些代码示例,展示了Voice类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Voice类的具体详情如下:
包路径:com.sun.speech.freetts.Voice
类名称:Voice

Voice介绍

暂无

代码示例

代码示例来源:origin: org.mobicents.media.resources/player

public void init(Map<String, Integer> voices) {
  for(String voiceName: voices.keySet())
  {
    int voiceCount = voices.get(voiceName);
    LinkedList<Voice> list = new LinkedList<Voice>();
    this.voicePool.put(voiceName, list);
    while(voiceCount>0)
    {
      
      Voice v = voiceManager.getVoice(voiceName);
      v.allocate();
      list.add(v);
      voiceCount--;
    }
  }
  
  
}

代码示例来源:origin: org.mobicents.media.resources/player

public void clear()
{
  Iterator<Entry<String, LinkedList<Voice>>> it =this.voicePool.entrySet().iterator();
  while(it.hasNext())
  {
    Entry<String, LinkedList<Voice>> entry = it.next();
    it.remove();
    for(Voice v: entry.getValue())
    {
      v.deallocate();
    }
    entry.getValue().clear();
  }
  
  
}

代码示例来源:origin: org.mobicents.resources/tts-ra

/**
 * Converts the text contained in the given stream to speech.
 * 
 * @param is
 *            the stream containing the text to speak
 */
public boolean streamToSpeech(InputStream is) {
  boolean ok;
  voice.startBatch();
  ok = voice.speak(is);
  voice.endBatch();
  return ok;
}

代码示例来源:origin: org.mobicents.media.resources/player

public void releaseVoice(Voice v)
{
  v.setAudioPlayer(null);
  this.voicePool.get(v.getName().toLowerCase()).add(v);
}

代码示例来源:origin: net.sf.phat/phat-audio

/**
 * Example of how to list all the known voices.
 */
public static void listAllVoices() {
  System.out.println();
  System.out.println("All voices available:");
  VoiceManager voiceManager = VoiceManager.getInstance();
  Voice[] voices = voiceManager.getVoices();
  for (int i = 0; i < voices.length; i++) {
    System.out.println("    " + voices[i].getName()
        + " (" + voices[i].getDomain() + " domain)");
  }
}

代码示例来源:origin: org.restcomm.media.core.resource/player

public TtsTrackImpl(URL url, String voiceName,VoicesCache vc) throws IOException {
  this.voiceCache = vc;
  isReady = false;
  URLConnection connection = url.openConnection();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
  // creating voice
  //VoiceManager voiceManager = VoiceManager.getInstance();
 //voice = voiceManager.getVoice(voiceName);
  voice = voiceCache.allocateVoice(voiceName);
  //this.voice.allocate();
  // creating speech buffer for writting
  TTSAudioBuffer audioBuffer = new TTSAudioBuffer();
  // assign buffer to speech engine and start generation
  // produced media data will be stored in the audio buffer
  this.voice.setAudioPlayer(audioBuffer);
  this.voice.speak(connection.getInputStream());
  audioBuffer.flip();
}

代码示例来源:origin: es.ucm.fdi.grasia.faerie.demos/talkingAgents.out

@Override
  public void run(ContextEvent event) {
    Attribute attribute = event.getSourceAttributeInstance();
    Entity entity = attribute.getEntity();
    Logger.getLogger(this.getClass()).info("<BEHAVIOR> " + oracle + " saying goodbye to " + entity.getName());

    VoiceManager voiceManager = VoiceManager.getInstance();
    Voice helloVoice = voiceManager.getVoice(voice);

    helloVoice.allocate();
    helloVoice.speak("Go!");
    helloVoice.deallocate();
  }
}

代码示例来源:origin: net.sf.phat/phat-audio

private boolean speak(String text, String path, String file) {
  try {
    System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
    SingleFileAudioPlayer objPlayer = null;
    String voiceName = "kevin16";
    VoiceManager voiceManager = VoiceManager.getInstance();                 
    Voice objVoice = voiceManager.getVoice(voiceName);
    if (objVoice == null) {
      System.err.println("Cannot find a voice named " + voiceName + ".  Please specify a different voice.");
      return false;
    }
    objVoice.allocate();
    objPlayer = new SingleFileAudioPlayer(path + file, Type.WAVE); 
    objPlayer.setAudioFormat(audioFormat);
    objVoice.setAudioPlayer(objPlayer);
    objVoice.speak(text);
    objVoice.deallocate();
    objPlayer.close();
    return true;
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: org.restcomm.media.core.resource/media-core-resource-player

private void setupMbrola() {
  MbrolaVoiceFactory mbrolaVoiceFactory = new MbrolaVoiceFactory();
  Voice[] voices = mbrolaVoiceFactory.getVoices();
  for (Voice v : voices) {
    voiceFactories.put(v.getName(), mbrolaVoiceFactory);
  }
}

代码示例来源:origin: ua.mobius.media.resources/player

public TtsTrackImpl(URL url, String voiceName,VoicesCache vc) throws IOException {
  this.voiceCache = vc;
  isReady = false;
  URLConnection connection = url.openConnection();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
  // creating voice
  //VoiceManager voiceManager = VoiceManager.getInstance();
 //voice = voiceManager.getVoice(voiceName);
  voice = voiceCache.allocateVoice(voiceName);
  //this.voice.allocate();
  // creating speech buffer for writting
  TTSAudioBuffer audioBuffer = new TTSAudioBuffer();
  // assign buffer to speech engine and start generation
  // produced media data will be stored in the audio buffer
  this.voice.setAudioPlayer(audioBuffer);
  this.voice.setVolume(1.0f);
    this.voice.speak(connection.getInputStream());
  audioBuffer.flip();
}

代码示例来源:origin: org.mobicents.resources/tts-ra

private void init() {
  VoiceManager voiceManager = VoiceManager.getInstance();
  this.voice = voiceManager.getVoice(this.getVoiceName());
  this.voice.allocate();
      audioPlayer = voice.getDefaultAudioPlayer();
    } catch (InstantiationException e) {
      log
  this.voice.setAudioPlayer(audioPlayer);

代码示例来源:origin: org.mobicents.resources/tts-ra

/**
 * Converts the given text to speech
 * 
 * @param text
 *            the text to speak
 * 
 * @return true if the utterance was played properly
 */
public boolean textToSpeech(String text) {
  return voice.speak(text);
}

代码示例来源:origin: org.restcomm.media.core.resource/media-core-resource-player

public TtsTrackImpl(URL url, String voiceName,VoicesCache vc) throws IOException {
  this.voiceCache = vc;
  isReady = false;
  URLConnection connection = url.openConnection();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
  // creating voice
  //VoiceManager voiceManager = VoiceManager.getInstance();
 //voice = voiceManager.getVoice(voiceName);
  voice = voiceCache.allocateVoice(voiceName);
  //this.voice.allocate();
  // creating speech buffer for writting
  TTSAudioBuffer audioBuffer = new TTSAudioBuffer();
  // assign buffer to speech engine and start generation
  // produced media data will be stored in the audio buffer
  this.voice.setAudioPlayer(audioBuffer);
  this.voice.speak(connection.getInputStream());
  audioBuffer.flip();
}

代码示例来源:origin: es.ucm.fdi.grasia.faerie.demos/talkingAgents.out

@Override
  public void run(ContextEvent event) {
    Attribute attribute = event.getSourceAttributeInstance();
    Entity entity = attribute.getEntity();
    Logger.getLogger(this.getClass()).info("<BEHAVIOR> " + oracle + " giving welcome to " + entity.getName());

    VoiceManager voiceManager = VoiceManager.getInstance();
    Voice helloVoice = voiceManager.getVoice(voice);

    helloVoice.allocate();
    helloVoice.speak("You, " + entity.getName());
    helloVoice.deallocate();
  }
}

代码示例来源:origin: org.restcomm.media.resources/player

public void releaseVoice(Voice v)
{
  v.setAudioPlayer(null);
  this.voicePool.get(v.getName().toLowerCase()).add(v);
}

代码示例来源:origin: ua.mobius.media.resources/player

private void setupAlan() {
  AlanVoiceFactory alanVoiceFactory = new AlanVoiceFactory();
  Voice[] voices = alanVoiceFactory.getVoices();
  for (Voice v : voices) {
    voiceFactories.put(v.getName(), alanVoiceFactory);
  }
}

代码示例来源:origin: ua.mobius.media.resources/player

public TtsTrackImpl(String text, String voiceName,VoicesCache vc) {
    this.voiceCache = vc;
    isReady = false;
    frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
    // creating voice
    //VoiceManager voiceManager = VoiceManager.getInstance();
    //voice = voiceManager.getVoice(voiceName);
    voice = voiceCache.allocateVoice(voiceName);

    //voice.allocate();
    // creating speech buffer for writting
    TTSAudioBuffer audioBuffer = new TTSAudioBuffer();

    // assign buffer to speech engine and start generation
    // produced media data will be stored in the audio buffer
    voice.setAudioPlayer(audioBuffer);
    voice.setVolume(1.0f);
    voice.speak(text);

    audioBuffer.flip();
//        frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);

  }

代码示例来源:origin: org.mobicents.media.resources/player

public TtsTrackImpl(URL url, String voiceName,VoicesCache vc) throws IOException {
  this.voiceCache = vc;
  isReady = false;
  URLConnection connection = url.openConnection();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
  // creating voice
  //VoiceManager voiceManager = VoiceManager.getInstance();
 //voice = voiceManager.getVoice(voiceName);
  voice = voiceCache.allocateVoice(voiceName);
  //this.voice.allocate();
  // creating speech buffer for writting
  TTSAudioBuffer audioBuffer = new TTSAudioBuffer();
  // assign buffer to speech engine and start generation
  // produced media data will be stored in the audio buffer
  this.voice.setAudioPlayer(audioBuffer);
  this.voice.speak(connection.getInputStream());
  audioBuffer.flip();
}

代码示例来源:origin: es.ucm.fdi.grasia.faerie.demos/talkingAgents.out

@Override
  public void run(ContextEvent event) {
    Attribute attribute = event.getSourceAttributeInstance();
    Entity entity = attribute.getEntity();
    Logger.getLogger(this.getClass()).info("<BEHAVIOR> " + oracle + " talking to " + entity.getName());

    VoiceManager voiceManager = VoiceManager.getInstance();
    Voice helloVoice = voiceManager.getVoice(voice);

    helloVoice.allocate();

    String text;
    if ("First Oracle".equals(oracle))
      text = "How you dare to disturb me?";
    else if ("Second Oracle".equals(oracle))
      text = "You are not interesting for me";
    else if ("Third Oracle".equals(oracle))
      text = "You are insignificant";
    else
      text = "Stupid";

    helloVoice.speak("I'm the " + oracle + ". " + text + ", mortal.");
    helloVoice.deallocate();
  }
}

代码示例来源:origin: org.restcomm.media.core.resource/player

public void releaseVoice(Voice v)
{
  v.setAudioPlayer(null);
  this.voicePool.get(v.getName().toLowerCase()).add(v);
}

相关文章