RTS API Documentation  1.10.11
Functions
ASR/TTS Functions
+ Collaboration diagram for ASR/TTS Functions:

Functions

switch_status_t switch_core_speech_open (_In_ switch_speech_handle_t *sh, const char *module_name, const char *voice_name, _In_ unsigned int rate, _In_ unsigned int interval, _In_ unsigned int channels, switch_speech_flag_t *flags, _In_opt_ switch_memory_pool_t *pool)
 Open a speech handle. More...
 
switch_status_t switch_core_speech_feed_tts (switch_speech_handle_t *sh, const char *text, switch_speech_flag_t *flags)
 Feed text to the TTS module. More...
 
void switch_core_speech_flush_tts (switch_speech_handle_t *sh)
 Flush TTS audio on a given handle. More...
 
void switch_core_speech_text_param_tts (switch_speech_handle_t *sh, char *param, const char *val)
 Set a text parameter on a TTS handle. More...
 
void switch_core_speech_numeric_param_tts (switch_speech_handle_t *sh, char *param, int val)
 Set a numeric parameter on a TTS handle. More...
 
void switch_core_speech_float_param_tts (switch_speech_handle_t *sh, char *param, double val)
 Set a float parameter on a TTS handle. More...
 
switch_status_t switch_core_speech_read_tts (switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags)
 Read rendered audio from the TTS module. More...
 
switch_status_t switch_core_speech_close (switch_speech_handle_t *sh, switch_speech_flag_t *flags)
 Close an open speech handle. More...
 
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. More...
 
switch_status_t switch_core_asr_close (switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 Close an asr handle. More...
 
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. More...
 
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. More...
 
switch_status_t switch_core_asr_check_results (switch_asr_handle_t *ah, switch_asr_flag_t *flags)
 Check an asr handle for results. More...
 
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. More...
 
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. More...
 
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. More...
 
switch_status_t switch_core_asr_unload_grammar (switch_asr_handle_t *ah, const char *name)
 Unload a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_enable_grammar (switch_asr_handle_t *ah, const char *name)
 Enable a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_disable_grammar (switch_asr_handle_t *ah, const char *name)
 Disable a grammar from an asr handle. More...
 
switch_status_t switch_core_asr_disable_all_grammars (switch_asr_handle_t *ah)
 Disable all grammars from an asr handle. More...
 
switch_status_t switch_core_asr_pause (switch_asr_handle_t *ah)
 Pause detection on an asr handle. More...
 
switch_status_t switch_core_asr_resume (switch_asr_handle_t *ah)
 Resume detection on an asr handle. More...
 
switch_status_t switch_core_asr_start_input_timers (switch_asr_handle_t *ah)
 Start input timers on an asr handle. More...
 
void switch_core_asr_text_param (switch_asr_handle_t *ah, char *param, const char *val)
 Set a text parameter on an asr handle. More...
 
void switch_core_asr_numeric_param (switch_asr_handle_t *ah, char *param, int val)
 Set a numeric parameter on an asr handle. More...
 
void switch_core_asr_float_param (switch_asr_handle_t *ah, char *param, double val)
 Set a float parameter on an asr handle. More...
 

Detailed Description

Function Documentation

◆ switch_core_asr_check_results()

switch_status_t switch_core_asr_check_results ( switch_asr_handle_t ah,
switch_asr_flag_t flags 
)

Check an asr handle for results.

Parameters
ahthe handle to check
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 297 of file switch_core_asr.c.

References switch_asr_interface::asr_check_results, switch_asr_handle::asr_interface, and switch_assert.

Referenced by speech_callback(), and speech_thread().

298 {
299  switch_assert(ah != NULL);
300 
301  return ah->asr_interface->asr_check_results(ah, flags);
302 }
switch_status_t(* asr_check_results)(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
switch_asr_interface_t * asr_interface
#define switch_assert(expr)

◆ switch_core_asr_close()

switch_status_t switch_core_asr_close ( switch_asr_handle_t ah,
switch_asr_flag_t flags 
)

Close an asr handle.

Parameters
ahthe handle to close
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 227 of file switch_core_asr.c.

References switch_asr_interface::asr_close, switch_asr_handle::asr_interface, switch_asr_handle::dbuf, switch_asr_handle::memory_pool, switch_asr_handle::resampler, SWITCH_ASR_FLAG_CLOSED, SWITCH_ASR_FLAG_FREE_POOL, switch_assert, switch_core_destroy_memory_pool, switch_resample_destroy(), switch_safe_free, switch_set_flag, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by speech_callback(), and switch_ivr_detect_speech_init().

228 {
229  switch_status_t status;
230 
231  switch_assert(ah != NULL);
232 
233  status = ah->asr_interface->asr_close(ah, flags);
235 
236  switch_safe_free(ah->dbuf);
238 
240 
243  }
244 
245  return status;
246 }
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_status_t(* asr_close)(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
switch_asr_interface_t * asr_interface
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
#define UNPROTECT_INTERFACE(_it)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_status_t
Common return values.
switch_memory_pool_t * memory_pool
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
#define switch_assert(expr)
switch_audio_resampler_t * resampler

◆ switch_core_asr_disable_all_grammars()

switch_status_t switch_core_asr_disable_all_grammars ( switch_asr_handle_t ah)

Disable all grammars from an asr handle.

Parameters
ahthe handle to disable the grammars from
Returns
SWITCH_STATUS_SUCCESS

Definition at line 200 of file switch_core_asr.c.

References switch_asr_interface::asr_disable_all_grammars, switch_asr_handle::asr_interface, switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_disable_all_grammars().

201 {
203 
204  switch_assert(ah != NULL);
205 
207  status = ah->asr_interface->asr_disable_all_grammars(ah);
208  }
209 
210  return status;
211 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_disable_all_grammars)(switch_asr_handle_t *ah)
switch_status_t
Common return values.
#define switch_assert(expr)

◆ switch_core_asr_disable_grammar()

switch_status_t switch_core_asr_disable_grammar ( switch_asr_handle_t ah,
const char *  name 
)

Disable a grammar from an asr handle.

Parameters
ahthe handle to disable the grammar from
namethe name of the grammar to disable
Returns
SWITCH_STATUS_SUCCESS

Definition at line 187 of file switch_core_asr.c.

References switch_asr_interface::asr_disable_grammar, switch_asr_handle::asr_interface, switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_disable_grammar().

188 {
190 
191  switch_assert(ah != NULL);
192 
194  status = ah->asr_interface->asr_disable_grammar(ah, name);
195  }
196 
197  return status;
198 }
switch_status_t(* asr_disable_grammar)(switch_asr_handle_t *ah, const char *name)
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ switch_core_asr_enable_grammar()

