Thank you for reaching out to Microsoft Q&A forum!
Regarding your issues 'Connection aborted' and 'TimeoutError', I suggest you to check your Network connection, Azure credentials and also check Azure storage account is running and accessible. I repro the below code for text to speech with python sdk without any errors:
import azure.cognitiveservices.speech as speechsdk
from azure.storage.blob import BlobServiceClient, ContentSettings
# Azure Speech SDK Configuration
speech_config = speechsdk.SpeechConfig(subscription='KEY', region='REGION')
speech_config.speech_synthesis_voice_name = 'en-US-JennyNeural'
# Azure Storage configuaration
connection_string = 'your_storage_account_connection_string'
container_name = 'your_container_name'
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_container_client = blob_service_client.get_container_client(container_name)
# Text to be synthesized
text = "I'm excited to try text to speech"
# Speech Synthesis
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
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))
# Upload audio to Azure Storage
audio_data = speech_synthesis_result.audio_data
blob_name = f"audio/{text.replace(' ', '_')}.wav"
blob_container_client.upload_blob(name=blob_name, data=audio_data, content_settings=ContentSettings(content_type='audio/wav'))
print(f"Audio content saved to Azure Storage: {blob_name}")
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?")
For more info see: Text-to-speech-overview.
I hope you understand! Thank you.