Skip to content

Commit 7b671f2

Browse files
author
LittleMouse
committed
[update] update melotts play stop cap
1 parent eff3a47 commit 7b671f2

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

projects/llm_framework/main_audio/src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ class llm_audio : public StackFlow {
495495
#endif
496496

497497
if (_rawdata == "play") {
498-
return play_state ? "None" : "Runing";
498+
return play_state ? "None" : "Running";
499499
} else if (_rawdata == "cap") {
500-
return cap_state ? "None" : "Runing";
500+
return cap_state ? "None" : "Running";
501501
} else {
502502
std::ostringstream return_val;
503-
return_val << "{\"play\":" << (play_state ? "\"None\"" : "\"Runing\"")
504-
<< ",\"cap\":" << (cap_state ? "\"None\"" : "\"Runing\"") << "}";
503+
return_val << "{\"play\":" << (play_state ? "\"None\"" : "\"Running\"")
504+
<< ",\"cap\":" << (cap_state ? "\"None\"" : "\"Running\"") << "}";
505505
return return_val.str();
506506
}
507507
}

projects/llm_framework/main_melotts/src/main.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <samplerate.h>
2323
#include "../../../../SDK/components/utilities/include/sample_log.h"
2424
#include "subprocess.h"
25+
#include <global_config.h>
2526

2627
using namespace StackFlows;
2728

@@ -87,6 +88,7 @@ class llm_task {
8788
task_callback_t out_callback_;
8889
bool enaudio_;
8990
int awake_delay_ = 1000;
91+
bool cap_;
9092
std::string tts_string_stream_buff;
9193

9294
bool parse_config(const nlohmann::json &config_body)
@@ -255,12 +257,42 @@ class llm_task {
255257
{
256258
try {
257259
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
258267
if (msg_str.empty()) {
259268
if (out_callback_) {
260269
std::string output = wav_pcm_data.empty() ? std::string()
261270
: std::string((char *)wav_pcm_data.data(),
262271
wav_pcm_data.size() * sizeof(int16_t));
263272
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
264296
}
265297
return false;
266298
}
@@ -528,7 +560,11 @@ class llm_tts : public StackFlow {
528560
llm_channel->send(llm_task_obj->response_format_, base64_data, LLM_NO_ERROR);
529561
}
530562
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)
531564
unit_call("audio", "queue_play", data);
565+
#else
566+
unit_call("audio", "play_raw", data);
567+
#endif
532568
}
533569
}
534570

0 commit comments

Comments
 (0)