switch_status_t switch_core_asr_enable_grammar ( switch_asr_handle_t ah,
const char *  name 
)

Enable a grammar from an asr handle.

Parameters
ahthe handle to enable the grammar from
namethe name of the grammar to enable
Returns
SWITCH_STATUS_SUCCESS

Definition at line 174 of file switch_core_asr.c.

References switch_asr_interface::asr_enable_grammar, switch_asr_handle::asr_interface, switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_enable_grammar().

175 {
177 
178  switch_assert(ah != NULL);
179 
181  status = ah->asr_interface->asr_enable_grammar(ah, name);
182  }
183 
184  return status;
185 }
switch_status_t(* asr_enable_grammar)(switch_asr_handle_t *ah, const char *name)
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ switch_core_asr_feed()

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.

Parameters
ahthe handle to feed data to
dataa pointer to the data
lenthe size in bytes of the data
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 248 of file switch_core_asr.c.

References switch_asr_interface::asr_feed, switch_asr_handle::asr_interface, switch_asr_handle::dbuf, switch_asr_handle::dbuflen, switch_asr_handle::native_rate, switch_asr_handle::resampler, switch_asr_handle::samplerate, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, switch_log_printf(), switch_resample_create, switch_resample_process(), SWITCH_RESAMPLE_QUALITY, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_audio_resampler_t::to, and switch_audio_resampler_t::to_len.

Referenced by speech_callback().

