vad = switch_vad_init(imp.samples_per_second, imp.number_of_channels);
switch_assert(vad);
- switch_vad_set_mode(vad, mode);
- if ((var = switch_channel_get_variable(channel, "vad_hangover_len"))) {
+ if ((var = switch_channel_get_variable(channel, "vad_debug"))) {
tmp = atoi(var);
- if (tmp > 0) switch_vad_set_param(vad, "hangover_len", tmp);
+ if (tmp < 0) tmp = 0;
+ if (tmp > 1) tmp = 1;
+
+ switch_vad_set_param(vad, "debug", tmp);
}
- if ((var = switch_channel_get_variable(channel, "vad_thresh"))) {
+ switch_vad_set_mode(vad, mode);
+
+ if ((var = switch_channel_get_variable(channel, "vad_silence_ms"))) {
tmp = atoi(var);
- if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp);
+ if (tmp > 0) switch_vad_set_param(vad, "sicence_ms", tmp);
}
- if ((var = switch_channel_get_variable(channel, "vad_listen_hits"))) {
+ if ((var = switch_channel_get_variable(channel, "vad_thresh"))) {
tmp = atoi(var);
- if (tmp > 0) switch_vad_set_param(vad, "listen_hits", tmp);
+ if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp);
}
- if ((var = switch_channel_get_variable(channel, "vad_debug"))) {
+ if ((var = switch_channel_get_variable(channel, "vad_voice_ms"))) {
tmp = atoi(var);
- if (tmp < 0) tmp = 0;
- if (tmp > 1) tmp = 1;
-
- switch_vad_set_param(vad, "debug", tmp);
+ if (tmp > 0) switch_vad_set_param(vad, "voice_ms", tmp);
}
while (switch_channel_ready(channel)) {
vad_state = switch_vad_process(vad, frame->data, frame->datalen / 2);
if (vad_state == SWITCH_VAD_STATE_START_TALKING) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "START TALKING\n");
switch_core_session_write_frame(session, frame, SWITCH_IO_FLAG_NONE, 0);
} else if (vad_state == SWITCH_VAD_STATE_STOP_TALKING) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STOP TALKING\n");
+ switch_vad_reset(vad);
} else if (vad_state == SWITCH_VAD_STATE_TALKING) {
switch_core_session_write_frame(session, frame, SWITCH_IO_FLAG_NONE, 0);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %s\n", switch_vad_state2str(vad_state));
+ // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %s\n", switch_vad_state2str(vad_state));
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "libfvad started, mode = %d\n", mode);
return ret;
#else
+ if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "set vad mode = %d\n", mode);
+
return 0;
#endif
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "listen_hits is deprecated, setting voice_ms to %d\n", 20 * val);
switch_vad_set_param(vad, "voice_ms", 20 * val);
}
+
+ if (vad->debug) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "set %s to %d\n", key, val);
+ }
}
SWITCH_DECLARE(void) switch_vad_reset(switch_vad_t *vad)
vad->vad_state = SWITCH_VAD_STATE_NONE;
vad->voice_samples = 0;
vad->silence_samples = 0;
+
+ if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "reset vad state\n");
}
SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t *data, unsigned int samples)
}
#endif
+ if (vad->debug > 9) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "score: %d\n", score);
+ }
+
// clear the STOP/START TALKING events
if (vad->vad_state == SWITCH_VAD_STATE_STOP_TALKING) {
vad->vad_state = SWITCH_VAD_STATE_NONE;
// check for state transitions
if (vad->vad_state == SWITCH_VAD_STATE_TALKING && vad->silence_samples > vad->silence_samples_thresh) {
vad->vad_state = SWITCH_VAD_STATE_STOP_TALKING;
+ if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "vad state STOP_TALKING\n");
} else if (vad->vad_state == SWITCH_VAD_STATE_NONE && vad->voice_samples > vad->voice_samples_thresh) {
vad->vad_state = SWITCH_VAD_STATE_START_TALKING;
+ if (vad->debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "vad state START_TALKING\n");
}
+ if (vad->debug > 9) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "vad state %s\n", switch_vad_state2str(vad->vad_state));
+
return vad->vad_state;
}