-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
The recognition and translation work correctly, but the translated output does not appear to be using the custom translation model. It seems to fall back to the default translation model instead.
Here's the relevant part of my code:
import azure.cognitiveservices.speech as speechsdk
speech_key = ""
speech_region = "southeastasia"
custom_model_category_id = ""
target_language = "en"
source_language = "zh-CN"
创建翻译配置
translation_config = speechsdk.translation.SpeechTranslationConfig(
subscription=speech_key, region=speech_region, target_languages=[target_language]
)
设置源语言
translation_config.speech_recognition_language = source_language
正确的方式设置自定义端点和模型
endpoint_url = f"wss://{speech_region}.stt.speech.microsoft.com/speech/universal/v2"
translation_config.set_service_property(
name="endpoint",
value=endpoint_url,
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
)
设置自定义模型
translation_config.set_service_property(
name="modelCategory",
value=custom_model_category_id,
channel=speechsdk.ServicePropertyChannel.UriQueryParameter
)
使用默认麦克风
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
translation_recognizer = speechsdk.translation.TranslationRecognizer(
translation_config=translation_config, audio_config=audio_config
)
print("请说话,系统将识别并翻译您的内容...")
result = translation_recognizer.recognize_once_async().get()
if result.reason == speechsdk.ResultReason.TranslatedSpeech:
print(f"识别结果: {result.text}")
print(f"翻译结果 ({target_language}): {result.translations.get(target_language)}")
elif result.reason == speechsdk.ResultReason.NoMatch:
print("无法识别语音")
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
print(f"翻译已取消: {cancellation_details.reason}")
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print(f"错误详情: {cancellation_details.error_details}")