Browse Source

fix(azure_speech): 修复多中文变体时错误启用讯飞ASR的问题

当配置的语言列表包含两个或以上的中文变体(如 zh-CN 和 zh-TW)时,即使所有语言都在讯飞支持范围内,也应禁用讯飞ASR,因为讯飞无法同时处理多个中文方言。此修改在决定是否启用讯飞ASR的条件中增加了对多中文变体的检查。
newdev_shunjiawei
lxm 8 months ago
parent
commit
29425b8367
  1. 11
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt
  2. 14
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift

11
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

14
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)
}
}

Loading…
Cancel
Save