|
|
|
@ -73,6 +73,9 @@ object AgentService : CoroutineScope { |
|
|
|
|
|
|
|
private var azureSpeechKey: String = "" |
|
|
|
private var azureSpeechRegion: String = "" |
|
|
|
private var xunfeiAppId: String = "" |
|
|
|
private var xunfeiAccessKeyId: String = "" |
|
|
|
private var xunfeiAccessKeySecret: String = "" |
|
|
|
|
|
|
|
// 协程相关 |
|
|
|
private val job = SupervisorJob() |
|
|
|
@ -238,6 +241,9 @@ object AgentService : CoroutineScope { |
|
|
|
//保存配置 |
|
|
|
this.azureSpeechKey = config["azureSpeechKey"]?.toString() ?: "" |
|
|
|
this.azureSpeechRegion = config["azureSpeechRegion"]?.toString() ?: "" |
|
|
|
this.xunfeiAppId = config["xunfeiAppId"]?.toString() ?: "" |
|
|
|
this.xunfeiAccessKeyId = config["xunfeiAccessKeyId"]?.toString() ?: "" |
|
|
|
this.xunfeiAccessKeySecret = config["xunfeiAccessKeySecret"]?.toString() ?: "" |
|
|
|
if (!customSystemPrompt.isNullOrBlank()) { |
|
|
|
systemPrompt = customSystemPrompt |
|
|
|
} else { |
|
|
|
@ -257,7 +263,10 @@ object AgentService : CoroutineScope { |
|
|
|
region = config["azureSpeechRegion"]?.toString() ?: "", |
|
|
|
supportedLanguages = supportedLanguages, |
|
|
|
audioSourceType = if (isExternalActive) AzureAsrHelper.AudioSourceType.EXTERNAL |
|
|
|
else AzureAsrHelper.AudioSourceType.MICROPHONE |
|
|
|
else AzureAsrHelper.AudioSourceType.MICROPHONE, |
|
|
|
xunfeiAppId = config["xunfeiAppId"]?.toString() ?: "", |
|
|
|
xunfeiAccessKeyId = config["xunfeiAccessKeyId"]?.toString() ?: "", |
|
|
|
xunfeiAccessKeySecret = config["xunfeiAccessKeySecret"]?.toString() ?: "" |
|
|
|
) |
|
|
|
|
|
|
|
if (asrInitSuccess) { |
|
|
|
@ -306,6 +315,9 @@ object AgentService : CoroutineScope { |
|
|
|
vipExptime = config["vipexptime"]?.toString()?.toIntOrNull() ?: vipExptime; |
|
|
|
navigationMode = config["navigationMode"]?.toString() ?: navigationMode |
|
|
|
musicServiceType = config["musicServiceType"]?.toString() ?: "" |
|
|
|
xunfeiAppId = config["xunfeiAppId"]?.toString() ?: xunfeiAppId |
|
|
|
xunfeiAccessKeyId = config["xunfeiAccessKeyId"]?.toString() ?: xunfeiAccessKeyId |
|
|
|
xunfeiAccessKeySecret = config["xunfeiAccessKeySecret"]?.toString() ?: xunfeiAccessKeySecret |
|
|
|
chatApiService.initialize( |
|
|
|
config["openaiApiKey"]?.toString() ?: "", |
|
|
|
config["openaiBaseUrl"]?.toString() ?: "", |
|
|
|
@ -1407,7 +1419,10 @@ object AgentService : CoroutineScope { |
|
|
|
subscriptionKey = this.azureSpeechKey, |
|
|
|
region = this.azureSpeechRegion, |
|
|
|
supportedLanguages = languages.toTypedArray(), |
|
|
|
audioSourceType = audioSourceType |
|
|
|
audioSourceType = audioSourceType, |
|
|
|
xunfeiAppId = this.xunfeiAppId, |
|
|
|
xunfeiAccessKeyId = this.xunfeiAccessKeyId, |
|
|
|
xunfeiAccessKeySecret = this.xunfeiAccessKeySecret |
|
|
|
) ?: false |
|
|
|
if (asrSuccess) { |
|
|
|
recognizeCallback() |
|
|
|
@ -1631,11 +1646,18 @@ object AgentService : CoroutineScope { |
|
|
|
* 发送事件 |
|
|
|
*/ |
|
|
|
private fun sendEvent(eventName: String, data: Map<String, Any>) { |
|
|
|
val shouldAttachAsrProvider = eventName == "recognizing" || eventName.startsWith("recognition_") |
|
|
|
val finalData: Map<String, Any> = if (shouldAttachAsrProvider && !data.containsKey("provider")) { |
|
|
|
val provider = azureAsrHelper?.getAsrProvider() ?: "unknown" |
|
|
|
data.toMutableMap().apply { put("provider", provider) } |
|
|
|
} else { |
|
|
|
data |
|
|
|
} |
|
|
|
// 切换到主线程执行监听器回调,避免 UI 更新问题 |
|
|
|
launch(Dispatchers.Main) { |
|
|
|
listeners.forEach { listener -> |
|
|
|
try { |
|
|
|
listener.onEvent(eventName, data) |
|
|
|
listener.onEvent(eventName, finalData) |
|
|
|
} catch (e: Exception) { |
|
|
|
Log.e(TAG, "向监听器发送事件失败", e) |
|
|
|
} |
|
|
|
|