Example usage for com.amazonaws.services.polly.model TextType Text

List of usage examples for com.amazonaws.services.polly.model TextType Text

Introduction

In this page you can find the example usage for com.amazonaws.services.polly.model TextType Text.

Prototype

TextType Text

To view the source code for com.amazonaws.services.polly.model TextType Text.

Click Source Link

Usage

From source file:org.openhab.voice.pollytts.internal.cloudapi.PollyTTSCloudImpl.java

License:Open Source License

/**
 * This method will return an input stream to an audio stream for the given
 * parameters./* www.  ja v  a 2s  .  co m*/
 * Get the given text in specified locale and audio format as input stream.
 *
 * @param text
 *            the text to translate into speech
 * @param label
 *            the voice Label to use
 * @param audioFormat
 *            the audio format to use
 * @return an InputStream to the audio data in specified format
 * @throws IOException
 *             will be raised if the audio data can not be retrieved from
 *             cloud service
 */
public InputStream getTextToSpeech(String text, String label, String audioFormat) {
    String voiceID = labelToID.get(label);
    String format = audioFormat.toLowerCase();
    if ("ogg".equals(format)) {
        format = "ogg_vorbis";
    }
    TextType textType = text.startsWith("<speak>") ? TextType.Ssml : TextType.Text;
    SynthesizeSpeechRequest request = new SynthesizeSpeechRequest().withTextType(textType).withText(text)
            .withVoiceId(voiceID).withOutputFormat(OutputFormat.fromValue(format));
    return client.synthesizeSpeech(request).getAudioStream();
}