Search code examples
azuretext-to-speechazure-cognitive-services

Microsoft cognitive-services text to speech problem


I'm trying to use microsoft TTS with python script, when i use english word the output file working perfectly when i use Hebrew letters and set the language to "he-IL" the output file is empty.

This is the code from microsoft examples:

import azure.cognitiveservices.speech as speechsdk

# Replace with your own subscription key and region identifier from here: https://aka.ms/speech/sdkregion
speech_key, service_region = "", "westeurope"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region, speech_recognition_language="he-IL")
# Creates an audio configuration that points to an audio file.
# Replace with your own audio filename.
audio_filename = "helloworld.wav"
audio_output = speechsdk.audio.AudioOutputConfig(filename=audio_filename)

# Creates a synthesizer with the given settings
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_output)

# Synthesizes the text to speech.
# Replace with your own text.
text = "בדיקה שומעים אותי"
result = speech_synthesizer.speak_text_async(text).get()

# Checks result.
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print("Speech synthesized to [{}] for text [{}]".format(audio_filename, 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:
        if cancellation_details.error_details:
            print("Error details: {}".format(cancellation_details.error_details))
    print("Did you update the subscription info?") 

Solution

  • The speech_recognition_language parameter is for recognition. You can follow this sample to set synthesis language.

    Key lines are

        speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
        # Sets the synthesis language.
        speech_config.speech_synthesis_language = "he-IL"
        # Creates a speech synthesizer for the specified language,
        # using the default speaker as audio output.
        speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)
        result = speech_synthesizer.speak_text_async(text).get()