Azure-Samples / cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
MIT License
2.82k stars 1.83k forks source link

How do I get notified when the speech has completed talking? #2594

Closed craigmccauley closed 5 days ago

craigmccauley commented 5 days ago

I'm trying to get this working in my blazor wasm application so I'm using the javascript library.

The problem is, the success message fires before the talking is completed.

function talkToUser(subscriptionKey, region, textToSpeak) {
    var sdk = window.SpeechSDK;
    var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, region);
    var synthesizer = new sdk.SpeechSynthesizer(speechConfig);
    synthesizer.speakTextAsync(
        textToSpeak,
        function (result) {
            if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
                // success
                window.dotNetObject.invokeMethodAsync('TalkToUserCompleted');
            } else {
                console.error("Speech synthesis canceled, " + result.errorDetails);
            }
            // success
            synthesizer.close();
            synthesizer = undefined;
        },
        function (err) {
            // error
            console.error(err);
            synthesizer.close();
            synthesizer = undefined;
        }
    );
}
pankopon commented 5 days ago

Hi, please see https://github.com/Azure-Samples/cognitive-services-speech-sdk/issues/1374