Browse Source

feat: 添加ASR初始化日志以增强调试能力

在iOS和Android平台添加ASR引擎初始化时的详细日志记录,包括支持的语音、区域配置、音频源类型以及讯飞配置状态。这些日志有助于在部署和生产环境中快速诊断语音识别初始化问题。
newdev_shunjiawei
lxm 8 months ago
parent
commit
12a49c59cd
  1. 11
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt
  2. 7
      local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt
  3. 18
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift
  4. 10
      local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift

11
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureAsrHelper.kt

@ -127,6 +127,11 @@ class AzureAsrHelper(private val context: Context) {
this.supportedLanguages = supportedLanguages
}
Log.i(
tag,
"lxm---ASR initialize: supportedLanguages=${supportedLanguages.joinToString(",")}, audioSourceType=$audioSourceType"
)
val xunfeiConfigReady = this.xunfeiAppId.isNotBlank() &&
this.xunfeiAccessKeyId.isNotBlank() &&
this.xunfeiAccessKeySecret.isNotBlank()
@ -140,6 +145,11 @@ class AzureAsrHelper(private val context: Context) {
this.currentLanguage = supportedLanguages[0]
}
Log.i(
tag,
"lxm---ASR initialize derived: isAutoDetectLanguage=$isAutoDetectLanguage, currentLanguage=$currentLanguage, provider=${getAsrProvider()}, xunfeiConfigured=$xunfeiConfigReady"
)
// 创建语音配置
speechConfig = SpeechConfig.fromSubscription(subscriptionKey, region).apply {
if (isAutoDetectLanguage) {
@ -314,6 +324,7 @@ class AzureAsrHelper(private val context: Context) {
}
try {
Log.d(tag, "startContinuousRecognition: ${audioStream.isContinuousRecognitionActive}")
xunFeiAsrHelper?.start(callback, currentLanguage, isAutoDetectLanguage, isRemoveFirstPunctuation)
this.audioSourceType = audioSourceType

7
local_plugins/azure_speech/android/src/main/kotlin/com/yunqiinnovation/azure_speech/AzureSpeechPlugin.kt

@ -423,6 +423,13 @@ class AzureSpeechPlugin : BleService.Callback, FlutterPlugin {
val xunfeiAccessKeySecret = call.argument<String>("xunfeiAccessKeySecret") ?: ""
try {
val isXunfeiConfigured = xunfeiAppId.isNotBlank() &&
xunfeiAccessKeyId.isNotBlank() &&
xunfeiAccessKeySecret.isNotBlank()
FileLogger.i(
tag,
"lxm---ASR initialize args: supportedLanguages=${supportedLanguages.joinToString(",")}, useExternalAudio=$useExternalAudio, region=$region, xunfeiConfigured=$isXunfeiConfigured"
)
FileLogger.d(tag, "选择音频源类型: ${useExternalAudio}") //
// 选择音频源类型
val audioSourceType = if (useExternalAudio) {

18
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureAsrHelper.swift

@ -136,9 +136,27 @@ public class AzureAsrHelper: NSObject {
$0 == "zh-CN" || $0 == "en-US" || $0 == "zh-HK" || $0 == "zh-TW"
} && xunfeiConfigReady
os_log(
"ASR helper initialize: supportedLanguages=%{public}@, audioSourceType=%{public}@, xunfeiConfigured=%{public}@, provider=%{public}@",
log: log,
type: .info,
supportedLanguages.joined(separator: ","),
String(describing: audioSourceType),
String(xunfeiConfigReady),
asrProvider()
)
// 根据支持的语言数量决定是否启用自动语言检测
self.isAutoDetectLanguage = supportedLanguages.count >= 2
os_log(
"ASR helper initialize derived: isAutoDetectLanguage=%{public}@, currentLanguage=%{public}@",
log: log,
type: .info,
String(self.isAutoDetectLanguage),
self.currentLanguage
)
// 如果只有一种语言,设置为当前语言
if !isAutoDetectLanguage && !supportedLanguages.isEmpty {
self.currentLanguage = supportedLanguages[0]

10
local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureSpeechPlugin.swift

@ -343,6 +343,16 @@ private func sendAstEvent(_ event: [String: Any]) {
let xunfeiAppId = args["xunfeiAppId"] as? String ?? ""
let xunfeiAccessKeyId = args["xunfeiAccessKeyId"] as? String ?? ""
let xunfeiAccessKeySecret = args["xunfeiAccessKeySecret"] as? String ?? ""
let isXunfeiConfigured = !xunfeiAppId.isEmpty && !xunfeiAccessKeyId.isEmpty && !xunfeiAccessKeySecret.isEmpty
os_log(
"ASR initialize args: supportedLanguages=%{public}@, region=%{public}@, xunfeiConfigured=%{public}@",
log: log,
type: .info,
supportedLanguages.joined(separator: ","),
region,
String(isXunfeiConfigured)
)
// 初始化ASR引擎
let success = azureAsrHelper.initialize(

Loading…
Cancel
Save