From 90182d13f1af30b75362e960cb2f4c906797bbfa Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Fri, 24 Oct 2025 16:36:17 +0100 Subject: [PATCH 1/3] feat: add way to handle fire_asr_events as a global var and not only as a channel var --- src/switch_ivr_async.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index ba80ea15f44..e8c0a620ae7 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -5405,7 +5405,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_init(switch_core_sessio sth->session = session; sth->ah = ah; - if ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p)) { + if (((p = switch_core_get_variable_dup("fire_asr_events")) && switch_true(p)) || + ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p))) { switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS); } @@ -5490,8 +5491,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * switch_ivr_resume_detect_speech(session); } - if ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p)) { - switch_set_flag(sth->ah, SWITCH_ASR_FLAG_FIRE_EVENTS); + if (((p = switch_core_get_variable_dup("fire_asr_events")) && switch_true(p)) || + ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p))) { + switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS); } return SWITCH_STATUS_SUCCESS; From 5bf2673474f680bc7d6531d6757d942be9ae287d Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 28 Oct 2025 20:01:30 +0000 Subject: [PATCH 2/3] feat: improvements --- src/switch_ivr_async.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index e8c0a620ae7..0fd64138cfe 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -5368,6 +5368,28 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_disable_all_grammars(sw return SWITCH_STATUS_FALSE; } +static switch_bool_t check_fire_asr_events(switch_channel_t *channel) +{ + char *core_val = NULL; + const char *chan_val = NULL; + switch_bool_t result = SWITCH_FALSE; + + chan_val = switch_channel_get_variable(channel, "fire_asr_events"); + if (chan_val && switch_true(chan_val)) { + return SWITCH_TRUE; + } + + core_val = switch_core_get_variable_dup("fire_asr_events"); + if (core_val) { + if (switch_true(core_val)) { + result = SWITCH_TRUE; + } + free(core_val); + } + + return result; +} + SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_init(switch_core_session_t *session, const char *mod_name, const char *dest, switch_asr_handle_t *ah) { @@ -5376,7 +5398,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_init(switch_core_sessio switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE; struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY); switch_codec_implementation_t read_impl = { 0 }; - const char *p; char key[512] = ""; if (sth) { @@ -5405,8 +5426,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_init(switch_core_sessio sth->session = session; sth->ah = ah; - if (((p = switch_core_get_variable_dup("fire_asr_events")) && switch_true(p)) || - ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p))) { + if (check_fire_asr_events(channel)) { switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS); } @@ -5461,7 +5481,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * { switch_channel_t *channel = switch_core_session_get_channel(session); struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY); - const char *p; int resume = 0; @@ -5491,8 +5510,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * switch_ivr_resume_detect_speech(session); } - if (((p = switch_core_get_variable_dup("fire_asr_events")) && switch_true(p)) || - ((p = switch_channel_get_variable(channel, "fire_asr_events")) && switch_true(p))) { + if (check_fire_asr_events(channel)) { switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS); } From a0a94ced1c4c32768b250c36edc752a16f6d587f Mon Sep 17 00:00:00 2001 From: Gustavo Almeida Date: Tue, 28 Oct 2025 22:19:24 +0000 Subject: [PATCH 3/3] fix: arg set_flag --- src/switch_ivr_async.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 0fd64138cfe..e5e933b2bbb 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -5511,7 +5511,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * } if (check_fire_asr_events(channel)) { - switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS); + switch_set_flag(sth->ah, SWITCH_ASR_FLAG_FIRE_EVENTS); } return SWITCH_STATUS_SUCCESS;