249 {
250  switch_size_t orig_len = len;
251  switch_assert(ah != NULL);
252 
253  if (ah->native_rate && ah->samplerate && ah->native_rate != ah->samplerate) {
254  if (!ah->resampler) {
256  ah->samplerate, ah->native_rate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
257  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
258  return SWITCH_STATUS_GENERR;
259  }
260  }
261 
262  switch_resample_process(ah->resampler, data, len / 2);
263  if (ah->resampler->to_len * 2 > orig_len) {
264  if (ah->dbuflen < ah->resampler->to_len * 2) {
265  void *mem;
266  ah->dbuflen = ah->resampler->to_len * 2;
267  mem = realloc(ah->dbuf, ah->dbuflen);
268  switch_assert(mem);
269  ah->dbuf = mem;
270  }
271  switch_assert(ah->resampler->to_len * 2 <= ah->dbuflen);
272  memcpy(ah->dbuf, ah->resampler->to, ah->resampler->to_len * 2);
273  data = ah->dbuf;
274  } else {
275  memcpy(data, ah->resampler->to, ah->resampler->to_len * 2);
276  }
277 
278  len = ah->resampler->to_len * 2;
279  }
280 
281  return ah->asr_interface->asr_feed(ah, data, len, flags);
282 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_RESAMPLE_QUALITY
switch_asr_interface_t * asr_interface
uintptr_t switch_size_t
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.
#define switch_assert(expr)
switch_audio_resampler_t * resampler
switch_status_t(* asr_feed)(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
#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.

◆ switch_core_asr_feed_dtmf()

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.

Parameters
ahthe handle to feed data to
dtmfa string of DTMF digits
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 284 of file switch_core_asr.c.

References switch_asr_interface::asr_feed_dtmf, switch_asr_handle::asr_interface, switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by speech_on_dtmf().

285 {
287 
288  switch_assert(ah != NULL);
289 
290  if (ah->asr_interface->asr_feed_dtmf) {
291  status = ah->asr_interface->asr_feed_dtmf(ah, dtmf, flags);
292  }
293 
294  return status;
295 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_feed_dtmf)(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags)
switch_status_t
Common return values.
#define switch_assert(expr)

◆ switch_core_asr_float_param()

void switch_core_asr_float_param ( switch_asr_handle_t ah,
char *  param,
double  val 
)

Set a float parameter on an asr handle.

Parameters
shthe asr handle
paramthe parameter
valthe value

Definition at line 354 of file switch_core_asr.c.

References switch_asr_interface::asr_float_param, switch_asr_handle::asr_interface, and switch_assert.

355 {
356  switch_assert(ah != NULL);
357 
358  if (ah->asr_interface->asr_float_param) {
359  ah->asr_interface->asr_float_param(ah, param, val);
360  }
361 }
switch_asr_interface_t * asr_interface
#define switch_assert(expr)
void(* asr_float_param)(switch_asr_handle_t *ah, char *param, double val)

◆ switch_core_asr_get_result_headers()

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.

Parameters
ahthe handle to get results from
headersa pointer to dynamically allocate an switch_event_t result to
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 311 of file switch_core_asr.c.

References switch_asr_interface::asr_get_result_headers, switch_asr_handle::asr_interface, switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by speech_thread().

312 {
313  switch_assert(ah != NULL);
314 
316  return ah->asr_interface->asr_get_result_headers(ah, headers, flags);
317  } else {
318  /* Since this is not always implemented, return success if the function can't be called */
319  return SWITCH_STATUS_SUCCESS;
320  }
321 }
switch_status_t(* asr_get_result_headers)(switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags)
switch_asr_interface_t * asr_interface
#define switch_assert(expr)

◆ switch_core_asr_get_results()

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.

Parameters
ahthe handle to get results from
xmlstra pointer to dynamically allocate an xml result string to
flagsflags to influence behaviour
Returns
SWITCH_STATUS_SUCCESS

Definition at line 304 of file switch_core_asr.c.

References switch_asr_interface::asr_get_results, switch_asr_handle::asr_interface, and switch_assert.

Referenced by speech_thread().

