本文整理汇总了Java中marytts.exceptions.SynthesisException类的典型用法代码示例。如果您正苦于以下问题:Java SynthesisException类的具体用法?Java SynthesisException怎么用?Java SynthesisException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SynthesisException类属于marytts.exceptions包,在下文中一共展示了SynthesisException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public void save(String speech, File file) {
new Thread("Saving speeches") {
@Override
public void run() {
if (!speech.trim().isEmpty()) {
ToastWindow toast = ToastWindow.showToast(MESSAGES.get("saving"), false);
try {
AudioInputStream audio = marytts.generateAudio(speech.toLowerCase());
AudioSystem.write(audio, AudioFileFormat.Type.WAVE, file);
toast.setVisible(false);
toast.dispose();
ToastWindow.showToast(MESSAGES.get("ready_saving"), true);
} catch (SynthesisException | IOException e) {
log.error("Unable to save speech", e);
toast.setVisible(false);
toast.dispose();
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null,
MESSAGES.get("offending_speech"), MESSAGES.get("error"), JOptionPane.ERROR_MESSAGE));
}
}
}
}.start();
}
示例2: speakBlocking
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public synchronized void speakBlocking(String text) //synchronized so that together with the call to join(), calls to this method will wait until previous calls are finished
{
if (text != null && !text.isEmpty())
{
try
{
AudioPlayer ap = new AudioPlayer();
ap.setAudio(maryTTS.generateAudio(text));
ap.start();
ap.join();
}
catch (SynthesisException se)
{
logger.log(Level.SEVERE, "MaryTTS failed to generate audio for text \"" + text + "\"", se);
}
catch (InterruptedException ie)
{
logger.log(Level.SEVERE, "MaryTTS AudioPlayer thread was interrupted.", ie);
}
}
}
示例3: say
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public static void say(String comment) {
if (isSilenced) {
System.out.println(comment);
return;
}
try {
if (!inited) {
init();
}
if (comment.isEmpty()) return;
final AudioInputStream audio = marytts.generateAudio(comment);
final AudioPlayer player = new AudioPlayer(audio);
player.start();
} catch (MaryConfigurationException | SynthesisException e) {
logger.error("Error sythesizing text to voice", e);
}
}
示例4: speakInternal
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public boolean speakInternal(String toSpeak, boolean blocking) throws SynthesisException, InterruptedException {
AudioInputStream audio;
log.info("speakInternal Blocking {} Text: {}", blocking, toSpeak);
if (toSpeak == null || toSpeak.length() == 0) {
log.info("speech null or empty");
return false;
}
audio = marytts.generateAudio(toSpeak);
// invoke("publishStartSpeaking", toSpeak);
MRLAudioPlayer player = new MRLAudioPlayer(audio, toSpeak);
// player.setAudio(audio);
player.start();
// To make this blocking you can join the player thread.
if (blocking) {
player.join();
}
// TODO: if this isn't blocking, we might just return immediately,
// rather
// than
// saying when the player has finished.
// invoke("publishEndSpeaking", toSpeak);
return true;
}
示例5: speakTextToAudioInputStream
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
private AudioInputStream speakTextToAudioInputStream(Document doc, MaryDataType inputType) throws TTSException
{
marytts.setInputType(inputType.toString());
marytts.setOutputType(MaryDataType.AUDIO.toString());
try
{
return marytts.generateAudio(doc);
}
catch (SynthesisException e)
{
throw new TTSException(e.getLocalizedMessage(),e);
}
}
示例6: getProsodyInfo
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public synchronized MaryProsodyInfo getProsodyInfo(String text) throws SynthesisException
{
MaryProsodyInfo p = new MaryProsodyInfo();
marytts.setInputType(MaryDataType.TEXT.toString());
marytts.setOutputType(MaryDataType.REALISED_ACOUSTPARAMS.toString());
p.parse(marytts.generateXML(text));
return p;
}
示例7: executeSpeaking
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
private void executeSpeaking(String speech) throws SynthesisException, InterruptedException {
AudioInputStream audio = marytts.generateAudio(speech.trim());
currentlySpeeking = new AudioPlayer(audio);
log.debug("Speeking: " + speech.trim());
notifySpeechListeners(speech.trim());
currentlySpeeking.start();
currentlySpeeking.join();
}
示例8: executeSpeaking
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
private void executeSpeaking(String speech) throws SynthesisException, InterruptedException {
AudioInputStream audio = marytts.generateAudio(speech);
currentlySpeeking = new AudioPlayer(audio);
log.debug("Speeking: " + speech);
currentlySpeeking.start();
currentlySpeeking.join();
}
示例9: speak
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
@Override
public AudioData speak(String toSpeak) throws SynthesisException, InterruptedException {
AudioData ret = new AudioData(toSpeak);
// TODO: handle the isSpeaking logic/state
speakInternal(toSpeak, false);
// FIXME - play cache track
return ret;
}
示例10: read
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
public static void read(String s) throws SynthesisException, InterruptedException {
AudioInputStream audio = marytts.generateAudio(s.length() > 0 ? s : "Ich kann das leider nicht lesen.");
player = new AudioPlayer(audio);
player.start();
player.join();
}
示例11: synthesize
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
@Override
public AudioStream synthesize(String text, org.eclipse.smarthome.core.voice.Voice voice,
AudioFormat requestedFormat) throws TTSException {
// Validate arguments
if ((null == text) || text.isEmpty()) {
throw new TTSException("The passed text is null or empty");
}
if (!this.voices.contains(voice)) {
throw new TTSException("The passed voice is unsupported");
}
boolean isAudioFormatSupported = false;
for (AudioFormat currentAudioFormat : this.audioFormats) {
if (currentAudioFormat.isCompatible(requestedFormat)) {
isAudioFormatSupported = true;
break;
}
}
if (!isAudioFormatSupported) {
throw new TTSException("The passed AudioFormat is unsupported");
}
/*
* NOTE: For each MaryTTS voice only a single AudioFormat is supported
* However, the TTSService interface allows the AudioFormat and
* the Voice to vary independently. Thus, an external user does
* not know about the requirement that a given voice is paired
* with a given AudioFormat. The test below enforces this.
*
* However, this leads to a problem. The user has no way to
* know which AudioFormat is apropos for a give Voice. Thus,
* throwing a TTSException for the wrong AudioFormat makes
* the user guess the right AudioFormat, a painful process.
* Alternatively, we can get the right AudioFormat for the
* Voice and ignore what the user requests, also wrong.
*
* TODO: Decide what to do
* Voice maryTTSVoice = Voice.getVoice(voice.getLabel());
* AudioFormat maryTTSVoiceAudioFormat = getAudioFormat(maryTTSVoice.dbAudioFormat());
* if (!maryTTSVoiceAudioFormat.isCompatible(requestedFormat)) {
* throw new TTSException("The passed AudioFormat is incompatable with the voice");
* }
*/
Voice maryTTSVoice = Voice.getVoice(voice.getLabel());
AudioFormat maryTTSVoiceAudioFormat = getAudioFormat(maryTTSVoice.dbAudioFormat());
// Synchronize on marytts
synchronized (marytts) {
// AudioStream to return
AudioStream audioStream = null;
// Set voice (Each voice supports onl a single AudioFormat)
marytts.setLocale(voice.getLocale());
marytts.setVoice(voice.getLabel());
try {
AudioInputStream audioInputStream = marytts.generateAudio(text);
audioStream = new MaryTTSAudioStream(audioInputStream, maryTTSVoiceAudioFormat);
} catch (SynthesisException | IOException e) {
throw new TTSException("Error generating an AudioStream", e);
}
return audioStream;
}
}
示例12: speakBlocking
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
@Override
public boolean speakBlocking(String toSpeak) throws SynthesisException, InterruptedException {
return speakInternal(toSpeak, true);
}
示例13: testMarySpeech
import marytts.exceptions.SynthesisException; //导入依赖的package包/类
@Test
public void testMarySpeech() throws SynthesisException, InterruptedException {
MarySpeech speech = (MarySpeech)Runtime.createAndStart("speech", "MarySpeech");
speech.speakBlocking("hello world");
}