1
votes

I'm trying to get web chat with my bot (V4 bot and web chat) to work with the speech cognitive service, using a specific voice. I've got it almost working as per this sample and others in the same folder (https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/06.c.cognitive-services-speech-services-js/index.html)

The only part of the equation I'm missing is whether I can specify the voice. I can't find how to specify voice in the samples and the web chat source code.

This page linked to from the speech cog service docco (https://docs.microsoft.com/en-gb/azure/cognitive-services/speech-service/speech-synthesis-markup) mentions specifying voice inside the SSML but I don't want to have to somehow crack open and modify the SSML being generated by the bot if I can avoid it.

Does anyone have any idea if this is possible, and if so how?

Thanks

Lee

1

1 Answers

3
votes

OK I came to an answer on this myself after looking at the pony fill code. Partial snippet below. Update the list of voice to locale mappings to match the voice you want to use for the specified locale.


    const speechServicesPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken, region });

    return options => {

        const ponyfill = speechServicesPonyfillFactory(options);

        var speechSynthesisUtterance = ponyfill.SpeechSynthesisUtterance;
        var speechSynthesis = ponyfill.speechSynthesis;

        speechSynthesis.getVoices = function () {
            return [
                { lang: 'en-US', gender: 'Male', voiceURI: 'Microsoft Server Speech Text to Speech Voice (en-US, BenjaminRUS)' }
            ];
        }

        return {
            SpeechGrammarList: ponyfill.SpeechGrammarList,
            SpeechRecognition: ponyfill.SpeechRecognition,
            speechSynthesis: speechSynthesis,
            SpeechSynthesisUtterance: speechSynthesisUtterance
        }
    };
};

...

var ponyfillFactory = await createSpeechPonyfillFactory({ authorizationToken, region });

...

// Do the usual stuff from the sample to get auth token and region...

window.WebChat.renderWebChat({
                directLine: directLine,
                webSpeechPonyfillFactory: ponyfillFactory,
                store
            }, document.getElementById('webchat'));