305 {
306  switch_assert(ah != NULL);
307 
308  return ah->asr_interface->asr_get_results(ah, xmlstr, flags);
309 }
switch_status_t(* asr_get_results)(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
switch_asr_interface_t * asr_interface
#define switch_assert(expr)

◆ switch_core_asr_load_grammar()

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.

Parameters
ahthe handle to load to
grammarthe grammar text, file path, or URI
namethe grammar name
Returns
SWITCH_STATUS_SUCCESS

Definition at line 101 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_load_grammar, switch_assert, switch_core_asr_text_param(), switch_find_end_paren(), switch_safe_free, switch_separate_string(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_ivr_detect_speech(), and switch_ivr_detect_speech_load_grammar().

102 {
104  char *param_string = NULL;
105  char *data = NULL;
106  char *lgrammar = NULL;
107 
108  switch_assert(ah != NULL);
109 
110  if (zstr(grammar)) {
111  status = SWITCH_STATUS_FALSE;
112  goto done;
113  }
114 
115  /* Set ASR parameters from params in the grammar string
116  * Params are defined as follows {name1=val1,name2=val2,name3=val3}grammar text
117  */
118  lgrammar = strdup(grammar);
119  data = lgrammar;
120 
121  /* strip leading spaces */
122  while (data && *data == ' ') {
123  data++;
124  }
125  if (zstr(data)) {
126  status = SWITCH_STATUS_FALSE;
127  goto done;
128  }
129 
130  /* extract params */
131  if (*data == '{') {
132  param_string = data + 1;
133  data = switch_find_end_paren(data, '{', '}');
134  if (zstr(data)) {
135  status = SWITCH_STATUS_FALSE;
136  goto done;
137  } else {
138  *data = '\0';
139  data++;
140  }
141  }
142 
143  /* set ASR params */
144  if (!zstr(param_string)) {
145  char *param[256] = { 0 };
146  int i;
147  int argc = switch_separate_string(param_string, ',', param, (sizeof(param) / sizeof(param[0])));
148  for (i = 0; i < argc && param[i]; ++i) {
149  char *param_pair[2] = { 0 };
150  if (switch_separate_string(param[i], '=', param_pair, (sizeof(param_pair) / sizeof(param_pair[0]))) == 2) {
151  switch_core_asr_text_param(ah, param_pair[0], param_pair[1]);
152  }
153  }
154  }
155 
156  status = ah->asr_interface->asr_load_grammar(ah, data, name);
157 
158  done:
159 
160  switch_safe_free(lgrammar);
161  return status;
162 }
char * switch_find_end_paren(const char *s, char open, char close)
Definition: switch_utils.c:796
switch_status_t(* asr_load_grammar)(switch_asr_handle_t *ah, const char *grammar, const char *name)
switch_asr_interface_t * asr_interface
#define zstr(x)
Definition: switch_utils.h:314
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.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_status_t
Common return values.
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)
void switch_core_asr_text_param(switch_asr_handle_t *ah, char *param, const char *val)
Set a text parameter on an asr handle.

◆ switch_core_asr_numeric_param()

void switch_core_asr_numeric_param ( switch_asr_handle_t ah,
char *  param,
int  val 
)

Set a numeric parameter on an asr handle.

Parameters
shthe asr handle
paramthe parameter
valthe value

Definition at line 345 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_numeric_param, and switch_assert.

346 {
347  switch_assert(ah != NULL);
348 
349  if (ah->asr_interface->asr_numeric_param) {
350  ah->asr_interface->asr_numeric_param(ah, param, val);
351  }
352 }
switch_asr_interface_t * asr_interface
void(* asr_numeric_param)(switch_asr_handle_t *ah, char *param, int val)
#define switch_assert(expr)

◆ switch_core_asr_open()

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.

Parameters
ahthe asr handle to open
module_namethe name of the asr module
codecthe preferred codec
ratethe preferred rate
destthe destination address
flagsflags to influence behaviour
poolthe pool to use (NULL for new pool)
Returns
SWITCH_STATUS_SUCCESS if the asr handle was opened

Definition at line 40 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_open, switch_cache_db_handle::flags, switch_asr_handle::flags, switch_asr_handle::memory_pool, switch_asr_handle::name, switch_asr_handle::native_rate, switch_asr_handle::param, pool, switch_asr_handle::rate, switch_asr_handle::samplerate, SWITCH_ASR_FLAG_FREE_POOL, switch_assert, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, switch_core_new_memory_pool, switch_core_strdup, switch_loadable_module_get_asr_interface(), SWITCH_LOG_ERROR, switch_log_printf(), switch_set_flag, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by switch_ivr_detect_speech_init().

43 {
44  switch_status_t status;
45  char *module_name_dup = NULL;
46  char *param = NULL;
47  int free_pool = 0;
48 
49  if (!pool) {
51  return status;
52  }
53  free_pool = 1;
54  }
55 
56  if (strchr(module_name, ':')) {
57  module_name_dup = switch_core_strdup(pool, module_name);
58  if ((param = strchr(module_name_dup, ':'))) {
59  *param++ = '\0';
60  module_name = module_name_dup;
61  }
62  }
63 
64  switch_assert(ah != NULL);
65 
66  if ((ah->asr_interface = switch_loadable_module_get_asr_interface(module_name)) == 0) {
67  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ASR module [%s]!\n", module_name);
68  if (free_pool) {
70  }
71  return SWITCH_STATUS_GENERR;
72  }
73 
74  ah->flags = *flags;
75 
76  ah->memory_pool = pool;
77  if (free_pool) {
79  }
80  if (param) {
81  ah->param = param;
82  }
83  ah->rate = rate;
84  ah->name = switch_core_strdup(ah->memory_pool, module_name);
85  ah->samplerate = rate;
86  ah->native_rate = rate;
87 
88  status = ah->asr_interface->asr_open(ah, codec, rate, dest, flags);
89 
90  if (status != SWITCH_STATUS_SUCCESS) {
93  }
95  }
96 
97  return status;
98 
99 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_status_t(* asr_open)(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
switch_asr_interface_t * asr_interface
#define UNPROTECT_INTERFACE(_it)
switch_asr_interface_t * switch_loadable_module_get_asr_interface(const char *name)
Retrieve the asr interface by it&#39;s registered name.
switch_status_t
Common return values.
switch_memory_pool_t * memory_pool
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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.
#define switch_assert(expr)

◆ switch_core_asr_pause()

switch_status_t switch_core_asr_pause ( switch_asr_handle_t ah)

Pause detection on an asr handle.

Parameters
ahthe handle to pause
Returns
SWITCH_STATUS_SUCCESS

Definition at line 213 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_pause, and switch_assert.

Referenced by switch_ivr_pause_detect_speech().

214 {
215  switch_assert(ah != NULL);
216 
217  return ah->asr_interface->asr_pause(ah);
218 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_pause)(switch_asr_handle_t *ah)
#define switch_assert(expr)

◆ switch_core_asr_resume()

switch_status_t switch_core_asr_resume ( switch_asr_handle_t ah)

Resume detection on an asr handle.

Parameters
ahthe handle to resume
Returns
SWITCH_STATUS_SUCCESS

Definition at line 220 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_resume, and switch_assert.

Referenced by switch_ivr_resume_detect_speech().

221 {
222  switch_assert(ah != NULL);
223 
224  return ah->asr_interface->asr_resume(ah);
225 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_resume)(switch_asr_handle_t *ah)
#define switch_assert(expr)

◆ switch_core_asr_start_input_timers()

switch_status_t switch_core_asr_start_input_timers ( switch_asr_handle_t ah)

Start input timers on an asr handle.

Parameters
ahthe handle to start timers on
Returns
SWITCH_STATUS_SUCCESS

Definition at line 323 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_start_input_timers, switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_detect_speech_start_input_timers().

324 {
326 
327  switch_assert(ah != NULL);
328 
330  status = ah->asr_interface->asr_start_input_timers(ah);
331  }
332 
333  return status;
334 }
switch_status_t(* asr_start_input_timers)(switch_asr_handle_t *ah)
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
#define switch_assert(expr)

