Search in sources :

Example 1 with TextType

use of com.amazonaws.services.polly.model.TextType in project openhab-addons by openhab.

the class PollyTTSCloudImpl method getTextToSpeech.

/**
 * This method will return an input stream to an audio stream for the given
 * parameters.
 * 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();
}
Also used : SynthesizeSpeechRequest(com.amazonaws.services.polly.model.SynthesizeSpeechRequest) TextType(com.amazonaws.services.polly.model.TextType)

Aggregations

SynthesizeSpeechRequest (com.amazonaws.services.polly.model.SynthesizeSpeechRequest)1 TextType (com.amazonaws.services.polly.model.TextType)1