Problem
I get the following error "Runtime error: Failed to initialize platform (azure-c-shared). Error: 2153" when trying to execute the following python line
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
Here's the whole snippet code. I am trying basically to do simply text-to-speech.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
```
Here's the whole snippet code. **I am trying basically to do simply text-to-speech.**
```python
subscription_key = 'xxxxxxxxxxxxxx'
region = 'eastus'
#https://eastus.api.cognitive.microsoft.com/sts/v1.0/issuetoken
def text_to_speech(text, language, output_file, speech_rate):
speech_config = speechsdk.SpeechConfig(subscription=subscription_key, region=region)
audio_config = speechsdk.audio.AudioOutputConfig(filename=output_file)
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
ssml = f"""
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="{language}">
<voice name="es-UY-MateoNeural">
<prosody rate="{speech_rate}">{text}</prosody>
</voice>
</speak>
"""
result = speech_synthesizer.speak_ssml_async(ssml).get()
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
print(f'Speech synthesized successfully and saved to {output_file}.')
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print(f'Speech synthesis canceled: {cancellation_details.reason}')
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print(f'Error details: {cancellation_details.error_details}')
Solutions tried
I tried using the code shared by the Azure portal, but I got the same problem:
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
# Note: the voice setting will not overwrite the voice element in input SSML.
speech_config.speech_synthesis_voice_name = "es-UY-MateoNeural"
text = "Hola, soy Mateo"
# use the default speaker as audio output.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
result = speech_synthesizer.speak_text_async(text).get()
# Check result
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
print("Speech synthesized for text [{}]".format(text))
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print("Speech synthesis canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print("Error details: {}".format(cancellation_details.error_details))
I tried other ways, but I always got a barrier like
HTTPError: 400 Client Error: Unexpected end of file has occurred. The following elements are not closed: prosody, voice, speak. Line 5, position 4976. for url: https://eastus.tts.speech.microsoft.com/cognitiveservices/v1
Context
Take into mind that the Version 1.32.1 was installed
import azure.cognitiveservices.speech as speechsdk
FYI, I can get the access token in several ways. Here's one:
!curl -v -X POST "https://eastus.api.cognitive.microsoft.com/sts/v1.0/issueToken" -H "Ocp-Apim-Subscription-Key: xxxxxxxxx" -H "Content-type: application/x-www-form-urlencoded" -H "Content-Length: 0"
SOS
How can I make this work? What am I doing wrong?
Thanks for your support!