◆ switch_core_asr_text_param()

void switch_core_asr_text_param ( switch_asr_handle_t ah,
char *  param,
const char *  val 
)

Set a text parameter on an asr handle.

Parameters
shthe asr handle
paramthe parameter
valthe value

Definition at line 336 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_text_param, and switch_assert.

Referenced by asr_set_json_text_params(), switch_core_asr_load_grammar(), and switch_ivr_set_param_detect_speech().

337 {
338  switch_assert(ah != NULL);
339 
340  if (ah->asr_interface->asr_text_param) {
341  ah->asr_interface->asr_text_param(ah, param, val);
342  }
343 }
switch_asr_interface_t * asr_interface
void(* asr_text_param)(switch_asr_handle_t *ah, char *param, const char *val)
#define switch_assert(expr)

◆ switch_core_asr_unload_grammar()

switch_status_t switch_core_asr_unload_grammar ( switch_asr_handle_t ah,
const char *  name 
)

Unload a grammar from an asr handle.

Parameters
ahthe handle to unload the grammar from
namethe name of the grammar to unload
Returns
SWITCH_STATUS_SUCCESS

Definition at line 164 of file switch_core_asr.c.

References switch_asr_handle::asr_interface, switch_asr_interface::asr_unload_grammar, and switch_assert.

Referenced by switch_ivr_detect_speech_unload_grammar().

165 {
166  switch_status_t status;
167 
168  switch_assert(ah != NULL);
169  status = ah->asr_interface->asr_unload_grammar(ah, name);
170 
171  return status;
172 }
switch_status_t(* asr_unload_grammar)(switch_asr_handle_t *ah, const char *name)
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ switch_core_speech_close()

switch_status_t switch_core_speech_close ( switch_speech_handle_t sh,
switch_speech_flag_t flags 
)

Close an open speech handle.

Parameters
shthe speech handle to close
flagsflags in/out for fine tuning
Returns
SWITCH_STATUS_SUCCESS if the file handle was closed

Definition at line 283 of file switch_core_speech.c.

