【问题标题】:Changing SpeechRecognizer language on Azure Cognitive Services在 Azure 认知服务上更改 SpeechRecognizer 语言
【发布时间】:2019-10-19 18:23:43
【问题描述】:

我正在尝试使用 azure 的认知服务 Speech to Text,遵循 Python 中的 Github 示例:https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/258949599ec32c8a7b03fb38a53f2033010b6b26/samples/python/console/speech_sample.py#L203

我在文档中找不到如何更改说话者语言识别,默认为英语,我想用西班牙语转录音频。

我认为它与SpeechRecognizer 功能有关,但我不知道如何正确使用它。

这是我正在使用的 Github 的代码示例:

def speech_recognize_continuous_from_file():
    """performs continuous speech recognition with input from an audio file"""
    # <SpeechContinuousRecognitionWithFile>
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
    audio_config = speechsdk.audio.AudioConfig(filename=weatherfilename)

    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

    done = False

    def stop_cb(evt):
        """callback that stops continuous recognition upon receiving an event `evt`"""
        print('CLOSING on {}'.format(evt))
        speech_recognizer.stop_continuous_recognition()
        nonlocal done
        done = True

    # Connect callbacks to the events fired by the speech recognizer
    speech_recognizer.recognizing.connect(lambda evt: print('RECOGNIZING: {}'.format(evt)))
    speech_recognizer.recognized.connect(lambda evt: print('RECOGNIZED: {}'.format(evt)))
    speech_recognizer.session_started.connect(lambda evt: print('SESSION STARTED: {}'.format(evt)))
    speech_recognizer.session_stopped.connect(lambda evt: print('SESSION STOPPED {}'.format(evt)))
    speech_recognizer.canceled.connect(lambda evt: print('CANCELED {}'.format(evt)))
    # stop continuous recognition on either session stopped or canceled events
    speech_recognizer.session_stopped.connect(stop_cb)
    speech_recognizer.canceled.connect(stop_cb)

    # Start continuous speech recognition
    speech_recognizer.start_continuous_recognition()
    while not done:
        time.sleep(.5)
    # </SpeechContinuousRecognitionWithFile>

【问题讨论】:

    标签: python azure speech-to-text azure-cognitive-services


    【解决方案1】:

    SpeechConfig 构造函数采用 speech_recognition_language 参数。您必须以 BCP-47 格式指定语言。

    language = 'es-ES' # or perhaps es-MX?
    
    speech_config = speechsdk.SpeechConfig(subscription=speech_key,
                                           region=service_region,
                                           speech_recognition_language=language) 
    
    

    该课程的其他文档是here

    【讨论】:

    • 实例已经创建后是否可以在运行时设置speech_recognition_language
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2019-12-01
    • 2019-11-17
    • 2019-01-07
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    相关资源
    最近更新 更多