From 7b671f21e03f105bf9062591eb389a54150ad5a6 Mon Sep 17 00:00:00 2001 From: LittleMouse Date: Mon, 22 Dec 2025 12:19:30 +0800 Subject: [PATCH] [update] update melotts play stop cap --- .../llm_framework/main_audio/src/main.cpp | 8 ++--- .../llm_framework/main_melotts/src/main.cpp | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/projects/llm_framework/main_audio/src/main.cpp b/projects/llm_framework/main_audio/src/main.cpp index 216a4d7..6a54c7b 100644 --- a/projects/llm_framework/main_audio/src/main.cpp +++ b/projects/llm_framework/main_audio/src/main.cpp @@ -495,13 +495,13 @@ public: #endif if (_rawdata == "play") { - return play_state ? "None" : "Runing"; + return play_state ? "None" : "Running"; } else if (_rawdata == "cap") { - return cap_state ? "None" : "Runing"; + return cap_state ? "None" : "Running"; } else { std::ostringstream return_val; - return_val << "{\"play\":" << (play_state ? "\"None\"" : "\"Runing\"") - << ",\"cap\":" << (cap_state ? "\"None\"" : "\"Runing\"") << "}"; + return_val << "{\"play\":" << (play_state ? "\"None\"" : "\"Running\"") + << ",\"cap\":" << (cap_state ? "\"None\"" : "\"Running\"") << "}"; return return_val.str(); } } diff --git a/projects/llm_framework/main_melotts/src/main.cpp b/projects/llm_framework/main_melotts/src/main.cpp index c4e2122..4b6f351 100644 --- a/projects/llm_framework/main_melotts/src/main.cpp +++ b/projects/llm_framework/main_melotts/src/main.cpp @@ -22,6 +22,7 @@ #include #include "../../../../SDK/components/utilities/include/sample_log.h" #include "subprocess.h" +#include using namespace StackFlows; @@ -87,6 +88,7 @@ public: task_callback_t out_callback_; bool enaudio_; int awake_delay_ = 1000; + bool cap_; std::string tts_string_stream_buff; bool parse_config(const nlohmann::json &config_body) @@ -255,12 +257,42 @@ public: { try { std::vector wav_pcm_data; +#if !defined(CONFIG_AX_620E_MSP_ENABLED) && !defined(CONFIG_AX_620Q_MSP_ENABLED) + std::string initial_status = unit_call("audio", "audio_status", "sys"); + if (!cap_ && initial_status.find("\"cap\":\"Running\"") != std::string::npos) { + unit_call("audio", "cap_stop_all", "sys"); + cap_ = true; + } +#endif if (msg_str.empty()) { if (out_callback_) { std::string output = wav_pcm_data.empty() ? std::string() : std::string((char *)wav_pcm_data.data(), wav_pcm_data.size() * sizeof(int16_t)); out_callback_(output, finish); +#if !defined(CONFIG_AX_620E_MSP_ENABLED) && !defined(CONFIG_AX_620Q_MSP_ENABLED) + int none_count = 0; + const int max_iterations = 100; + + for (int i = 0; i < max_iterations; ++i) { + std::string current_status = unit_call("audio", "audio_status", "sys"); + if (current_status.find("\"play\":\"None\"") != std::string::npos) { + none_count++; + } else { + none_count = 0; + } + if (none_count >= 5) { + break; + } + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + + if (cap_) { + unit_call("audio", "cap", "sys"); + cap_ = false; + } +#endif } return false; } @@ -528,7 +560,11 @@ public: llm_channel->send(llm_task_obj->response_format_, base64_data, LLM_NO_ERROR); } if (llm_task_obj->response_format_.find("sys") != std::string::npos) { +#if defined(CONFIG_AX_620E_MSP_ENABLED) || defined(CONFIG_AX_620Q_MSP_ENABLED) unit_call("audio", "queue_play", data); +#else + unit_call("audio", "play_raw", data); +#endif } }