From f10cdf628cced038dc420c4bb3219b5208e0fbc3 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Tue, 3 Feb 2026 10:41:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(azure=5Fspeech):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A4=9A=E4=B8=AD=E6=96=87=E5=8F=98=E4=BD=93=E6=97=B6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=90=AF=E7=94=A8=E8=AE=AF=E9=A3=9EASR=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当配置的语言列表包含两个或以上的中文变体(如 zh-CN 和 zh-TW)时,即使所有语言都在讯飞支持范围内,也应禁用讯飞ASR,因为讯飞无法同时处理多个中文方言。此修改在决定是否启用讯飞ASR的条件中增加了对多中文变体的检查。 --- .../yunqiinnovation/azure_speech/AzureAsrHelper.kt | 11 ++++++++++- .../Sources/azure_speech/AzureAsrHelper.swift | 14 ++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) 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) } } -