diff --git a/CMakeLists.txt b/CMakeLists.txt index 683b908c..1c83e408 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,6 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -if($ENV{MULTINET}) - message("Enabling MultiNet support. Please note we will not provide support. Issues related to MultiNet will be closed without resolution.") - add_definitions(-DWILLOW_SUPPORT_MULTINET) -endif() - if(DEFINED ENV{WILLOW_VERSION}) add_definitions(-DWILLOW_USER_AGENT="Willow/$ENV{WILLOW_VERSION}") else() diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 975aa0b6..2954fdc8 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -5,7 +5,6 @@ endif() idf_component_register( SRC_DIRS "." - "endpoint" "${WILLOW_ETHERNET_SRC_DIRS}" INCLUDE_DIRS "." diff --git a/main/audio.c b/main/audio.c index b1c64708..6c6db37f 100644 --- a/main/audio.c +++ b/main/audio.c @@ -9,7 +9,6 @@ #include "esp_http_client.h" #include "esp_log.h" #include "esp_lvgl_port.h" -#include "esp_task_wdt.h" #include "esp_timer.h" #include "filter_resample.h" #include "flac_decoder.h" @@ -34,23 +33,10 @@ #include "ui.h" #include "was.h" -#include "endpoint/hass.h" -#include "endpoint/openhab.h" -#include "endpoint/rest.h" - -#if !defined(CONFIG_TASK_WDT_PANIC) -#define CONFIG_TASK_WDT_PANIC 10 -#endif - -#if defined(WILLOW_SUPPORT_MULTINET) -#include "generated_cmd_multinet.h" -#endif - #define DEFAULT_AUDIO_CODEC "PCM" #define DEFAULT_AUDIO_RESPONSE_TYPE "None" #define DEFAULT_RECORD_BUFFER 12 #define DEFAULT_SPEAKER_VOLUME 60 -#define DEFAULT_SPEECH_REC_MODE "WIS" #define DEFAULT_STREAM_TIMEOUT 5 #define DEFAULT_VAD_MODE 3 #define DEFAULT_VAD_TIMEOUT 300 @@ -61,7 +47,6 @@ #define HTTP_STREAM_TIMEOUT_MS 10 * 1000 -#define MULTINET_TWDT 30 #define STR_WAKE_LEN 25 #define WIS_URL_TTS_ARG "?format=WAV&speaker=CLB&text=" @@ -360,11 +345,7 @@ static void init_esp_audio(void) static esp_err_t cb_ar_event(audio_rec_evt_t *are, void *data) { - char *speech_rec_mode = NULL; int msg = -1; -#if defined(WILLOW_SUPPORT_MULTINET) - int command_id = 0; -#endif switch (are->type) { case AUDIO_REC_VAD_END: @@ -381,31 +362,9 @@ static esp_err_t cb_ar_event(audio_rec_evt_t *are, void *data) recording = true; } - speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - if (strcmp(speech_rec_mode, "Multinet") == 0) { - msg = MSG_START_LOCAL; - } else if (strcmp(speech_rec_mode, "WIS") == 0) { - msg = MSG_START; - } else { - free(speech_rec_mode); - return ESP_ERR_INVALID_ARG; - } - free(speech_rec_mode); + msg = MSG_START; xQueueSend(q_rec, &msg, 0); break; - case AUDIO_REC_COMMAND_DECT: - // Multinet timeout - ESP_LOGI(TAG, "AUDIO_REC_COMMAND_DECT"); - war.fn_err("unrecognized command"); - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_text_align(lbl_ln4, LV_TEXT_ALIGN_LEFT, 0); - lv_label_set_text(lbl_ln4, "#ff0000 Unrecognized Command"); - lvgl_port_unlock(); - } - - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); - break; case AUDIO_REC_WAKEUP_END: ESP_LOGI(TAG, "AUDIO_REC_WAKEUP_END"); msg = MSG_STOP; @@ -428,12 +387,7 @@ static esp_err_t cb_ar_event(audio_rec_evt_t *are, void *data) ESP_LOGI(TAG, "wake volume: %f", wake_data->data_volume); send_wake_start(wake_data->data_volume); reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), true); - - speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - - if (strcmp(speech_rec_mode, "WIS") == 0) { - reset_timer(hdl_sess_timer, config_get_int("stream_timeout", DEFAULT_STREAM_TIMEOUT), false); - } + reset_timer(hdl_sess_timer, config_get_int("stream_timeout", DEFAULT_STREAM_TIMEOUT), false); if (lvgl_port_lock(lvgl_lock_timeout)) { lv_obj_add_flag(lbl_ln1, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(lbl_ln2, LV_OBJ_FLAG_HIDDEN); @@ -442,62 +396,15 @@ static esp_err_t cb_ar_event(audio_rec_evt_t *are, void *data) lv_obj_clear_flag(btn_cancel, LV_OBJ_FLAG_HIDDEN); lv_obj_clear_flag(lbl_ln3, LV_OBJ_FLAG_HIDDEN); - if (strcmp(speech_rec_mode, "Multinet") == 0) { - lv_label_set_text_static(lbl_ln3, "Say local command..."); - } else if (strcmp(speech_rec_mode, "WIS") == 0) { - lv_label_set_text_static(lbl_ln3, "Say command..."); - } else { - return ESP_ERR_INVALID_ARG; - } + lv_label_set_text_static(lbl_ln3, "Say command..."); lv_obj_add_event_cb(btn_cancel, cb_btn_cancel, LV_EVENT_PRESSED, NULL); lvgl_port_unlock(); } - free(speech_rec_mode); display_set_backlight(true, false); break; default: - speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - if (strcmp(speech_rec_mode, "Multinet") == 0) { -#if defined(WILLOW_SUPPORT_MULTINET) - // Catch all for local commands - command_id = are->type; - bool was_mode = config_get_bool("was_mode", DEFAULT_WAS_MODE); - char *command_endpoint = config_get_char("command_endpoint", DEFAULT_COMMAND_ENDPOINT); - char *json; - json = calloc(29 + strlen(lookup_cmd_multinet(command_id)), sizeof(char)); - snprintf(json, 29 + strlen(lookup_cmd_multinet(command_id)), "{\"text\":\"%s\",\"language\":\"en\"}", - lookup_cmd_multinet(command_id)); - if (was_mode) { - was_send_endpoint(json, false); - } else if (strcmp(command_endpoint, "Home Assistant") == 0) { - hass_send(json); - } else if (strcmp(command_endpoint, "openHAB") == 0) { - openhab_send(lookup_cmd_multinet(command_id)); - } else if (strcmp(command_endpoint, "REST") == 0) { - rest_send(json); - } - free(command_endpoint); - free(json); - - ESP_LOGI(TAG, "Got local command ID: '%d'", command_id); - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln1, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(lbl_ln2, LV_OBJ_FLAG_HIDDEN); - lv_obj_add_flag(lbl_ln3, LV_OBJ_FLAG_HIDDEN); - - lv_label_set_text_static(lbl_ln1, "I heard command:"); - lv_label_set_text(lbl_ln2, lookup_cmd_multinet(command_id)); - lvgl_port_unlock(); - } - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); -#else - ESP_LOGE(TAG, "multinet not supported but enabled in config"); -#endif - } else { - ESP_LOGI(TAG, "cb_ar_event: unhandled event: '%d'", are->type); - } - free(speech_rec_mode); + ESP_LOGI(TAG, "cb_ar_event: unhandled event: '%d'", are->type); break; } @@ -615,18 +522,7 @@ static esp_err_t hdl_ev_hs_to_api(http_stream_event_msg_t *msg) lv_obj_add_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); lvgl_port_unlock(); } - bool was_mode = config_get_bool("was_mode", DEFAULT_WAS_MODE); - char *command_endpoint = config_get_char("command_endpoint", DEFAULT_COMMAND_ENDPOINT); - if (was_mode) { - was_send_endpoint(buf, false); - } else if (strcmp(command_endpoint, "Home Assistant") == 0) { - hass_send(buf); - } else if (strcmp(command_endpoint, "openHAB") == 0) { - openhab_send(buf); - } else if (strcmp(command_endpoint, "REST") == 0) { - rest_send(buf); - } - free(command_endpoint); + was_send_endpoint(buf, false); cJSON *cjson = cJSON_Parse(buf); cJSON *text = cJSON_GetObjectItemCaseSensitive(cjson, "text"); @@ -825,7 +721,6 @@ static esp_err_t start_rec(void) recorder_sr_cfg_t cfg_srr = { .afe_cfg = cfg_afe, .input_order = INPUT_ORDER_DEFAULT(), - .multinet_init = false, .feed_task_core = FEED_TASK_PINNED_CORE, .feed_task_prio = FEED_TASK_PRIO, .feed_task_stack = FEED_TASK_STACK_SZ, @@ -834,37 +729,12 @@ static esp_err_t start_rec(void) .fetch_task_stack = FETCH_TASK_STACK_SZ, .rb_size = 12 * 1024, // default is 6 * 1024 .partition_label = "model", - .mn_language = ESP_MN_ENGLISH, .wn_wakeword = wake_word, }; ESP_LOGI(TAG, "Using record buffer '%d'", config_get_int("record_buffer", DEFAULT_RECORD_BUFFER)); cfg_srr.rb_size = config_get_int("record_buffer", DEFAULT_RECORD_BUFFER) * 1024; - char *speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - if (strcmp(speech_rec_mode, "Multinet") == 0) { -#if defined(WILLOW_SUPPORT_MULTINET) - esp_task_wdt_config_t twdt_config = { - .timeout_ms = MULTINET_TWDT, - .idle_core_mask = 0, - .trigger_panic = CONFIG_TASK_WDT_PANIC ? true : false, - }; - - ESP_LOGI(TAG, "Using local multinet"); - ESP_LOGI(TAG, "cmd_multinet[] size: %u bytes", get_cmd_multinet_size()); -#if defined(CONFIG_ESP_TASK_WDT_INIT) - esp_task_wdt_reconfigure(&twdt_config); -#else - esp_task_wdt_init(&twdt_config); -#endif - cfg_srr.multinet_init = true; - cfg_srr.rb_size = 6 * 1024; -#else - ESP_LOGE(TAG, "multinet not supported but enabled in config"); -#endif - } - free(speech_rec_mode); - recorder_encoder_cfg_t recorder_encoder_cfg = {0}; char *audio_codec = config_get_char("audio_codec", DEFAULT_AUDIO_CODEC); @@ -944,9 +814,6 @@ static void at_read(void *data) stream_to_api = true; // this confirms that the URL is still set correctly ESP_LOGI(TAG, "Using WIS URL '%s'", audio_element_get_uri(hdl_ae_hs)); - __attribute__((fallthrough)); - case MSG_START_LOCAL: - recording = true; break; case MSG_STOP: delay = portMAX_DELAY; @@ -1020,7 +887,6 @@ void init_adc(void) esp_err_t init_audio(void) { - char *speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); char *wake_word = config_get_char("wake_word", DEFAULT_WAKE_WORD); esp_err_t ret = ESP_OK; @@ -1039,10 +905,7 @@ esp_err_t init_audio(void) init_audio_response(); init_session_timer(); - if (strcmp(speech_rec_mode, "WIS") == 0) { - init_ap_to_api(); - } - free(speech_rec_mode); + init_ap_to_api(); ESP_RETURN_ON_ERROR(start_rec(), TAG, "start_rec failed"); hdl_aha->audio_codec_set_volume(config_get_int("mic_gain", DEFAULT_MIC_GAIN)); @@ -1101,13 +964,11 @@ void deinit_audio(void) audio_pipeline_wait_for_stop(hdl_ap); audio_pipeline_terminate(hdl_ap); } - char *speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - if (strcmp(speech_rec_mode, "WIS") && hdl_ap_to_api != NULL) { + if (hdl_ap_to_api != NULL) { audio_pipeline_stop(hdl_ap_to_api); audio_pipeline_wait_for_stop(hdl_ap_to_api); audio_pipeline_terminate(hdl_ap_to_api); } - free(speech_rec_mode); if (hdl_ea != NULL) { esp_audio_destroy(hdl_ea); } diff --git a/main/audio.h b/main/audio.h index fcdd2ef6..b0491365 100644 --- a/main/audio.h +++ b/main/audio.h @@ -11,7 +11,6 @@ struct willow_audio_response { typedef enum { MSG_STOP, MSG_START, - MSG_START_LOCAL, } q_msg; extern audio_rec_handle_t hdl_ar; diff --git a/main/config.c b/main/config.c index 9f884e0a..0579ac74 100644 --- a/main/config.c +++ b/main/config.c @@ -13,7 +13,6 @@ #include "audio.h" #include "config.h" #include "display.h" -#include "endpoint/hass.h" #include "shared.h" #include "slvgl.h" #include "system.h" @@ -133,7 +132,6 @@ void config_write(const char *data) { deinit_was(); deinit_audio(); - deinit_hass(); FILE *f = fopen(CONFIG_PATH, "w"); if (f == NULL) { diff --git a/main/endpoint/hass.c b/main/endpoint/hass.c deleted file mode 100644 index 3bb118c9..00000000 --- a/main/endpoint/hass.c +++ /dev/null @@ -1,488 +0,0 @@ -#include "audio_hal.h" -#include "audio_thread.h" -#include "cJSON.h" -#include "esp_http_client.h" -#include "esp_log.h" -#include "esp_lvgl_port.h" -#include "esp_timer.h" -#include "esp_transport_ws.h" -#include "esp_websocket_client.h" -#include "lvgl.h" -#include "sdkconfig.h" - -#include "../http.h" -#include "audio.h" -#include "config.h" -#include "shared.h" -#include "slvgl.h" -#include "timer.h" - -#define DEFAULT_HOST "homeassistant.local" -#define DEFAULT_PORT 8123 -#define DEFAULT_TLS false -#define DEFAULT_TOKEN "your_ha_token" - -#define HASS_URI_COMPONENTS "/api/components" -#define HASS_URI_CONVERSATION_PROCESS "/api/conversation/process" -#define HASS_URI_WEBSOCKET "/api/websocket" -#define STR_SCHEME_LEN 6 -#define URL_CLEN (8 + 1 + 5 + 1) // https:// + : + $PORT + NULL terminator - -struct hass_intent_response { - bool has_speech; - bool ok; - char *speech; -}; - -static struct hass_intent_response hir; - -static bool has_assist_pipeline = false; -static const char *TAG = "WILLOW/HASS"; -static esp_websocket_client_handle_t hdl_wc = NULL; - -static void init_hass_ws_client(void); - -static void cb_ws_event(const void *arg_evh, const esp_event_base_t *base_ev, const int id_ev, const void *ev_data) -{ - switch (id_ev) { - case WEBSOCKET_EVENT_CONNECTED: - ESP_LOGI(TAG, "WebSocket connected"); - break; - case WEBSOCKET_EVENT_DATA: - if (ev_data == NULL) { - ESP_LOGW(TAG, "WEBSOCKET_EVENT_DATA: ev_data == NULL"); - break; - } - esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)ev_data; - - if (data->op_code == WS_TRANSPORT_OPCODES_TEXT) { - char *json = NULL; - - if (data->data_ptr == NULL) { - ESP_LOGW(TAG, "WEBSOCKET_EVENT_DATA: data->data_ptr == NULL"); - break; - } - if (data->data_len <= 0) { - ESP_LOGW(TAG, "WEBSOCKET_EVENT_DATA: data->data_len <= 0"); - break; - } - char *resp = strndup((char *)data->data_ptr, data->data_len); - - ESP_LOGD(TAG, "received text data on WebSocket: %s", resp); - - cJSON *cjson = cJSON_Parse(resp); - if (!cJSON_IsObject(cjson)) { - goto cleanup; - } - - cJSON *type = cJSON_GetObjectItemCaseSensitive(cjson, "type"); - if (!cJSON_IsString(type) || type->valuestring == NULL) { - goto cleanup; - } - - if (strcmp(type->valuestring, "auth_required") == 0) { - char *hass_token = config_get_char("hass_token", DEFAULT_TOKEN); - int len_auth = strlen(hass_token) + 34; - char *auth = calloc(len_auth, sizeof(char)); - snprintf(auth, len_auth, "{\"type\":\"auth\",\"access_token\":\"%s\"}", hass_token); - free(hass_token); - - // we must not send the terminating null byte - int ret = esp_websocket_client_send_text(hdl_wc, auth, len_auth - 1, 2000 / portTICK_PERIOD_MS); - free(auth); - if (ret < 0) { - ESP_LOGE(TAG, "failed to authenticate WebSocket client"); - } - goto cleanup; - } - - cJSON *event = cJSON_GetObjectItemCaseSensitive(cjson, "event"); - if (!cJSON_IsObject(event)) { - goto cleanup; - } - - cJSON *event_type = cJSON_GetObjectItemCaseSensitive(event, "type"); - if (!cJSON_IsString(event_type) || event_type->valuestring == NULL) { - goto cleanup; - } - - if (strcmp(event_type->valuestring, "run-end") == 0) { - goto end; - } - - if (strcmp(event_type->valuestring, "intent-end") != 0) { - goto cleanup; - } - - cJSON *event_data = cJSON_GetObjectItemCaseSensitive(event, "data"); - if (!cJSON_IsObject(event_data)) { - goto cleanup; - } - - cJSON *intent_output = cJSON_GetObjectItemCaseSensitive(event_data, "intent_output"); - if (!cJSON_IsObject(intent_output)) { - goto cleanup; - } - - cJSON *response = cJSON_GetObjectItemCaseSensitive(intent_output, "response"); - if (!cJSON_IsObject(response)) { - goto cleanup; - } - - cJSON *speech = cJSON_GetObjectItemCaseSensitive(response, "speech"); - if (!cJSON_IsObject(speech)) { - goto no_speech; - } - - cJSON *plain = cJSON_GetObjectItemCaseSensitive(speech, "plain"); - if (!cJSON_IsObject(plain)) { - goto no_speech; - } - - cJSON *speech2 = cJSON_GetObjectItemCaseSensitive(plain, "speech"); - if (cJSON_IsString(speech2) && speech2->valuestring != NULL && strlen(speech2->valuestring) > 0) { - hir.has_speech = true; - hir.speech = calloc(strlen(speech2->valuestring) + 1, sizeof(char)); - snprintf(hir.speech, strlen(speech2->valuestring) + 1, "%s", speech2->valuestring); - } - -no_speech:; - cJSON *response_type = cJSON_GetObjectItemCaseSensitive(response, "response_type"); - if (cJSON_IsString(response_type) && response_type->valuestring != NULL) { - ESP_LOGI(TAG, "home assistant response_type: %s", response_type->valuestring); - if (strcmp(response_type->valuestring, "error") == 0) { - hir.ok = false; - } else { - hir.ok = true; - } - goto cleanup; - } - -end: - json = cJSON_Print(cjson); - ESP_LOGI(TAG, "received run-end event on WebSocket: %s", json); - cJSON_free(json); - - if (hir.has_speech) { - hir.ok ? war.fn_ok(hir.speech) : war.fn_err(hir.speech); - } else { - hir.ok ? war.fn_ok("Success") : war.fn_err("Error"); - } - - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(lbl_ln5, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_text_align(lbl_ln4, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_set_style_text_align(lbl_ln5, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_remove_event_cb(lbl_ln4, cb_btn_cancel); - if (hir.has_speech) { - lv_label_set_text_static(lbl_ln4, "Response:"); - lv_label_set_text(lbl_ln5, hir.speech); - } else { - lv_label_set_text_static(lbl_ln4, "Command status:"); - lv_label_set_text(lbl_ln5, hir.ok ? "Success!" : "Error"); - } - lvgl_port_unlock(); - } - - if (hir.has_speech) { - free(hir.speech); - } - - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); - -cleanup: - cJSON_Delete(cjson); - free(resp); - } - break; - case WEBSOCKET_EVENT_DISCONNECTED: - ESP_LOGI(TAG, "WebSocket disconnected"); - break; - case WEBSOCKET_EVENT_CLOSED: - ESP_LOGI(TAG, "WebSocket closed"); - init_hass_ws_client(); - break; - default: - ESP_LOGI(TAG, "WS event ID: %d", id_ev); - break; - } -} - -static void hass_get_url(char **url, const char *path, const bool ws) -{ - char *hass_host; - char scheme[STR_SCHEME_LEN]; - int len_url = 0; - - if (config_get_bool("hass_tls", DEFAULT_TLS)) { - strncpy(scheme, ws ? "wss" : "https", STR_SCHEME_LEN); - } else { - strncpy(scheme, ws ? "ws" : "http", STR_SCHEME_LEN); - } - - hass_host = config_get_char("hass_host", DEFAULT_HOST); - len_url = URL_CLEN + strlen(hass_host) + strlen(path); - if (path != NULL) { - len_url += strlen(path); - } - *url = calloc(len_url, sizeof(char)); - snprintf(*url, len_url, "%s://%s:%d%s", scheme, hass_host, config_get_int("hass_port", DEFAULT_PORT), - path ? path : ""); - free(hass_host); - - ESP_LOGI(TAG, "HASS URL: %s", *url); -} - -static void init_hass_ws_client(void) -{ - char *url = NULL; - hass_get_url(&url, HASS_URI_WEBSOCKET, true); - - const esp_websocket_client_config_t cfg_wc = { - .buffer_size = 16384, - .path = HASS_URI_WEBSOCKET, - .task_stack = 6 * 1024, // default 4 * 1024 - .uri = url, - .user_agent = WILLOW_USER_AGENT, - }; - - hdl_wc = esp_websocket_client_init(&cfg_wc); - free(url); - - esp_websocket_register_events(hdl_wc, WEBSOCKET_EVENT_ANY, (esp_event_handler_t)cb_ws_event, NULL); - - esp_err_t err = esp_websocket_client_start(hdl_wc); - if (err != ESP_OK) { - ESP_LOGE(TAG, "failed to start WebSocket client: %s", esp_err_to_name(err)); - } -} - -static esp_err_t hass_set_http_auth(const esp_http_client_handle_t hdl_hc) -{ - char *hass_token = config_get_char("hass_token", DEFAULT_TOKEN); - char *hdr_auth = calloc(8 + strlen(hass_token), sizeof(char)); - snprintf(hdr_auth, 8 + strlen(hass_token), "Bearer %s", hass_token); - free(hass_token); - esp_err_t ret = esp_http_client_set_header(hdl_hc, "Authorization", hdr_auth); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to set authorization header: %s", esp_err_to_name(ret)); - } - free(hdr_auth); - return ret; -} - -static void hass_check_assist_pipeline(void) -{ - char *body = NULL; - char *url = NULL; - esp_err_t ret; - int http_status; - - esp_http_client_handle_t hdl_hc = init_http_client(); - hass_set_http_auth(hdl_hc); - - hass_get_url(&url, HASS_URI_COMPONENTS, false); - - ret = http_get(hdl_hc, url, &body, &http_status); - - if (ret != ESP_OK || http_status != 200) { - goto http_error; - } - - cJSON *cjson = cJSON_Parse(body); - if (cJSON_IsArray(cjson)) { - cJSON *component = NULL; - cJSON_ArrayForEach(component, cjson) - { - if (cJSON_IsString(component) && component->valuestring != NULL) { - if (strcmp(component->valuestring, "assist_pipeline") == 0) { - ESP_LOGI(TAG, "Home Assistant has Assist Pipeline support"); - has_assist_pipeline = true; - break; - } - } - } - } - cJSON_Delete(cjson); - -http_error: - free(body); - free(url); -} - -static void hass_post(const char *data) -{ - bool ok = false; - char *body = NULL; - char *json = NULL; - char *url = NULL; - esp_err_t ret; - int http_status; - - esp_http_client_handle_t hdl_hc = init_http_client(); - hass_set_http_auth(hdl_hc); - - hass_get_url(&url, HASS_URI_CONVERSATION_PROCESS, false); - - ESP_LOGI(TAG, "sending '%s' to Home Assistant API on '%s'", data, url); - - ret = http_post(hdl_hc, url, "application/json", data, &body, &http_status); - if (ret != ESP_OK || http_status != 200) { - ESP_LOGE(TAG, "hass_post: failed to contact Home Assistant: HTTP %d", http_status); - war.fn_err("error"); - goto http_error; - } - - cJSON *cjson = cJSON_Parse(body); - cJSON *response = cJSON_GetObjectItemCaseSensitive(cjson, "response"); - if (cJSON_IsObject(response)) { - cJSON *response_type = cJSON_GetObjectItemCaseSensitive(response, "response_type"); - if (cJSON_IsString(response_type) && response_type->valuestring != NULL) { - ESP_LOGI(TAG, "home assistant response_type: %s", response_type->valuestring); - if (!strcmp(response_type->valuestring, "error")) { - war.fn_err("error"); - } else { - ok = true; - war.fn_ok("ok"); - } - } - } - json = cJSON_Print(cjson); - cJSON_Delete(cjson); - if (json != NULL) { - ESP_LOGI(TAG, "HTTP POST response body:\n%s", json); - cJSON_free(json); - } - -http_error: - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(lbl_ln5, LV_OBJ_FLAG_HIDDEN); - lv_obj_remove_event_cb(lbl_ln4, cb_btn_cancel); - if (http_status == 200) { - lv_label_set_text_static(lbl_ln4, "Command status:"); - lv_label_set_text(lbl_ln5, ok ? "Success!" : "No Matching HA Intent"); - } else { - lv_label_set_text_static(lbl_ln4, "Error contacting HASS:"); - lv_label_set_text_fmt(lbl_ln5, "HTTP %d", http_status); - } - - lvgl_port_unlock(); - } - - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); - free(body); - - free(url); -} - -static void hass_send_ws(const char *data) -{ - int ret; - - if (!esp_websocket_client_is_connected(hdl_wc)) { - esp_websocket_client_destroy(hdl_wc); - init_hass_ws_client(); - } - - cJSON *cjson = cJSON_Parse(data); - cJSON *text = cJSON_GetObjectItemCaseSensitive(cjson, "text"); - cJSON *text_ = NULL; - - cJSON *ws_input = cJSON_CreateObject(); - if (ws_input == NULL) { - ESP_LOGE(TAG, "failed to create ws_input JSON object"); - } - - if (cJSON_IsString(text) && text->valuestring != NULL) { - cJSON_AddItemToObjectCS(ws_input, "text", text); - } else { - text_ = cJSON_CreateStringReference(data); - cJSON_AddItemToObjectCS(ws_input, "text", text_); - } - - cJSON *ws_data = cJSON_CreateObject(); - if (ws_data == NULL) { - ESP_LOGE(TAG, "failed to create ws_data JSON object"); - } - - // avoid {"id":123,"type":"result","success":false,"error":{"code":"id_reuse","message":"Identifier values have to - // increase."}} - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - - hir.has_speech = false; - hir.ok = false; - - cJSON *end_stage = cJSON_CreateStringReference("intent"); - cJSON *id = cJSON_CreateNumber(tv_now.tv_sec); - cJSON *start_stage = cJSON_CreateStringReference("intent"); - cJSON *type = cJSON_CreateStringReference("assist_pipeline/run"); - - cJSON_AddItemToObjectCS(ws_data, "end_stage", end_stage); - cJSON_AddItemToObjectCS(ws_data, "id", id); - cJSON_AddItemToObjectCS(ws_data, "input", ws_input); - cJSON_AddItemToObjectCS(ws_data, "start_stage", start_stage); - cJSON_AddItemToObjectCS(ws_data, "type", type); - - char *string = cJSON_Print(ws_data); - - cJSON_free(end_stage); - cJSON_free(id); - cJSON_free(start_stage); - cJSON_free(type); - cJSON_free(ws_data); - cJSON_free(ws_input); - - if (text_ != NULL) { - cJSON_free(text_); - } - - ESP_LOGI(TAG, "sending command to Home Assistant via WebSocket: %s", string); - - ret = esp_websocket_client_send_text(hdl_wc, string, strlen(string), 2000 / portTICK_PERIOD_MS); - cJSON_free(string); - if (ret < 0) { - ESP_LOGE(TAG, "failed to send command via WebSocket client"); - } - cJSON_Delete(cjson); -} - -void hass_send(const char *data) -{ - if (has_assist_pipeline) { - hass_send_ws(data); - } else { - hass_post(data); - } -} - -void init_hass(void) -{ - hass_check_assist_pipeline(); - if (has_assist_pipeline) { - init_hass_ws_client(); - } -} - -void hass_deinit_task(void *data) -{ - ESP_LOGI(TAG, "stopping WebSocket client"); - esp_err_t ret = esp_websocket_client_destroy(hdl_wc); - - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to stop WebSocket client: %s", esp_err_to_name(ret)); - } - vTaskDelete(NULL); -} - -void deinit_hass(void) -{ - if (hdl_wc == NULL) { - return; - } - // needs to be done in a task to avoid this error: - // WEBSOCKET_CLIENT: Client cannot be stopped from websocket task - xTaskCreate(&hass_deinit_task, "hass_deinit_task", 4096, NULL, 5, NULL); -} diff --git a/main/endpoint/hass.h b/main/endpoint/hass.h deleted file mode 100644 index debb2e24..00000000 --- a/main/endpoint/hass.h +++ /dev/null @@ -1,3 +0,0 @@ -void deinit_hass(void); -void hass_send(const char *data); -void init_hass(void); \ No newline at end of file diff --git a/main/endpoint/openhab.c b/main/endpoint/openhab.c deleted file mode 100644 index 1fd30291..00000000 --- a/main/endpoint/openhab.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "audio_hal.h" -#include "audio_thread.h" -#include "cJSON.h" -#include "esp_http_client.h" -#include "esp_log.h" -#include "esp_lvgl_port.h" -#include "esp_timer.h" - -#include "../http.h" -#include "audio.h" -#include "config.h" -#include "shared.h" -#include "slvgl.h" -#include "timer.h" - -#define DEFAULT_TOKEN "http://your_openhab_url" -#define DEFAULT_URL "your_openhab_token" - -#define OH_URI_INTERPRETERS "/rest/voice/interpreters" - -static const char *TAG = "WILLOW/OPENHAB"; - -void openhab_send(const char *data) -{ - bool ok = false; - char *body = NULL, *url = NULL; - esp_err_t ret; - int http_status = 0, len_url = 0; - - char *openhab_url = config_get_char("openhab_url", DEFAULT_URL); - len_url = strlen(openhab_url) + strlen(OH_URI_INTERPRETERS) + 1; - url = calloc(sizeof(char), len_url); - snprintf(url, len_url, "%s%s", openhab_url, OH_URI_INTERPRETERS); - free(openhab_url); - - cJSON *cjson = cJSON_Parse(data); - if (!cJSON_IsObject(cjson)) { - goto end; - } - cJSON *text = cJSON_GetObjectItemCaseSensitive(cjson, "text"); - if (!cJSON_IsString(text) && text->valuestring != NULL) { - goto end; - } - - esp_http_client_handle_t hdl_hc = init_http_client(); - char *openhab_token = config_get_char("openhab_token", DEFAULT_TOKEN); - ret = http_set_basic_auth(hdl_hc, openhab_token, ""); - free(openhab_token); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to enable HTTP Basic Authentication: %s", esp_err_to_name(ret)); - } - - ESP_LOGI(TAG, "sending '%s' to openHAB REST API on '%s'", text->valuestring, url); - - ret = http_post(hdl_hc, url, "text/plain", text->valuestring, &body, &http_status); - cJSON_Delete(cjson); - if (ret == ESP_OK) { - if (http_status >= 200 && http_status <= 299) { - ok = true; - } - } else { - ESP_LOGE(TAG, "failed to read HTTP POST response from openHAB"); - } - -end: - free(url); - if (ok) { - war.fn_ok("Success"); - } else { - war.fn_err("Error"); - } - - if (body != NULL && strlen(body) > 1) { - ESP_LOGI(TAG, "REST response: %s", body); - } - - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(lbl_ln5, LV_OBJ_FLAG_HIDDEN); - lv_obj_remove_event_cb(lbl_ln4, cb_btn_cancel); - lv_label_set_text_static(lbl_ln4, "Command status:"); - if (body != NULL && strlen(body) > 1) { - lv_label_set_text(lbl_ln5, body); - } else { - lv_label_set_text(lbl_ln5, ok ? "Success" : "Error"); - } - lvgl_port_unlock(); - } - - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); - - free(body); -} diff --git a/main/endpoint/openhab.h b/main/endpoint/openhab.h deleted file mode 100644 index bfa2370b..00000000 --- a/main/endpoint/openhab.h +++ /dev/null @@ -1 +0,0 @@ -void openhab_send(const char *data); diff --git a/main/endpoint/rest.c b/main/endpoint/rest.c deleted file mode 100644 index d2b142d0..00000000 --- a/main/endpoint/rest.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "audio_hal.h" -#include "audio_thread.h" -#include "esp_http_client.h" -#include "esp_log.h" -#include "esp_lvgl_port.h" -#include "esp_timer.h" -#include "lvgl.h" - -#include "audio.h" -#include "config.h" -#include "http.h" -#include "shared.h" -#include "slvgl.h" -#include "timer.h" - -#define DEFAULT_AUTH_HEADER "" -#define DEFAULT_AUTH_PASS "" -#define DEFAULT_AUTH_TYPE "None" -#define DEFAULT_AUTH_USER "" -#define DEFAULT_URL "http://your_rest_url" - -static const char *TAG = "WILLOW/REST"; - -void rest_send(const char *data) -{ - bool ok = false; - char *auth_type = NULL, *body = NULL, *pass = NULL, *url = NULL, *user = NULL; - esp_err_t ret; - int http_status; - - esp_http_client_handle_t hdl_hc = init_http_client(); - - auth_type = config_get_char("rest_auth_type", DEFAULT_AUTH_TYPE); - if (strcmp(auth_type, "Header") == 0) { - char *auth_header = config_get_char("rest_auth_header", DEFAULT_AUTH_HEADER); - ret = esp_http_client_set_header(hdl_hc, "Authorization", auth_header); - free(auth_header); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to set authorization header: %s", esp_err_to_name(ret)); - } - } else if (strcmp(auth_type, "Basic") == 0) { - pass = config_get_char("rest_auth_pass", DEFAULT_AUTH_PASS); - user = config_get_char("rest_auth_user", DEFAULT_AUTH_USER); - ret = http_set_basic_auth(hdl_hc, user, pass); - free(pass); - free(user); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to enable HTTP Basic Authentication: %s", esp_err_to_name(ret)); - } - } - free(auth_type); - - url = config_get_char("rest_url", DEFAULT_URL); - ret = http_post(hdl_hc, url, "application/json", data, &body, &http_status); - free(url); - if (ret == ESP_OK) { - if (http_status >= 200 && http_status <= 299) { - ok = true; - } - } else { - ESP_LOGE(TAG, "failed to read HTTP POST response"); - } - - if (ok) { - if (body != NULL && strlen(body) > 1) { - ESP_LOGI(TAG, "REST response: %s", body); - war.fn_ok(body); - } else { - ESP_LOGI(TAG, "REST successful"); - war.fn_ok("Success"); - } - } else { - ESP_LOGI(TAG, "REST failed"); - war.fn_err("Error"); - } - - if (lvgl_port_lock(lvgl_lock_timeout)) { - lv_obj_clear_flag(lbl_ln4, LV_OBJ_FLAG_HIDDEN); - lv_obj_clear_flag(lbl_ln5, LV_OBJ_FLAG_HIDDEN); - lv_obj_set_style_text_align(lbl_ln4, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_set_style_text_align(lbl_ln5, LV_TEXT_ALIGN_LEFT, 0); - lv_obj_remove_event_cb(lbl_ln4, cb_btn_cancel); - if (body != NULL && strlen(body) > 1) { - lv_label_set_text_static(lbl_ln4, "Response:"); - lv_label_set_text(lbl_ln5, body); - } else { - lv_label_set_text_static(lbl_ln4, "Command status:"); - lv_label_set_text(lbl_ln5, ok ? "Success" : "Error"); - } - lvgl_port_unlock(); - } - - reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false); - - free(body); -} diff --git a/main/endpoint/rest.h b/main/endpoint/rest.h deleted file mode 100644 index 189c5e04..00000000 --- a/main/endpoint/rest.h +++ /dev/null @@ -1 +0,0 @@ -void rest_send(const char *data); diff --git a/main/http.c b/main/http.c index e257a7f5..4c32502e 100644 --- a/main/http.c +++ b/main/http.c @@ -1,7 +1,4 @@ #include "esp_http_client.h" -#include "esp_log.h" - -static const char *TAG = "WILLOW/HTTP"; esp_http_client_handle_t init_http_client(void) { @@ -13,73 +10,3 @@ esp_http_client_handle_t init_http_client(void) return esp_http_client_init(&cfg_hc); } - -static esp_err_t http_do(const esp_http_client_handle_t hdl_hc, const esp_http_client_method_t method, const char *url, - const char *ctype, const char *data, char **body, int *http_status) -{ - esp_err_t ret; - int n; - - esp_http_client_set_url(hdl_hc, url); - esp_http_client_set_method(hdl_hc, method); - if (ctype != NULL) { - esp_http_client_set_header(hdl_hc, "Content-Type", ctype); - } - ret = esp_http_client_open(hdl_hc, method == HTTP_METHOD_POST ? strlen(data) : 0); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to open HTTP connection: %s", esp_err_to_name(ret)); - return ret; - } - if (method == HTTP_METHOD_POST) { - ESP_LOGV(TAG, "sending '%s' to '%s'", data, url); - n = esp_http_client_write(hdl_hc, data, strlen(data)); - if (n < 0) { - ESP_LOGE(TAG, "failed to POST HTTP data"); - return ESP_FAIL; - } - } - n = esp_http_client_fetch_headers(hdl_hc); - if (n < 0) { - ESP_LOGE(TAG, "failed to get HTTP headers"); - return ESP_FAIL; - } - *body = calloc(n + 1, sizeof(char)); - n = esp_http_client_read_response(hdl_hc, *body, n); - if (n >= 0) { - *http_status = esp_http_client_get_status_code(hdl_hc); - ESP_LOGI(TAG, "HTTP status='%d' content_length='%llu'", *http_status, - esp_http_client_get_content_length(hdl_hc)); - } - esp_http_client_cleanup(hdl_hc); - - return ret; -} - -esp_err_t http_get(const esp_http_client_handle_t hdl_hc, const char *url, char **body, int *http_status) -{ - return http_do(hdl_hc, HTTP_METHOD_GET, url, NULL, NULL, body, http_status); -} - -esp_err_t http_post(const esp_http_client_handle_t hdl_hc, const char *url, const char *ctype, const char *data, - char **body, int *http_status) -{ - return http_do(hdl_hc, HTTP_METHOD_POST, url, ctype, data, body, http_status); -} - -esp_err_t http_set_basic_auth(const esp_http_client_handle_t hdl_hc, const char *username, const char *password) -{ - esp_err_t ret = ESP_OK; - ret = esp_http_client_set_authtype(hdl_hc, HTTP_AUTH_TYPE_BASIC); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to enable HTTP Basic Authentication: %s", esp_err_to_name(ret)); - } - ret = esp_http_client_set_username(hdl_hc, username); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to set HTTP username: %s", esp_err_to_name(ret)); - } - ret = esp_http_client_set_password(hdl_hc, password); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to set HTTP password: %s", esp_err_to_name(ret)); - } - return ret; -} diff --git a/main/http.h b/main/http.h index f7040e50..d01e54e4 100644 --- a/main/http.h +++ b/main/http.h @@ -1,5 +1 @@ esp_http_client_handle_t init_http_client(void); -esp_err_t http_get(const esp_http_client_handle_t hdl_hc, const char *url, char **body, int *http_status); -esp_err_t http_post(const esp_http_client_handle_t hdl_hc, const char *url, const char *ctype, const char *data, - char **body, int *http_status); -esp_err_t http_set_basic_auth(const esp_http_client_handle_t hdl_hc, const char *username, const char *password); \ No newline at end of file diff --git a/main/main.c b/main/main.c index 3713e0d8..351d2622 100644 --- a/main/main.c +++ b/main/main.c @@ -22,8 +22,6 @@ #include "ui.h" #include "was.h" -#include "endpoint/hass.h" - #ifdef CONFIG_MBEDTLS_SSL_PROTO_TLS1_3 #include "psa/crypto.h" #endif @@ -164,14 +162,6 @@ void app_main(void) vTaskDelay(portMAX_DELAY); } - bool was_mode = config_get_bool("was_mode", DEFAULT_WAS_MODE); - if (!was_mode) { - char *command_endpoint = config_get_char("command_endpoint", DEFAULT_COMMAND_ENDPOINT); - if (strcmp(command_endpoint, "Home Assistant") == 0) { - init_hass(); - } - free(command_endpoint); - } init_buttons(); init_input_key_service(); init_audio(); diff --git a/main/ota.c b/main/ota.c index 695e2d6d..ec15ae85 100644 --- a/main/ota.c +++ b/main/ota.c @@ -12,7 +12,6 @@ #include "audio.h" #include "config.h" #include "display.h" -#include "endpoint/hass.h" #include "http.h" #include "shared.h" #include "slvgl.h" @@ -184,7 +183,6 @@ void ota_start(char *url) display_set_backlight(true, false); deinit_audio(); - deinit_hass(); deinit_was(); vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/main/shared.h b/main/shared.h index 564ea6f5..97c90eae 100644 --- a/main/shared.h +++ b/main/shared.h @@ -1,4 +1 @@ -#define DEFAULT_COMMAND_ENDPOINT "Home Assistant" -#define DEFAULT_MIC_GAIN 14 -#define DEFAULT_SPEECH_REC_MODE "WIS" -#define DEFAULT_WAS_MODE false +#define DEFAULT_MIC_GAIN 14 diff --git a/main/ui.c b/main/ui.c index 65ea9b10..b7872009 100644 --- a/main/ui.c +++ b/main/ui.c @@ -2,8 +2,6 @@ #include "esp_log.h" #include "esp_lvgl_port.h" -#include "config.h" -#include "shared.h" #include "slvgl.h" static const char *TAG = "WILLOW/UI"; @@ -13,8 +11,6 @@ void init_ui(void) if (ld == NULL) { ESP_LOGE(TAG, "lv_disp_t ld is NULL!!!!"); } else { - char *speech_rec_mode = config_get_char("speech_rec_mode", DEFAULT_SPEECH_REC_MODE); - if (lvgl_port_lock(lvgl_lock_timeout)) { lv_obj_t *scr_act = lv_disp_get_scr_act(ld); lv_obj_t *lbl_hdr = lv_label_create(scr_act); @@ -89,20 +85,11 @@ void init_ui(void) lv_obj_set_width(lbl_ln4, 300); lv_obj_set_width(lbl_ln5, 300); - if (strcmp(speech_rec_mode, "Multinet") == 0) { -#if defined(WILLOW_SUPPORT_MULTINET) - lv_label_set_text_static(lbl_ln3, "Starting up (local)..."); -#else - lv_label_set_text_static(lbl_ln3, "Multinet Not Supported"); -#endif - } else if (strcmp(speech_rec_mode, "WIS") == 0) { - lv_label_set_text_static(lbl_ln3, "Starting up (server)..."); - } + lv_label_set_text_static(lbl_ln3, "Starting up (server)..."); lv_obj_clear_flag(lbl_ln3, LV_OBJ_FLAG_HIDDEN); lvgl_port_unlock(); } - free(speech_rec_mode); } } diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 51196291..c6f35805 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -127,8 +127,7 @@ CONFIG_SPIRAM_SPEED_80M=y CONFIG_SPI_MASTER_IN_IRAM=y CONFIG_SPI_SLAVE_IN_IRAM=y CONFIG_SR_MN_CN_NONE=y -CONFIG_SR_MN_EN_MULTINET6_QUANT=y -# CONFIG_SR_MN_EN_NONE is not set +CONFIG_SR_MN_EN_NONE=y CONFIG_SR_WN_LOAD_MULIT_WORD=y CONFIG_SR_WN_WN9_ALEXA_MULTI=y CONFIG_SR_WN_WN9_HIESP_MULTI=y diff --git a/speech_commands/.gitignore b/speech_commands/.gitignore deleted file mode 100644 index 2211df63..00000000 --- a/speech_commands/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.txt diff --git a/speech_commands/generate_commands.py b/speech_commands/generate_commands.py deleted file mode 100644 index 20b63944..00000000 --- a/speech_commands/generate_commands.py +++ /dev/null @@ -1,111 +0,0 @@ -# This script is GROSS - -from num2words import num2words -from requests import get -import re -import sys -import os -import string - -max_commands = 400 - -entity_types = ['light.', 'switch.'] -entity_types_str = str(entity_types) - -tag = "MULTINET: Generate speech commands:" - -willow_path = os.getenv('WILLOW_PATH') - -willow_config = f'{willow_path}/sdkconfig' - -file = open(willow_config, 'r') -lines = file.readlines() -for line in lines: - if 'CONFIG_WILLOW_WAS_URL=' in line: - was_url = line.replace('CONFIG_WILLOW_WAS_URL=', '') - was_url = was_url.strip('\n') - was_url = was_url.replace('\"', '') - -file.close() - -# sdkconfig has WebSocket URL -was_url = re.sub("^ws", "http", was_url) -was_url = re.sub("/ws$", "/api/config", was_url) -was_url = f"{was_url}?type=multinet" - -try: - response = get(was_url) -except Exception as e: - print(f'Could not get Multinet commands from WAS: {e}') - sys.exit(0) - -commands_json = response.json() - -# Start index -index = 0 - -commands = [] -for command in commands_json: - index = index + 1 - commands.append(f"{index} {command}") - -if index >= max_commands: - print(f'WARNING: Multinet supports a maximum of {max_commands} commands and you have {index}') - print(f'WARNING: YOU WILL NEED TO TRIM YOUR COMMANDS MANUALLY') - sys.exit(1) - -multinet_command_file = open(f'{willow_path}/speech_commands/commands_en.txt', 'w') - -for command in commands: - multinet_command_file.write(f'{command}\n') - -multinet_command_file.close() - -multinet_header = open(f'{willow_path}/main/generated_cmd_multinet.h', 'w') - -multinet_header.write(f'#include \n\n') - -multinet_header.write('char *cmd_multinet[] = {\n') - -# Different indexes -multinet_header.write(f'\t\"DUMMY\",\n') - -for command in commands_json: - multinet_header.write(f'\t\"{command}.\",\n') - -multinet_header.write('};\n\n') -multinet_header.write(f'int cmd_multinet_max = {index};\n') - -fn = """ -char *lookup_cmd_multinet(int id) { - if (id > cmd_multinet_max) { - return "INVALID"; - } - - return cmd_multinet[id]; -} - -size_t get_cmd_multinet_size(void) -{ - int i = 0; - size_t sz = 0; - - while(true) { - if (strcmp(lookup_cmd_multinet(i), "INVALID") == 0) { - break; - } - - // strlen excludes terminating null byte - sz += strlen(lookup_cmd_multinet(i)) + 1; - i++; - } - - return sz; -} -""" - -multinet_header.write(fn); - -multinet_header.close() - -print(f'{tag} Success!') diff --git a/utils.sh b/utils.sh index a2236add..290deb40 100755 --- a/utils.sh +++ b/utils.sh @@ -117,17 +117,6 @@ check_deps() { fi } -generate_speech_commands() { - rm -rf build/srmodels - /usr/bin/python3 speech_commands/generate_commands.py - - if [ -r "$WILLOW_PATH"/speech_commands/commands_en.txt ]; then - echo "Linking custom speech commands" - ln -sf "$WILLOW_PATH"/speech_commands/commands_en.txt \ - "$WILLOW_PATH"/managed_components/esp-sr/model/multinet_model/fst/commands_en.txt - fi -} - generate_nvs() { SSID=$(grep CONFIG_WIFI_SSID sdkconfig | cut -d'=' -f2 | tr -d '"') PASSWORD=$(grep CONFIG_WIFI_PASSWORD sdkconfig | cut -d'=' -f2 | tr -d '"') @@ -217,7 +206,6 @@ fullclean) build) check_container check_deps - [ "$MULTINET" ] && generate_speech_commands if [ $2 ]; then echo "Adding timestamp to dev build" TS=$(date '+%d-%m-%Y_%H:%M:%S')