add device state
This commit is contained in:
parent
c4a50bc6b2
commit
6783da891c
@ -34,7 +34,7 @@
|
||||
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
|
||||
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
|
||||
|
||||
|
||||
static DeviceState deviceState = kDeviceStateIdle;
|
||||
|
||||
static ReturnValue sleep_helper_set_mode_callback(const PropertyList* properties) {
|
||||
Property* mode_prop = property_list_get_by_name(properties, "mode");
|
||||
@ -263,6 +263,44 @@ void app_mcp_init(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void app_set_device_state(DeviceState state){
|
||||
deviceState = state;
|
||||
switch(deviceState){
|
||||
case kDeviceStateIdle:
|
||||
LOGE("set_device_state -> idle\n");
|
||||
break;
|
||||
case kDeviceStateConnecting:
|
||||
LOGE("set_device_state -> connecting\n");
|
||||
break;
|
||||
case kDeviceStateListening:
|
||||
LOGE("set_device_state -> listening\n");
|
||||
break;
|
||||
case kDeviceStateSpeaking:
|
||||
LOGE("set_device_state -> speaking\n");
|
||||
break;
|
||||
case kDeviceStateUpgrading:
|
||||
LOGE("set_device_state -> upgrading\n");
|
||||
break;
|
||||
case kDeviceStateActivating:
|
||||
LOGE("set_device_state -> activating\n");
|
||||
break;
|
||||
case kDeviceStateAudioTesting:
|
||||
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void app_on_incoming_json(char *json_text, unsigned int size){
|
||||
|
||||
}
|
||||
DeviceState app_get_device_state(){
|
||||
return deviceState;
|
||||
}
|
||||
void app_start(){
|
||||
app_mcp_init();
|
||||
}
|
@ -21,13 +21,14 @@ typedef struct
|
||||
uint32_t sleep_timeout;
|
||||
}app_config_t;
|
||||
|
||||
enum AecMode {
|
||||
|
||||
typedef enum AecMode {
|
||||
kAecOff,
|
||||
kAecOnDeviceSide,
|
||||
kAecOnServerSide,
|
||||
};
|
||||
}AecMode;
|
||||
|
||||
enum DeviceState {
|
||||
typedef enum DeviceState {
|
||||
kDeviceStateUnknown,
|
||||
kDeviceStateStarting,
|
||||
kDeviceStateWifiConfiguring,
|
||||
@ -39,18 +40,18 @@ enum DeviceState {
|
||||
kDeviceStateActivating,
|
||||
kDeviceStateAudioTesting,
|
||||
kDeviceStateFatalError
|
||||
};
|
||||
}DeviceState;
|
||||
|
||||
enum AbortReason {
|
||||
typedef enum AbortReason {
|
||||
kAbortReasonNone,
|
||||
kAbortReasonWakeWordDetected
|
||||
};
|
||||
}AbortReason;
|
||||
|
||||
enum ListeningMode {
|
||||
typedef enum ListeningMode {
|
||||
kListeningModeAutoStop,
|
||||
kListeningModeManualStop,
|
||||
kListeningModeRealtime // 需要 AEC 支持
|
||||
};
|
||||
}ListeningMode;
|
||||
|
||||
|
||||
#include "cJSON.h"
|
||||
@ -106,6 +107,8 @@ char* app_get_ota_url();
|
||||
|
||||
void app_start();
|
||||
|
||||
void app_set_device_state(DeviceState state);
|
||||
DeviceState app_get_device_state();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -580,7 +580,7 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
|
||||
{
|
||||
cJSON *text = cJSON_GetObjectItem(root, "text");
|
||||
if(text != NULL){
|
||||
LOGE(">> %s\n",text->valuestring);
|
||||
LOGE("STT >> %s\n",text->valuestring);
|
||||
}
|
||||
|
||||
}
|
||||
@ -589,8 +589,29 @@ void rtc_websocket_msg_handle(char *json_text, unsigned int size)
|
||||
cJSON *state = cJSON_GetObjectItem(root, "state");
|
||||
cJSON *text = cJSON_GetObjectItem(root, "text");
|
||||
if(state != NULL && text != NULL){
|
||||
LOGE("<< (%s) %s\n",state->valuestring,text->valuestring);
|
||||
}
|
||||
LOGE("TTS << (%s) %s\n",state->valuestring,text->valuestring);
|
||||
}
|
||||
if(text == NULL) return;
|
||||
if (strcmp(state->valuestring, "start") == 0) {
|
||||
if (app_get_device_state() == kDeviceStateIdle || app_get_device_state() == kDeviceStateListening) {
|
||||
app_set_device_state(kDeviceStateSpeaking);
|
||||
}
|
||||
}
|
||||
else if (strcmp(state->valuestring, "stop") == 0) {
|
||||
if (app_get_device_state() == kDeviceStateSpeaking) {
|
||||
app_set_device_state(kDeviceStateListening);
|
||||
}
|
||||
}
|
||||
else if (strcmp(state->valuestring, "sentence_start") == 0) {
|
||||
if (app_get_device_state() == kDeviceStateIdle || app_get_device_state() == kDeviceStateListening) {
|
||||
app_set_device_state(kDeviceStateSpeaking);
|
||||
}
|
||||
}
|
||||
else if (strcmp(state->valuestring, "sentence_end") == 0) {
|
||||
if (app_get_device_state() == kDeviceStateSpeaking) {
|
||||
app_set_device_state(kDeviceStateListening);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if APPLICATION_IOT_PROTOCOL_MCP
|
||||
@ -639,7 +660,7 @@ static void poka_aud_tras_main(void)
|
||||
// LOGE("msg = %02x %02x len = %d \n",msg.opus_addr[0],msg.opus_addr[1],msg.opus_len);
|
||||
ret = bk_aud_intf_write_spk_data((uint8_t *)msg.opus_addr, msg.opus_len);
|
||||
|
||||
rtos_delay_milliseconds(61);
|
||||
rtos_delay_milliseconds(60);
|
||||
|
||||
// LOGE("rv opus len: %d \r\n", msg.opus_len);
|
||||
// int32_t decoder_len = opus_decode(dec, msg.opus_addr, msg.opus_len, (int16_t *)pcm_out2, 960, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user