References switch_speech_handle::buffer, switch_speech_handle::memory_pool, switch_speech_handle::resampler, switch_speech_interface::speech_close, switch_speech_handle::speech_interface, switch_buffer_destroy(), switch_clear_flag, switch_core_destroy_memory_pool, switch_resample_destroy(), SWITCH_SPEECH_FLAG_FREE_POOL, SWITCH_SPEECH_FLAG_OPEN, SWITCH_STATUS_FALSE, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by switch_ivr_clear_speech_cache(), and switch_ivr_speak_text().

284 {
285  switch_status_t status = sh->speech_interface->speech_close(sh, flags);
286 
288  return SWITCH_STATUS_FALSE;
289  }
290 
291  if (sh->buffer) {
293  }
294 
296 
298 
301  }
302 
304 
305  return status;
306 }
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
switch_memory_pool_t * memory_pool
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
switch_speech_interface_t * speech_interface
switch_audio_resampler_t * resampler
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
switch_status_t(* speech_close)(switch_speech_handle_t *, switch_speech_flag_t *flags)

◆ switch_core_speech_feed_tts()

switch_status_t switch_core_speech_feed_tts ( switch_speech_handle_t sh,
const char *  text,
switch_speech_flag_t flags 
)

Feed text to the TTS module.

Parameters
shthe speech handle to feed
textthe buffer to write
flagsflags in/out for fine tuning
Returns
SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful

Definition at line 99 of file switch_core_speech.c.

References switch_speech_interface::speech_feed_tts, switch_speech_handle::speech_interface, switch_assert, switch_core_speech_text_param_tts(), switch_find_end_paren(), switch_safe_free, switch_separate_string(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_ivr_speak_text_handle().

100 {
102  char *param_string = NULL;
103  char *data = NULL;
104  char *ltext = NULL;
105 
106  switch_assert(sh != NULL);
107 
108  if (zstr(text)) {
109  status = SWITCH_STATUS_FALSE;
110  goto done;
111  }
112 
113  /* Set TTS parameters from params in the text string
114  * Params are defined as follows {name1=val1,name2=val2,name3=val3}text to speak
115  */
116  ltext = strdup(text);
117  data = ltext;
118 
119  /* strip leading spaces */
120  while (data && *data == ' ') {
121  data++;
122  }
123  if (zstr(data)) {
124  status = SWITCH_STATUS_FALSE;
125  goto done;
126  }
127 
128  /* extract params */
129  if (*data == '{') {
130  param_string = data + 1;
131  data = switch_find_end_paren(data, '{', '}');
132  if (zstr(data)) {
133  status = SWITCH_STATUS_FALSE;
134  goto done;
135  } else {
136  *data = '\0';
137  data++;
138  }
139  }
140 
141  /* set TTS params */
142  if (!zstr(param_string)) {
143  char *param[256] = { 0 };
144  int i;
145  int argc = switch_separate_string(param_string, ',', param, (sizeof(param) / sizeof(param[0])));
146  for (i = 0; i < argc && param[i]; ++i) {
147  char *param_pair[2] = { 0 };
148  if (switch_separate_string(param[i], '=', param_pair, (sizeof(param_pair) / sizeof(param_pair[0]))) == 2) {
149  switch_core_speech_text_param_tts(sh, param_pair[0], param_pair[1]);
150  }
151  }
152  }
153 
154  status = sh->speech_interface->speech_feed_tts(sh, data, flags);
155 
156  done:
157 
158  switch_safe_free(ltext);
159  return status;
160 }
char * switch_find_end_paren(const char *s, char open, char close)
Definition: switch_utils.c:796
void switch_core_speech_text_param_tts(switch_speech_handle_t *sh, char *param, const char *val)
Set a text parameter on a TTS handle.
switch_status_t(* speech_feed_tts)(switch_speech_handle_t *sh, char *text, switch_speech_flag_t *flags)
#define zstr(x)
Definition: switch_utils.h:314
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.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
switch_speech_interface_t * speech_interface
switch_status_t
Common return values.
#define switch_assert(expr)

◆ switch_core_speech_float_param_tts()

void switch_core_speech_float_param_tts ( switch_speech_handle_t sh,
char *  param,
double  val 
)

Set a float parameter on a TTS handle.

Parameters
shthe speech handle
paramthe parameter
valthe value

Definition at line 189 of file switch_core_speech.c.

References switch_speech_interface::speech_float_param_tts, switch_speech_handle::speech_interface, and switch_assert.

190 {
191  switch_assert(sh != NULL);
192 
194  sh->speech_interface->speech_float_param_tts(sh, param, val);
195  }
196 }
void(* speech_float_param_tts)(switch_speech_handle_t *sh, char *param, double val)
switch_speech_interface_t * speech_interface
#define switch_assert(expr)

