Skip to content

[Bug]: AutoDetectSourceLanguage not works well in SpeechSDK.TranslationRecognizer, Error: throwIfNullOrUndefined:SpeechServiceConnection_RecoLanguage #2935

@stonefishy

Description

@stonefishy

When using the TranslationRegcognizer of the SpeechSDK for AutoDetectLanguage case, It throws an error "Error: throwIfNullOrUndefined:SpeechServiceConnection_RecoLanguage" when not set the speechRecognitionLanguage of speechConfig. But if this property set, it can not auto detect language.

Javascript SDK version: 1.45.0

Below is source code.

const TargetLanguage = "en-US";
const AutoDetectLanguages = ["zh-CN", "ja-JP", "ko-KR"];
const speechConfig = SpeechSDK.SpeechTranslationConfig.fromSubscription(config.SPEECH_SUBSCRIPTION_KEY, config.SPEECH_SERVICE_REGION);

// It throws the error "Error: throwIfNullOrUndefined:SpeechServiceConnection_RecoLanguage" when not setting below language to "speechRecognitionLanguage" property.
// speechConfig.speechRecognitionLanguage = "zh-CN";

speechConfig.outputFormat = SpeechSDK.OutputFormat.Detailed;
speechConfig.addTargetLanguage(TargetLanguage);
speechConfig.setProperty(SpeechSDK.PropertyId.SpeechServiceConnection_TranslationVoice, "en-US-JennyNeural");
const audioConfig = SpeechSDK.AudioConfig.fromStreamInput(stream);
const autoDetectSourceLanguageConfig = SpeechSDK.AutoDetectSourceLanguageConfig.fromLanguages(AutoDetectLanguages);
autoDetectSourceLanguageConfig.mode = SpeechSDK.LanguageIdMode.Continuous;
const recognizer = SpeechSDK.TranslationRecognizer.FromConfig(speechConfig, autoDetectSourceLanguageConfig, audioConfig);
recognizer.recognizing = speechRecognizing;
recognizer.recognized = speechRecognized;
recognizer.synthesizing = speechSynthesizing;

In the C# SDK example code which in https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/csharp/sharedcontent/console/translation_samples.cs. It proves that there is no need to set the speechRecognitionLanguage property to speechConfig when using AutoDetectLanguage feature.

After looking at the javascript SDK source code. I found there is an condition to check speechRecognitionLanguage property in constructor TranslationRecognizer. Please see below screenshot. The issue is gone after removing this check condition in constructor, and the AutoDetectLanguage feature works well.

Image

I think it should consider DO NOT to check this property speechRecognitionLanguage of speechConfig when autoDetectSourceLanguageConfig is set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    update neededFor items that are in progress but have not been updated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions