com.sun.speech.freetts.Voice.speak()方法的使用及代码示例

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

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

Voice.speak介绍

暂无

代码示例

代码示例来源: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.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: 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: 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: 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.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: 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: 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: org.restcomm.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: 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: 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.resources/player

public TtsTrackImpl(String text, String voiceName,VoicesCache vc) {
  this.voiceCache = vc;
  isReady = false;
  // 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.speak(text);
  audioBuffer.flip();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
}

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

public TtsTrackImpl(String text, String voiceName,VoicesCache vc) {
  this.voiceCache = vc;
  isReady = false;
  // 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.speak(text);
  audioBuffer.flip();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
}

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

public TtsTrackImpl(String text, String voiceName,VoicesCache vc) {
  this.voiceCache = vc;
  isReady = false;
  // 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.speak(text);
  audioBuffer.flip();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
}

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

public TtsTrackImpl(String text, String voiceName,VoicesCache vc) {
  this.voiceCache = vc;
  isReady = false;
  // 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.speak(text);
  audioBuffer.flip();
  frameSize = (int) (period * format.getChannels() * format.getSampleSize() * format.getSampleRate() / 8000);
}

代码示例来源: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);

  }

相关文章