How do I change speech_synthesizer language to croatian "hr-HR" in Azure Text To Speech service using Python in VS Code?

Mario Malljak 1 Reputation point
2021-08-21T15:31:18.383+00:00

Hi!

I'm still a beginner using Azure services and kind of beginner in programming so I would appreciate some help and code sample so I can change speech_synthesizer language to croatian "hr-HR" in Azure Text To Speech service using Python in VS Code.

Can someone please help?

Here is my sample code that outputs text to voice in english language:

import azure.cognitiveservices.speech as speechsdk



# Creates an instance of a speech config with specified subscription key and service region.
# Replace with your own subscription key and service region (e.g., "westus").
speech_key, service_region = "my_key", "westeurope"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

# Creates a speech synthesizer using the default speaker as audio output.
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config)

# Receives a text from console input.
print("Type some text that you want to speak...")
text = input()

# Synthesizes the received text to speech.
# The synthesized speech is expected to be heard on the speaker with this line executed.
result = speech_synthesizer.speak_text_async(text).get()

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

Can someone help me to change voice output to croatian, because I need it to say croatian text correctly?

Thanks :)

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,393 questions
Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
635 questions
Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
354 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,373 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 46,566 Reputation points
    2021-08-23T18:05:15+00:00

    Hello,

    Thanks for reaching out to us here. For language configuration, you can do it in your SSML file. Speak is the root element, and is required for all SSML documents. The speak element contains important information, such as version, language, and the markup vocabulary definition.

    <speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="string"></speak>  
    

    125719-image.png

    Also, source language class will take care of source language: https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.languageconfig.sourcelanguageconfig?view=azure-python

    Hope this helps.

    Regards,
    Yutong

    0 comments No comments