Text to speech is not working

Oliver Weidner 1 Reputation point
2022-10-28T18:30:13.56+00:00

Hello guys,
i was really hyped to try azure text-to-speech, but already the sample code isn't working.

This one from the offical page:
https://zcusa.951200.xyz/en-us/azure/cognitive-services/speech-service/get-started-text-to-speech?tabs=windows%2Cterminal&pivots=programming-language-python

> import os  
> import azure.cognitiveservices.speech as speechsdk  
>   
> # This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"  
> speech_config = speechsdk.SpeechConfig(subscription=key, region=region)  
> audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)  
>   
> # The language of the voice that speaks.  
> speech_config.speech_synthesis_voice_name='en-US-JennyNeural'  
>   
> speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)  
>   
> # Get text from the console and synthesize to the default speaker.  
> print("Enter some text that you want to speak >")  
> text = input()  
>   
> speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()  
>   
> if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:  
>     print("Speech synthesized for text [{}]".format(text))  
> elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:  
>     cancellation_details = speech_synthesis_result.cancellation_details  
>     print("Speech synthesis canceled: {}".format(cancellation_details.reason))  
>     if cancellation_details.reason == speechsdk.CancellationReason.Error:  
>         if cancellation_details.error_details:  
>             print("Error details: {}".format(cancellation_details.error_details))  
>             print("Did you set the speech resource key and region values?")  

I am using python 3.9 and downloaded Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017, 2019, and 2022. Also i tried it to set the environment variables, but its also not working.

This is my output:

> Enter some text that you want to speak >  
> hello there  
> Speech synthesis canceled: CancellationReason.Error  
> Error details: USP error: timeout waiting for the first audio chunk  
> Did you set the speech resource key and region values?  

A new api key and a new text-to-speech module i also generated, i dont know what the problem is...

This code dont shows me any error, just creates a empty test.wav file:

> def synthesize_to_speaker():  
>     # Find your key and resource region under the 'Keys and Endpoint' tab in your Speech resource in Azure Portal  
>     # Remember to delete the brackets <> when pasting your key and region!  
>     speech_config = speechsdk.SpeechConfig(subscription=key, region=region)  
>     # In this sample we are using the default speaker  
>     # Learn how to customize your speaker using SSML in Azure Cognitive Services Speech documentation  
>     # audio_config = AudioOutputConfig(use_default_speaker=True)  
>     audio_config = speechsdk.audio.AudioOutputConfig(filename="file.mp3")  
>     synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)  
>     synthesizer.speak_text_async("Text Text Text wie geht es dir du fettes bier ich hau mir ne nudel nei")  
>   
>   
> synthesize_to_speaker()  

hope someone can help me.

Azure AI Immersive Reader
Azure AI Immersive Reader
An Azure Applied AI Service that embeds text reading and comprehension capabilities into your applications.
30 questions
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,836 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,096 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Oliver Weidner 1 Reputation point
    2022-10-28T18:39:40.853+00:00

    I just tried the speech-to-text module with this code, this is working totally fine.

    def recognize_from_microphone():  
        # This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"  
        speech_config = speechsdk.SpeechConfig(subscription=key, region=region)  
        speech_config.speech_recognition_language="en-US"  
      
        audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)  
        speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)  
      
        print("Speak into your microphone.")  
        speech_recognition_result = speech_recognizer.recognize_once_async().get()  
      
        if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:  
            print("Recognized: {}".format(speech_recognition_result.text))  
        elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:  
            print("No speech could be recognized: {}".format(speech_recognition_result.no_match_details))  
        elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:  
            cancellation_details = speech_recognition_result.cancellation_details  
            print("Speech Recognition canceled: {}".format(cancellation_details.reason))  
            if cancellation_details.reason == speechsdk.CancellationReason.Error:  
                print("Error details: {}".format(cancellation_details.error_details))  
                print("Did you set the speech resource key and region values?")  
      
    recognize_from_microphone()  
    

  2. Grmacjon-MSFT 18,646 Reputation points
    2022-11-19T05:41:18.963+00:00

    This issue was resolved by in this Github issue https://github.com/MicrosoftDocs/azure-docs/issues/101028

    Positing the solution here for more awareness:

    "*There is a known issue introduced by some security updates October 12th that might cause connectivity issues using the TTS endpoints. There is an out of band update available for Windows 11 that fixes these issues. The update may be manually installed by following the instructions here:
    Windows 11 21H2: https://support.microsoft.com/topic/october-17-2022-kb5020387-os-build-22000-1100-out-of-band-5e723873-2769-4e3d-8882-5cb044455a92
    Windows 11 22H2: https://support.microsoft.com/topic/october-25-2022-kb5018496-os-build-22621-755-preview-64040bea-1e02-4b6d-bad1-b036200c2cb3*"

    Thanks,
    Grace

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.