Browse Source

Merge branch 'liwei' of https://github.com/deepcloud2048/deep_voice into new_dev

weicu
liwei1dao 1 year ago
parent
commit
585dd82bd9
  1. 1
      lib/modules/agent/controllers/agent_controller.dart
  2. 9
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  3. 10
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt
  4. 10
      local_plugins/agent_service/lib/agent_service.dart

1
lib/modules/agent/controllers/agent_controller.dart

@ -155,6 +155,7 @@ class AgentController extends GetxController {
@override @override
void onClose() { void onClose() {
AgentService.stopAiSteam(); //停止AI流
AgentService.stopConversation(); // 停止当前会话 AgentService.stopConversation(); // 停止当前会话
AgentService.stopTts(); // 停止当前语音 AgentService.stopTts(); // 停止当前语音
textController.dispose(); textController.dispose();

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

@ -572,7 +572,7 @@ object AgentService : CoroutineScope {
/** /**
* 停止AI流输出 * 停止AI流输出
*/ */
private fun stopAiStream() { fun stopAiStream() {
if (isAiStreaming) { if (isAiStreaming) {
try { try {
// 先更新状态,避免回调时的状态不一致 // 先更新状态,避免回调时的状态不一致
@ -581,7 +581,8 @@ object AgentService : CoroutineScope {
// 取消当前AI生成任务 // 取消当前AI生成任务
currentAiJob?.cancel() currentAiJob?.cancel()
currentAiJob = null currentAiJob = null
currsessionId = "" //取消会话
// 通知ChatAPI服务终止当前流式请求 // 通知ChatAPI服务终止当前流式请求
chatApiService.cancelCurrentStream() chatApiService.cancelCurrentStream()
@ -757,9 +758,6 @@ object AgentService : CoroutineScope {
responseBuilder.append(token) responseBuilder.append(token)
if (speakResponse && broadcast) { if (speakResponse && broadcast) {
ttsService?.speakStream(token) ttsService?.speakStream(token)
if (token.length > 0) {
audioPlayer?.stopAudio()
}
} }
if (broadcast) { if (broadcast) {
// 发送流式回复token // 发送流式回复token
@ -775,6 +773,7 @@ object AgentService : CoroutineScope {
// 视情况决定是否朗读回复 // 视情况决定是否朗读回复
if (speakResponse && broadcast && sessionid == currsessionId){ if (speakResponse && broadcast && sessionid == currsessionId){
ttsService?.flushStream() ttsService?.flushStream()
audioPlayer?.stopAudio()
} }
val response = responseBuilder.toString() val response = responseBuilder.toString()
// 发送完整回复,包含是否有图片的标记 // 发送完整回复,包含是否有图片的标记

10
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt

@ -177,6 +177,16 @@ class AgentServicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.Stream
result.error("STOP_TTS_ERROR", "停止语音合成失败: ${e.message}", null) result.error("STOP_TTS_ERROR", "停止语音合成失败: ${e.message}", null)
} }
} }
"stopAiSteam" -> {
try {
AgentService.stopAiStream()
result.success(true)
} catch (e: Exception) {
Log.e(TAG, "停止语音合成失败", e)
result.error("STOP_TTS_ERROR", "停止语音合成失败: ${e.message}", null)
}
}
"clearChatHistory" -> { "clearChatHistory" -> {
try { try {
AgentService.clearChatHistory { success -> AgentService.clearChatHistory { success ->

10
local_plugins/agent_service/lib/agent_service.dart

@ -293,6 +293,16 @@ class AgentService {
} }
} }
/// 停止语音合成
static Future<bool> stopAiSteam() async {
try {
final bool result = await _channel.invokeMethod('stopAiSteam');
return result;
} on PlatformException catch (e) {
throw AgentServiceException(e.code, e.message ?? '停止语音合成失败', e.details);
}
}
/// 停止语音合成 /// 停止语音合成
static Future<bool> stopTts() async { static Future<bool> stopTts() async {
try { try {

Loading…
Cancel
Save