ejbeaty / ChattyKathy

A wrapper for working with Amazons Aws.Polly library
75 stars 23 forks source link

Feature request: SSML support #4

Open sgasser opened 7 years ago

sgasser commented 7 years ago

SSML not working: http://docs.aws.amazon.com/polly/latest/dg/ssml-to-speech-console.html

kathy.Speak('<speak>He was caught up in the game.<break time="1s"/> In the middle of the 10/3/2014 <sub alias="World Wide Web Consortium">W3C</sub> meeting he shouted, "Score!" quite loudly. When his boss stared at him, he repeated <amazon:effect name="whispered">"Score"</amazon:effect> in a whisper.</speak>');

On line 111 the TextType has to be set: `` Text: message,

TextType: 'ssml',

VoiceId: settings.pollyVoiceId ``

I will add a PR with a regex to check if message is ssml and set TextType to ssml.

ejbeaty commented 7 years ago

That would be an excellent addition, thank you!

cdcv commented 5 years ago

This would be great. Were you able to do it? Alternatively, is there a way to adjust a setting to use ssml/etc. Thanks!

cdcv commented 5 years ago

I was able to add SSML support by adding the following single line of code. Currently this is non-selectable:

// Make request to Amazon polly
function requestSpeechFromAWS(message) {
    return new Promise(function (successCallback, errorCallback) {
        var polly = new AWS.Polly();
        var params = {
            OutputFormat: 'mp3',
            Text: message,
            VoiceId: settings.pollyVoiceId,
            TextType: 'ssml' // ADD THIS LINE
        }
        polly.synthesizeSpeech(params, function (error, data) {
            if (error) {
                errorCallback(error)
            } else {
                saveSpeechToLocalCache(message, data.AudioStream);
                successCallback(data.AudioStream);
            }
        });
    });
}
Tom-Carpenter commented 5 years ago

To make this selectable could you just parameterize the TextType into the function like this, requestSpeechFromAWS(message, textType="text") //to default to text unless otherwise stated?

dominik-meissner commented 4 years ago

I have added a PR to enable SSML support by default. It does not break existing code but now you can easily add the common SSML tags supported by Polly.