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.