Example usage for com.amazonaws.services.polly.model OutputFormat fromValue

List of usage examples for com.amazonaws.services.polly.model OutputFormat fromValue

Introduction

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

Prototype

public static OutputFormat fromValue(String value) 

Source Link

Document

Use this in place of valueOf.

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./*from   ww w  .ja va 2s  .  c om*/
 * 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();
}