◆ switch_core_speech_flush_tts()

void switch_core_speech_flush_tts ( switch_speech_handle_t sh)

Flush TTS audio on a given handle.

Parameters
shthe speech handle

Definition at line 162 of file switch_core_speech.c.

References switch_speech_interface::speech_flush_tts, switch_speech_handle::speech_interface, and switch_assert.

Referenced by switch_ivr_speak_text_handle().

163 {
164  switch_assert(sh != NULL);
165 
168  }
169 }
void(* speech_flush_tts)(switch_speech_handle_t *sh)
switch_speech_interface_t * speech_interface
#define switch_assert(expr)

◆ switch_core_speech_numeric_param_tts()

void switch_core_speech_numeric_param_tts ( switch_speech_handle_t sh,
char *  param,
int  val 
)

Set a numeric parameter on a TTS handle.

Parameters
shthe speech handle
paramthe parameter
valthe value

Definition at line 180 of file switch_core_speech.c.

References switch_speech_handle::speech_interface, switch_speech_interface::speech_numeric_param_tts, and switch_assert.

181 {
182  switch_assert(sh != NULL);
183 
185  sh->speech_interface->speech_numeric_param_tts(sh, param, val);
186  }
187 }
void(* speech_numeric_param_tts)(switch_speech_handle_t *sh, char *param, int val)
switch_speech_interface_t * speech_interface
#define switch_assert(expr)

◆ switch_core_speech_open()

switch_status_t switch_core_speech_open ( _In_ switch_speech_handle_t sh,
const char *  module_name,
const char *  voice_name,
_In_ unsigned int  rate,
_In_ unsigned int  interval,
_In_ unsigned int  channels,
switch_speech_flag_t flags,
_In_opt_ switch_memory_pool_t pool 
)

Open a speech handle.

Parameters
sha speech handle to use
module_namethe speech module to use
voice_namethe desired voice name
ratethe sampling rate
intervalthe sampling interval
flagstts flags
poolthe pool to use (NULL for new pool)
Returns
SWITCH_STATUS_SUCCESS if the handle is opened

Referenced by switch_ivr_speak_text().

◆ switch_core_speech_read_tts()

switch_status_t switch_core_speech_read_tts ( switch_speech_handle_t sh,
void *  data,
switch_size_t datalen,
switch_speech_flag_t flags 
)

Read rendered audio from the TTS module.

Parameters
shthe speech handle to read
datathe buffer to read to
datalenthe max size / written size of the data
ratethe rate of the read audio
flagsflags in/out for fine tuning
Returns
SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful

Definition at line 198 of file switch_core_speech.c.

References switch_speech_handle::buffer, switch_speech_handle::channels, switch_speech_handle::dbuf, switch_speech_handle::dbuflen, switch_speech_handle::memory_pool, switch_speech_handle::native_rate, switch_speech_handle::real_channels, switch_speech_handle::resampler, switch_speech_handle::samplerate, switch_speech_handle::speech_interface, switch_speech_interface::speech_read_tts, switch_assert, switch_buffer_create_dynamic(), switch_buffer_inuse(), switch_buffer_read(), switch_buffer_write(), SWITCH_CHANNEL_LOG, switch_clear_flag, switch_core_alloc, SWITCH_LOG_CRIT, switch_log_printf(), switch_mux_channels(), switch_resample_create, switch_resample_process(), SWITCH_RESAMPLE_QUALITY, switch_set_flag, SWITCH_SPEECH_FLAG_DONE, SWITCH_STATUS_BREAK, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_test_flag, switch_audio_resampler_t::to, and switch_audio_resampler_t::to_len.

Referenced by switch_ivr_speak_text_handle().

