Browse Source

add

newdev_shunjiawei
wolfplus 1 year ago
parent
commit
c4d1ee0358
  1. 55
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  2. 6
      local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt

55
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -985,4 +985,59 @@ object AgentService : CoroutineScope {
return true
}
/**
* 简单音频播放器,用于播放提示音等
*/
class AudioPlayer(private val context: Context) {
private var mediaPlayer: MediaPlayer? = null
/**
* 播放音频资源
* @param resId 资源ID
*/
fun playAudio(resId: Int) {
try {
// 释放之前的资源
release()
// 创建播放器并设置资源
mediaPlayer = MediaPlayer().apply {
// 设置资源
context.resources.openRawResourceFd(resId)?.use { fd ->
setDataSource(fd.fileDescriptor, fd.startOffset, fd.length)
}
// 播放完成后自动释放资源
setOnCompletionListener {
release()
}
// 准备并播放
prepare()
start()
}
FileLogger.d(TAG, "开始播放音频资源")
} catch (e: Exception) {
FileLogger.e(TAG, "播放音频资源异常: ${e.message}", e)
release()
}
}
/**
* 释放资源
*/
fun release() {
try {
mediaPlayer?.apply {
if (isPlaying) stop()
release()
}
mediaPlayer = null
} catch (e: Exception) {
// 忽略异常
}
}
}
}

6
local_plugins/open_ai_service/android/src/main/kotlin/com/yunqiinnovation/open_ai_service/OpenAIService.kt

@ -355,7 +355,11 @@ class OpenAIService(private val context: Context? = null) {
callback.onFunctionCallResult(functionCall, resultObj)
// 发送结果到OpenAI继续对话
val resultContent = resultObj.optString("context", "工具调用失败")
val resultContent = if (resultObj.has("context") && resultObj.getString("context").isNotEmpty()) {
resultObj.getString("context")
} else {
"工具调用失败"
}
sendFunctionCallResult(
messages = messages,
functionCall = functionCall,

Loading…
Cancel
Save