forked from xiaozhi/xiaozhi-esp32
ESP-BOX-3 / LichuangDev enable AEC to support realtime chat (#429)
* read frame duration from server * fit wechat style emoji size * Make Wechat UI look better * Add Realtime Chat to ESP-BOX-3/LichuangDev * disable debug log * Fix Sh1106 Compile Error Bug. IDF 5.3.2 Not supporting sh1106-esp-idf. (#424) * Fix ESP32 Board Led No Light Bug (#427) * add board esp32-s3-touch-lcd-3.5 (#415) * add board esp32-s3-touch-lcd-3.5 * add axp2101 --------- Co-authored-by: flyingtjy <flyingtjy@gmail.com> --------- Co-authored-by: ooxxU <71391474@qq.com> Co-authored-by: flying1425 <79792003+flying1425@users.noreply.github.com> Co-authored-by: flyingtjy <flyingtjy@gmail.com>
This commit is contained in:
@@ -254,6 +254,10 @@ void MqttProtocol::ParseServerHello(const cJSON* root) {
|
||||
if (sample_rate != NULL) {
|
||||
server_sample_rate_ = sample_rate->valueint;
|
||||
}
|
||||
auto frame_duration = cJSON_GetObjectItem(audio_params, "frame_duration");
|
||||
if (frame_duration != NULL) {
|
||||
server_frame_duration_ = frame_duration->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
auto udp = cJSON_GetObjectItem(root, "udp");
|
||||
|
||||
@@ -49,7 +49,7 @@ void Protocol::SendWakeWordDetected(const std::string& wake_word) {
|
||||
void Protocol::SendStartListening(ListeningMode mode) {
|
||||
std::string message = "{\"session_id\":\"" + session_id_ + "\"";
|
||||
message += ",\"type\":\"listen\",\"state\":\"start\"";
|
||||
if (mode == kListeningModeAlwaysOn) {
|
||||
if (mode == kListeningModeRealtime) {
|
||||
message += ",\"mode\":\"realtime\"";
|
||||
} else if (mode == kListeningModeAutoStop) {
|
||||
message += ",\"mode\":\"auto\"";
|
||||
|
||||
@@ -21,7 +21,7 @@ enum AbortReason {
|
||||
enum ListeningMode {
|
||||
kListeningModeAutoStop,
|
||||
kListeningModeManualStop,
|
||||
kListeningModeAlwaysOn // 需要 AEC 支持
|
||||
kListeningModeRealtime // 需要 AEC 支持
|
||||
};
|
||||
|
||||
class Protocol {
|
||||
@@ -31,6 +31,9 @@ public:
|
||||
inline int server_sample_rate() const {
|
||||
return server_sample_rate_;
|
||||
}
|
||||
inline int server_frame_duration() const {
|
||||
return server_frame_duration_;
|
||||
}
|
||||
inline const std::string& session_id() const {
|
||||
return session_id_;
|
||||
}
|
||||
@@ -60,7 +63,8 @@ protected:
|
||||
std::function<void()> on_audio_channel_closed_;
|
||||
std::function<void(const std::string& message)> on_network_error_;
|
||||
|
||||
int server_sample_rate_ = 16000;
|
||||
int server_sample_rate_ = 24000;
|
||||
int server_frame_duration_ = 60;
|
||||
bool error_occurred_ = false;
|
||||
std::string session_id_;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_incoming_time_;
|
||||
|
||||
@@ -146,6 +146,10 @@ void WebsocketProtocol::ParseServerHello(const cJSON* root) {
|
||||
if (sample_rate != NULL) {
|
||||
server_sample_rate_ = sample_rate->valueint;
|
||||
}
|
||||
auto frame_duration = cJSON_GetObjectItem(audio_params, "frame_duration");
|
||||
if (frame_duration != NULL) {
|
||||
server_frame_duration_ = frame_duration->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
xEventGroupSetBits(event_group_handle_, WEBSOCKET_PROTOCOL_SERVER_HELLO_EVENT);
|
||||
|
||||
Reference in New Issue
Block a user