-
-
Save maurice2k/cc60f8960f51ca6f43b2a109e079ce28 to your computer and use it in GitHub Desktop.
func_talkdetect patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/funcs/func_talkdetect.c b/funcs/func_talkdetect.c | |
index 5c7f41ab39..ea27d3eeee 100644 | |
--- a/funcs/func_talkdetect.c | |
+++ b/funcs/func_talkdetect.c | |
@@ -159,6 +159,7 @@ static const struct ast_datastore_info talk_detect_datastore = { | |
static int talk_detect_audiohook_cb(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction) | |
{ | |
int total_silence; | |
+ int talking; | |
int update_talking = 0; | |
struct ast_datastore *datastore; | |
struct talk_detect_params *td_params; | |
@@ -181,14 +182,16 @@ static int talk_detect_audiohook_cb(struct ast_audiohook *audiohook, struct ast_ | |
} | |
td_params = datastore->data; | |
- ast_dsp_silence(td_params->dsp, frame, &total_silence); | |
+ talking = !ast_dsp_silence(td_params->dsp, frame, &total_silence); | |
if (total_silence < td_params->dsp_silence_threshold) { | |
- if (!td_params->talking) { | |
- update_talking = 1; | |
- td_params->talking_start = ast_tvnow(); | |
+ if (talking) { | |
+ if (!td_params->talking) { | |
+ update_talking = 1; | |
+ td_params->talking_start = ast_tvnow(); | |
+ } | |
+ td_params->talking = 1; | |
} | |
- td_params->talking = 1; | |
} else { | |
if (td_params->talking) { | |
update_talking = 1; | |
@@ -202,6 +205,9 @@ static int talk_detect_audiohook_cb(struct ast_audiohook *audiohook, struct ast_ | |
if (!td_params->talking) { | |
int64_t diff_ms = ast_tvdiff_ms(ast_tvnow(), td_params->talking_start); | |
diff_ms -= td_params->dsp_silence_threshold; | |
+ if (diff_ms < 0) { | |
+ diff_ms = 0; | |
+ } | |
blob = ast_json_pack("{s: i}", "duration", diff_ms); | |
if (!blob) { | |
@@ -357,7 +363,7 @@ static int talk_detect_fn_write(struct ast_channel *chan, const char *function, | |
if (dsp_talking_threshold < 1) { | |
ast_log(AST_LOG_WARNING, "Invalid value %d for dsp_talking_threshold\n", | |
- dsp_silence_threshold); | |
+ dsp_talking_threshold); | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment