From 80816b8b63091c7117d17e673a0d58e019224a60 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 16 Nov 2023 18:02:44 +0200 Subject: [PATCH 1/2] config: allow NULL as default in config_get_char --- main/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/config.c b/main/config.c index 55d0212c..baeee5e7 100644 --- a/main/config.c +++ b/main/config.c @@ -81,7 +81,7 @@ char *config_get_char(const char *key, const char *default_value) if (val != NULL && cJSON_IsString(val) && val->valuestring != NULL) { ret = strndup(val->valuestring, strlen(val->valuestring)); } else { - ret = strndup(default_value, strlen(default_value)); + ret = default_value == NULL ? NULL : strndup(default_value, strlen(default_value)); } ESP_LOGD(TAG, "config_get_char(%s): %s", key, ret); return ret; From 0add33640559a74acb46869e467ab5b49b66e500 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 15 Nov 2023 21:50:59 +0200 Subject: [PATCH 2/2] audio: support wis_tts_url_v2 in config To have more flexibility with the new Coqui TTS backend, we're going to construct the TTS URL in WAS before sending it to Willow. We will support both the old and the new way for a while, both in Willow and WAS, so that old Willow versions will work with new WAS versions, and new Willow version will work with old WAS versions. --- main/audio.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main/audio.c b/main/audio.c index 15129122..3ecfc93d 100644 --- a/main/audio.c +++ b/main/audio.c @@ -99,14 +99,26 @@ void play_audio_ok(void *data) static void play_audio_wis_tts(void *data) { + char *url = NULL; + char *wis_tts_url = NULL; + if (data == NULL) { ESP_LOGW(TAG, "called play_audio_wis_tts with NULL data"); return; } - char *wis_tts_url = config_get_char("wis_tts_url", DEFAULT_WIS_TTS_URL); - int len_url = strlen(wis_tts_url) + strlen(WIS_URL_TTS_ARG) + strlen((char *)data) + 1; - char *url = calloc(sizeof(char), len_url); - snprintf(url, len_url, "%s%s%s", wis_tts_url, WIS_URL_TTS_ARG, (char *)data); + + wis_tts_url = config_get_char("wis_tts_url_v2", NULL); + if (wis_tts_url != NULL) { + int len_url = strlen(wis_tts_url) + strlen((char *)data) + 1; + url = calloc(sizeof(char), len_url); + snprintf(url, len_url, "%s%s", wis_tts_url, (char *)data); + } else { + wis_tts_url = config_get_char("wis_tts_url", DEFAULT_WIS_TTS_URL); + int len_url = strlen(wis_tts_url) + strlen(WIS_URL_TTS_ARG) + strlen((char *)data) + 1; + url = calloc(sizeof(char), len_url); + snprintf(url, len_url, "%s%s%s", wis_tts_url, WIS_URL_TTS_ARG, (char *)data); + } + free(wis_tts_url); gpio_set_level(get_pa_enable_gpio(), 1); ESP_LOGI(TAG, "Using WIS TTS URL '%s'", url);