diff --git a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt index 1f6ac4e1e..d10835762 100644 --- a/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt +++ b/local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt @@ -135,7 +135,16 @@ class AzureAsrHelper(private val context: Context) { val xunfeiConfigReady = this.xunfeiAppId.isNotBlank() && this.xunfeiAccessKeyId.isNotBlank() && this.xunfeiAccessKeySecret.isNotBlank() - this.useXunfei = supportedLanguages.all { it == "zh-CN" || it == "en-US" || it == "zh-HK"|| it == "zh-TW" } && xunfeiConfigReady + val onlySupportedByXunfei = supportedLanguages.all { + it == "zh-CN" || it == "en-US" || it == "zh-HK" || it == "zh-TW" + } + val chineseVariantsCount = supportedLanguages + .map { it.trim().lowercase() } + .filter { it == "zh" || it.startsWith("zh-") } + .distinct() + .size + val hasMultipleChineseVariants = chineseVariantsCount >= 2 + this.useXunfei = onlySupportedByXunfei && xunfeiConfigReady && !hasMultipleChineseVariants // 根据支持的语言数量决定是否启用自动语言检测 this.isAutoDetectLanguage = supportedLanguages.size >= 2 diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift index fc8f112ca..5cc8fda70 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift @@ -131,10 +131,17 @@ public class AzureAsrHelper: NSObject { let xunfeiConfigReady = !self.xunfeiAppId.isEmpty && !self.xunfeiAccessKeyId.isEmpty && !self.xunfeiAccessKeySecret.isEmpty + let onlySupportedByXunfei = supportedLanguages.allSatisfy { + $0 == "zh-CN" || $0 == "en-US" || $0 == "zh-HK" || $0 == "zh-TW" + } + let chineseVariants = Set( + supportedLanguages + .map { $0.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() } + .filter { $0 == "zh" || $0.hasPrefix("zh-") } + ) + let hasMultipleChineseVariants = chineseVariants.count >= 2 self.useXunfei = - supportedLanguages.allSatisfy { - $0 == "zh-CN" || $0 == "en-US" || $0 == "zh-HK" || $0 == "zh-TW" - } && xunfeiConfigReady + onlySupportedByXunfei && xunfeiConfigReady && !hasMultipleChineseVariants os_log( "ASR helper initialize: supportedLanguages=%{public}@, audioSourceType=%{public}@, xunfeiConfigured=%{public}@, provider=%{public}@", @@ -1246,4 +1253,3 @@ private class AudioDataCallbackProxy: SimpleAudioReceiver.AudioDataCallback { xunfeiCallback?(data) } } -