在 Azure 认知服务上更改 SpeechRecognizer 语言
Changing SpeechRecognizer language on Azure Cognitive Services
我正在尝试按照 Python
中的 Github 示例使用 azure 的认知服务 Speech to Text: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>
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)
class 的其他文档是 here。
我正在尝试按照 Python
中的 Github 示例使用 azure 的认知服务 Speech to Text: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>
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)
class 的其他文档是 here。