text to speech in javascript

张寒轩 1 Reputation point
2022-04-21T13:22:16.39+00:00

Hello,
I'm new to here Azure. And I only want to use the text to speech function with Azure.

I've follow the tour how-to-speech-synthesis to write the code. And everything looks fine. But the broswer only sound up once. I've try to change the config and location of the service but failed still.
what's more, there are no any error in F12. So it confuse me a lot. And don't know what to do.

In Addition, I'm using global Azure in China for free account. the last service has been set to South Korea. Is it problem in net? I'm getting more confused with the code has worked well for once.
PPPPPPPPPPPPPPPPPPPPPPPPPlase help me. Thanks a lot.

here is the code.

function synthesizeSpeech() {  
            const speechConfig = SpeechSDK.SpeechConfig.fromSubscription("***", "koreacentral");  
            // Set either the `SpeechSynthesisVoiceName` or `SpeechSynthesisLanguage`.  
            speechConfig.speechSynthesisLanguage = "zh-CN";   
            // speechConfig.speechSynthesisVoiceName = "zh-CN-YunyeNeural";  
            const audioConfig=SpeechSDK.AudioConfig.fromDefaultSpeakerOutput();  
  
            const synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig);  
            synthesizer.speakTextAsync(  
                t,  
                result=>{  
                    if(result){  
                        synthesizer.close();  
                        return result.audioData;  
                    }  
                },  
                error=>{  
                    console.error(error);  
                    synthesizer.close();  
                }  
            )  
        }  

t=some Chinese characters;

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,391 questions
Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
353 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 41,866 Reputation points Microsoft Employee
    2022-04-22T07:39:42.68+00:00

    @张寒轩 I have tried the sample and it seems to work as expected.

    195482-image.png

    Could you try to use the complete sample referenced above directly?

    If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.