void *private_info;
int64_t pos;
switch_buffer_t *audio_buffer;
+ uint32_t thresh;
+ uint32_t silence_hits;
};
/*! \brief Abstract interface to an asr module */
int len = 0;
switch_input_callback_function_t dtmf_func = NULL;
struct input_callback_state cb_state = {0};
- switch_file_handle_t fh;
+ switch_file_handle_t fh = {0};
JSFunction *function;
int32 limit = 0;
if (argc > 3) {
JS_ValueToInt32(cx, argv[3], &limit);
}
+
+ if (argc > 4) {
+ int32_t thresh;
+ JS_ValueToInt32(cx, argv[4], &thresh);
+ fh.thresh = thresh;
+ }
+
+ if (argc > 5) {
+ int32_t silence_hits;
+ JS_ValueToInt32(cx, argv[5], &silence_hits);
+ fh.silence_hits = silence_hits;
+ }
}
- memset(&fh, 0, sizeof(fh));
+
cb_state.extra = &fh;
cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
switch_ivr_record_file(jss->session, &fh, file_name, dtmf_func, bp, len, limit);
int len = 0;
switch_input_callback_function_t dtmf_func = NULL;
struct input_callback_state cb_state = {0};
- switch_file_handle_t fh;
+ switch_file_handle_t fh = {0};
JSFunction *function;
channel = switch_core_session_get_channel(jss->session);
if (argc > 4) {
int32 samps;
- uint32_t pos = 0;
JS_ValueToInt32(cx, argv[4], &samps);
- switch_core_file_seek(&fh, &pos, samps, SEEK_CUR);
+ fh.samples = samps;
}
- memset(&fh, 0, sizeof(fh));
cb_state.extra = &fh;
cb_state.ret = BOOLEAN_TO_JSVAL( JS_FALSE );
switch_ivr_play_file(jss->session, &fh, file_name, timer_name, dtmf_func, bp, len);
*str = NULL;
- if (!(buf = malloc(blocksize))) {
+ dlen = blocksize * 2;
+
+ if (!(buf = malloc(dlen))) {
return SWITCH_STATUS_MEMERR;
}
return SWITCH_STATUS_MEMERR;
}
- dlen = blocksize;
-
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n");
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "hit serialze!.\n");
for (hp = event->headers; hp; hp = hp->next) {
/*
* grab enough memory to store 3x the string (url encode takes one char and turns it into %XX)
*/
if(encode_len < ((strlen(hp->value) * 3) + 1)) {
char* tmp;
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len);
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Allocing %d was %d.\n", ((strlen(hp->value) * 3) + 1), encode_len);
/* we can use realloc for initial alloc as well, if encode_buf is zero it treats it as a malloc */
if(!(tmp = realloc(encode_buf, ((strlen(hp->value) * 3) + 1)))) {
/* oh boy, ram's gone, give back what little we grabbed and bail */
start = time(NULL);
}
+ if (fh->thresh) {
+ if (!fh->silence_hits) {
+ fh->silence_hits = 20;
+ }
+ }
+
while(switch_channel_ready(channel)) {
switch_size_t len;
switch_event_t *event;
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
+
+ if (fh->thresh) {
+ int16_t *fdata = (int16_t *) read_frame->data;
+ uint32_t samples = read_frame->datalen / sizeof(*fdata);
+ uint32_t score, count = 0, j = 0;
+ double energy = 0;
+
+ for (count = 0; count < samples; count++) {
+ energy += abs(fdata[j]);
+ j += read_codec->implementation->number_of_channels;
+ }
+
+ score = energy / samples;
+ if (score < fh->thresh) {
+ if (!--fh->silence_hits) {
+ break;
+ }
+ }
+ }
+
if (!switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
len = (switch_size_t) read_frame->datalen / 2;
switch_core_file_write(fh, read_frame->data, &len);
write_frame.data = abuf;
write_frame.buflen = sizeof(abuf);
+ if (fh->samples) {
+ uint32_t pos = 0;
+ switch_core_file_seek(fh, &pos, fh->samples, SEEK_CUR);
+ }
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_TITLE, &p) == SWITCH_STATUS_SUCCESS) {
title = (char *) switch_core_session_strdup(session, (char *)p);