41 const
char *module_name,
48 if (strchr(module_name,
':')) {
50 if ((param = strchr(buf,
':'))) {
66 ah->memory_pool =
pool;
80 ah->samplerate = rate;
81 ah->native_rate = rate;
83 status = ah->asr_interface->asr_open(ah, codec, rate, dest, flags);
96 char *param_string = NULL;
98 char *lgrammar = NULL;
110 lgrammar = strdup(grammar);
114 while (data && *data ==
' ') {
124 param_string = data + 1;
136 if (!
zstr(param_string)) {
137 char *param[256] = { 0 };
140 for (i = 0; i < argc && param[i]; ++i) {
141 char *param_pair[2] = { 0 };
142 if (
switch_separate_string(param[i],
'=', param_pair, (
sizeof(param_pair) /
sizeof(param_pair[0]))) == 2) {
148 status = ah->asr_interface->asr_load_grammar(ah, data, name);
161 status = ah->asr_interface->asr_unload_grammar(ah, name);
172 if (ah->asr_interface->asr_enable_grammar) {
173 status = ah->asr_interface->asr_enable_grammar(ah, name);
185 if (ah->asr_interface->asr_disable_grammar) {
186 status = ah->asr_interface->asr_disable_grammar(ah, name);
198 if (ah->asr_interface->asr_disable_all_grammars) {
199 status = ah->asr_interface->asr_disable_all_grammars(ah);
209 return ah->asr_interface->asr_pause(ah);
216 return ah->asr_interface->asr_resume(ah);
225 status = ah->asr_interface->asr_close(ah, flags);
244 if (ah->native_rate && ah->samplerate && ah->native_rate != ah->samplerate) {
245 if (!ah->resampler) {
254 if (ah->resampler->to_len > orig_len) {
257 ah->dbuflen = ah->resampler->to_len * 2;
258 mem = realloc(ah->dbuf, ah->dbuflen);
263 memcpy(ah->dbuf, ah->resampler->to, ah->resampler->to_len * 2);
266 memcpy(data, ah->resampler->to, ah->resampler->to_len * 2);
269 len = ah->resampler->to_len;
272 return ah->asr_interface->asr_feed(ah, data, len, flags);
281 if (ah->asr_interface->asr_feed_dtmf) {
282 status = ah->asr_interface->asr_feed_dtmf(ah, dtmf, flags);
292 return ah->asr_interface->asr_check_results(ah, flags);
299 return ah->asr_interface->asr_get_results(ah, xmlstr, flags);
306 if (ah->asr_interface->asr_get_result_headers) {
307 return ah->asr_interface->asr_get_result_headers(ah, headers, flags);
320 if (ah->asr_interface->asr_start_input_timers) {
321 status = ah->asr_interface->asr_start_input_timers(ah);
331 if (ah->asr_interface->asr_text_param) {
332 ah->asr_interface->asr_text_param(ah, param, val);
340 if (ah->asr_interface->asr_numeric_param) {
341 ah->asr_interface->asr_numeric_param(ah, param, val);
349 if (ah->asr_interface->asr_float_param) {
350 ah->asr_interface->asr_float_param(ah, param, val);
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_core_asr_start_input_timers(switch_asr_handle_t *ah)
Start input timers on an asr handle.
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#define SWITCH_CHANNEL_LOG
switch_status_t switch_core_asr_disable_all_grammars(switch_asr_handle_t *ah)
Disable all grammars from an asr handle.
void switch_core_asr_float_param(switch_asr_handle_t *ah, char *param, double val)
Set a float parameter on an asr handle.
char * switch_find_end_paren(const char *s, char open, char close)
switch_status_t switch_core_asr_get_result_headers(switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags)
Get result headers from an asr handle.
switch_status_t switch_core_asr_open(switch_asr_handle_t *ah, const char *module_name, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags, switch_memory_pool_t *pool)
Open an asr handle.
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
switch_status_t switch_core_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
Get results from an asr handle.
switch_status_t switch_core_asr_feed_dtmf(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags)
Feed DTMF to an asr handle.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
Representation of an event.
#define SWITCH_RESAMPLE_QUALITY
switch_status_t switch_core_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
Feed audio data to an asr handle.
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
switch_status_t switch_core_asr_load_grammar(switch_asr_handle_t *ah, const char *grammar, const char *name)
Load a grammar to an asr handle.
switch_status_t switch_core_asr_pause(switch_asr_handle_t *ah)
Pause detection on an asr handle.
#define UNPROTECT_INTERFACE(_it)
switch_byte_t switch_byte_t * buf
unsigned int switch_separate_string(_In_ char *buf, char delim, _Post_count_(return) char **array, unsigned int arraylen)
Separate a string into an array based on a character delimiter.
switch_status_t switch_core_asr_close(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
Close an asr handle.
void switch_core_asr_numeric_param(switch_asr_handle_t *ah, char *param, int val)
Set a numeric parameter on an asr handle.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
switch_status_t switch_core_asr_disable_grammar(switch_asr_handle_t *ah, const char *name)
Disable a grammar from an asr handle.
uint32_t switch_asr_flag_t
switch_asr_interface_t * switch_loadable_module_get_asr_interface(const char *name)
Retrieve the asr interface by it's registered name.
switch_status_t switch_core_asr_check_results(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
Check an asr handle for results.
switch_status_t
Common return values.
switch_status_t switch_core_asr_resume(switch_asr_handle_t *ah)
Resume detection on an asr handle.
#define switch_set_string(_dst, _src)
struct apr_pool_t switch_memory_pool_t
switch_status_t switch_core_asr_enable_grammar(switch_asr_handle_t *ah, const char *name)
Enable a grammar from an asr handle.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_core_asr_unload_grammar(switch_asr_handle_t *ah, const char *name)
Unload a grammar from an asr handle.
void switch_core_asr_text_param(switch_asr_handle_t *ah, char *param, const char *val)
Set a text parameter on an asr handle.
#define switch_resample_create(_n, _fr, _tr, _ts, _q, _c)
uint32_t switch_resample_process(switch_audio_resampler_t *resampler, int16_t *src, uint32_t srclen)
Resample one float buffer into another using specifications of a given handle.