|
22 | 22 | #include <samplerate.h> |
23 | 23 | #include "../../../../SDK/components/utilities/include/sample_log.h" |
24 | 24 | #include "subprocess.h" |
| 25 | +#include <global_config.h> |
25 | 26 |
|
26 | 27 | using namespace StackFlows; |
27 | 28 |
|
@@ -87,6 +88,7 @@ class llm_task { |
87 | 88 | task_callback_t out_callback_; |
88 | 89 | bool enaudio_; |
89 | 90 | int awake_delay_ = 1000; |
| 91 | + bool cap_; |
90 | 92 | std::string tts_string_stream_buff; |
91 | 93 |
|
92 | 94 | bool parse_config(const nlohmann::json &config_body) |
@@ -255,12 +257,42 @@ class llm_task { |
255 | 257 | { |
256 | 258 | try { |
257 | 259 | std::vector<int16_t> wav_pcm_data; |
| 260 | +#if !defined(CONFIG_AX_620E_MSP_ENABLED) && !defined(CONFIG_AX_620Q_MSP_ENABLED) |
| 261 | + std::string initial_status = unit_call("audio", "audio_status", "sys"); |
| 262 | + if (!cap_ && initial_status.find("\"cap\":\"Running\"") != std::string::npos) { |
| 263 | + unit_call("audio", "cap_stop_all", "sys"); |
| 264 | + cap_ = true; |
| 265 | + } |
| 266 | +#endif |
258 | 267 | if (msg_str.empty()) { |
259 | 268 | if (out_callback_) { |
260 | 269 | std::string output = wav_pcm_data.empty() ? std::string() |
261 | 270 | : std::string((char *)wav_pcm_data.data(), |
262 | 271 | wav_pcm_data.size() * sizeof(int16_t)); |
263 | 272 | out_callback_(output, finish); |
| 273 | +#if !defined(CONFIG_AX_620E_MSP_ENABLED) && !defined(CONFIG_AX_620Q_MSP_ENABLED) |
| 274 | + int none_count = 0; |
| 275 | + const int max_iterations = 100; |
| 276 | + |
| 277 | + for (int i = 0; i < max_iterations; ++i) { |
| 278 | + std::string current_status = unit_call("audio", "audio_status", "sys"); |
| 279 | + if (current_status.find("\"play\":\"None\"") != std::string::npos) { |
| 280 | + none_count++; |
| 281 | + } else { |
| 282 | + none_count = 0; |
| 283 | + } |
| 284 | + if (none_count >= 5) { |
| 285 | + break; |
| 286 | + } |
| 287 | + |
| 288 | + std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 289 | + } |
| 290 | + |
| 291 | + if (cap_) { |
| 292 | + unit_call("audio", "cap", "sys"); |
| 293 | + cap_ = false; |
| 294 | + } |
| 295 | +#endif |
264 | 296 | } |
265 | 297 | return false; |
266 | 298 | } |
@@ -528,7 +560,11 @@ class llm_tts : public StackFlow { |
528 | 560 | llm_channel->send(llm_task_obj->response_format_, base64_data, LLM_NO_ERROR); |
529 | 561 | } |
530 | 562 | if (llm_task_obj->response_format_.find("sys") != std::string::npos) { |
| 563 | +#if defined(CONFIG_AX_620E_MSP_ENABLED) || defined(CONFIG_AX_620Q_MSP_ENABLED) |
531 | 564 | unit_call("audio", "queue_play", data); |
| 565 | +#else |
| 566 | + unit_call("audio", "play_raw", data); |
| 567 | +#endif |
532 | 568 | } |
533 | 569 | } |
534 | 570 |
|
|
0 commit comments