199 {
200  switch_status_t status;
201  switch_size_t want, orig_len = *datalen;
202 
203  switch_assert(sh != NULL);
204 
205  want = *datalen;
206 
207  top:
208 
209  if (sh->buffer && (switch_buffer_inuse(sh->buffer) >= orig_len || switch_test_flag(sh, SWITCH_SPEECH_FLAG_DONE))) {
210  if ((*datalen = switch_buffer_read(sh->buffer, data, orig_len))) {
211  status = SWITCH_STATUS_SUCCESS;
212  goto done;
213  }
214  }
215 
218  *datalen = 0;
219  return SWITCH_STATUS_BREAK;
220  }
221 
222  more:
223 
224  *datalen = orig_len / sh->channels;
225 
226  if ((status = sh->speech_interface->speech_read_tts(sh, data, datalen, flags)) != SWITCH_STATUS_SUCCESS) {
228  goto top;
229  }
230 
231  if (sh->native_rate && sh->samplerate && sh->native_rate != sh->samplerate) {
232  if (!sh->resampler) {
234  sh->native_rate, sh->samplerate, (uint32_t) orig_len / sh->channels, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
235  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
236  return SWITCH_STATUS_GENERR;
237  }
238  }
239 
240  switch_resample_process(sh->resampler, data, (uint32_t)(*datalen / 2));
241  if (sh->resampler->to_len < want / 2 || sh->resampler->to_len > orig_len / 2) {
242  if (!sh->buffer) {
243  int factor = sh->resampler->to_len * sh->samplerate / 1000;
244  switch_buffer_create_dynamic(&sh->buffer, factor, factor, 0);
245  switch_assert(sh->buffer);
246  }
247  if (!sh->dbuf || sh->dbuflen < sh->resampler->to_len * 2) {
248  sh->dbuflen = sh->resampler->to_len * 2;
249  sh->dbuf = switch_core_alloc(sh->memory_pool, sh->dbuflen);
250  }
251  switch_assert(sh->resampler->to_len <= sh->dbuflen);
252 
253  memcpy((int16_t *) sh->dbuf, sh->resampler->to, sh->resampler->to_len * 2);
254  switch_buffer_write(sh->buffer, sh->dbuf, sh->resampler->to_len * 2);
255 
256  if (switch_buffer_inuse(sh->buffer) < want) {
257  *datalen = want;
258  goto more;
259  }
260  *datalen = switch_buffer_read(sh->buffer, data, orig_len);
261  status = SWITCH_STATUS_SUCCESS;
262  } else {
263  memcpy(data, sh->resampler->to, sh->resampler->to_len * 2);
264  *datalen = sh->resampler->to_len * 2;
265  status = SWITCH_STATUS_SUCCESS;
266  }
267  }
268 
269 
270  done:
271 
272  if (sh->channels != sh->real_channels) {
273  uint32_t rlen = *datalen / 2;
274  switch_mux_channels((int16_t *) data, rlen, 1, sh->channels);
275  *datalen = rlen * 2 * sh->channels;
276  }
277 
278  return status;
279 
280 }
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define SWITCH_CHANNEL_LOG
switch_size_t switch_buffer_read(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen)
Read data from a switch_buffer_t up to the ammount of datalen if it is available. Remove read data fr...
switch_status_t switch_buffer_create_dynamic(_Out_ switch_buffer_t **buffer, _In_ switch_size_t blocksize, _In_ switch_size_t start_len, _In_ switch_size_t max_len)
Allocate a new dynamic switch_buffer.
#define SWITCH_RESAMPLE_QUALITY
switch_size_t switch_buffer_write(_In_ switch_buffer_t *buffer, _In_bytecount_(datalen) const void *data, _In_ switch_size_t datalen)
Write data into a switch_buffer_t up to the length of datalen.
switch_memory_pool_t * memory_pool
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_speech_interface_t * speech_interface
uintptr_t switch_size_t
void switch_mux_channels(int16_t *data, switch_size_t samples, uint32_t orig_channels, uint32_t channels)
switch_audio_resampler_t * resampler
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
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.
#define switch_assert(expr)
switch_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
switch_status_t(* speech_read_tts)(switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags)
#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.

◆ switch_core_speech_text_param_tts()

void switch_core_speech_text_param_tts ( switch_speech_handle_t sh,
char *  param,
const char *  val 
)

Set a text parameter on a TTS handle.

Parameters
shthe speech handle
paramthe parameter
valthe value

Definition at line 171 of file switch_core_speech.c.

References switch_speech_handle::speech_interface, switch_speech_interface::speech_text_param_tts, and switch_assert.

Referenced by switch_core_speech_feed_tts(), and switch_ivr_speak_text().

172 {
173  switch_assert(sh != NULL);
174 
176  sh->speech_interface->speech_text_param_tts(sh, param, val);
177  }
178 }
void(* speech_text_param_tts)(switch_speech_handle_t *sh, char *param, const char *val)
switch_speech_interface_t * speech_interface
#define switch_assert(expr)