Search code examples
pythonazureazure-functionsspeech-to-textazure-speech

Azure speech to text doesn't work in Spanish


I have this azure function written in python

import logging
import azure.functions as func
import azure.cognitiveservices.speech as speechsdk
import azure_config

def main(req: func.HttpRequest) -> func.HttpResponse:

    language = 'es-ES' 

    speech_config = speechsdk.SpeechConfig(subscription=azure_config.speech_subscription_key, region=azure_config.speech_region, speech_recognition_language=language)

    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

    logging.info("Speak into your microphone.")
    speech_recognition_result = speech_recognizer.recognize_once_async().get()

    if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
        logging.info("Recognized: {}".format(speech_recognition_result.text))

    elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
        logging.info("No speech could be recognized: {}".format(speech_recognition_result.no_match_details))

    elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = speech_recognition_result.cancellation_details
        logging.info("Speech Recognition canceled: {}".format(cancellation_details.reason))
        
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            logging.info("Error details: {}".format(cancellation_details.error_details))
            logging.info("Did you set the speech resource key and region values?")
    
    return func.HttpResponse("Speech recognition completed.", status_code=200)

I have set the language to es-ES, however when I am testing it, it still got my voice input as English. For example, when I said "Soy Anna", it gave me a result of "Sorry, Anna".

I am not sure if my setting is wrong or free tier (I am using pay as you go) doesn't support Spanish...thank you.

I did the changes of the setting several times with different approaches. I hope to get Spanish output from the speech service.


Solution

  • I made some changes to your code and got the text output with the input speech in Spanish.

    Code:

    import logging
    import azure.functions as func
    import azure.cognitiveservices.speech as speechsdk
    
    def main(req: func.HttpRequest) -> func.HttpResponse:
        language = 'es-ES'
        subscription_key = '<speech-key>'
        region = '<speech-region>'
    
        speech_config = speechsdk.SpeechConfig(subscription=subscription_key, region=region, speech_recognition_language=language)
        audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
        speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
    
        logging.info("Speak into your microphone.")
        speech_recognition_result = speech_recognizer.recognize_once_async().get()
    
        if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
            logging.info("Recognized: {}".format(speech_recognition_result.text))
    
        elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
            logging.info("No speech could be recognized: {}".format(speech_recognition_result.no_match_details))
    
        elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
            cancellation_details = speech_recognition_result.cancellation_details
            logging.info("Speech Recognition canceled: {}".format(cancellation_details.reason))
    
            if cancellation_details.reason == speechsdk.CancellationReason.Error:
                logging.info("Error details: {}".format(cancellation_details.error_details))
                logging.info("Did you set the speech resource key and region values?")
    
        return func.HttpResponse("Speech recognition completed.", status_code=200)
    

    Output:

    It runs successfully as below,

    enter image description here

    With the above URL, I got the speak into your microphone as below,

    enter image description here

    Then, I spoke a Hola kamali, Como estas? in Spanish and got the text output as below,

    enter image description here

    I got below output with the URL,

    enter image description here