FreeSWITCH API Documentation  1.7.0
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, 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_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 288 of file switch_core_asr.c.

References switch_assert.

Referenced by speech_callback(), and speech_thread().

289 {
290  switch_assert(ah != NULL);
291 
292  return ah->asr_interface->asr_check_results(ah, flags);
293 }
switch_asr_interface_t * asr_interface
#define switch_assert(expr)
switch_status_t(* asr_check_results)(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
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 219 of file switch_core_asr.c.

References SWITCH_ASR_FLAG_CLOSED, SWITCH_ASR_FLAG_FREE_POOL, switch_assert, switch_core_destroy_memory_pool, switch_resample_destroy(), switch_set_flag, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by speech_callback(), and switch_ivr_detect_speech_init().

220 {
221  switch_status_t status;
222 
223  switch_assert(ah != NULL);
224 
225  status = ah->asr_interface->asr_close(ah, flags);
227 
229 
231 
234  }
235 
236  return status;
237 }
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_asr_interface_t * asr_interface
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
#define UNPROTECT_INTERFACE(_it)
switch_status_t(* asr_close)(switch_asr_handle_t *ah, switch_asr_flag_t *flags)
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:624
#define switch_assert(expr)
switch_audio_resampler_t * resampler
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 192 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_disable_all_grammars().

193 {
195 
196  switch_assert(ah != NULL);
197 
199  status = ah->asr_interface->asr_disable_all_grammars(ah);
200  }
201 
202  return status;
203 }
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
#define switch_assert(expr)
switch_status_t(* asr_disable_all_grammars)(switch_asr_handle_t *ah)
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 179 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_disable_grammar().

180 {
182 
183  switch_assert(ah != NULL);
184 
186  status = ah->asr_interface->asr_disable_grammar(ah, name);
187  }
188 
189  return status;
190 }
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
switch_status_t(* asr_disable_grammar)(switch_asr_handle_t *ah, const char *name)
#define switch_assert(expr)
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 166 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_FALSE.

Referenced by switch_ivr_detect_speech_enable_grammar().

167 {
169 
170  switch_assert(ah != NULL);
171 
173  status = ah->asr_interface->asr_enable_grammar(ah, name);
174  }
175 
176  return status;
177 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_enable_grammar)(switch_asr_handle_t *ah, const char *name)
switch_status_t
Common return values.
#define switch_assert(expr)
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 239 of file switch_core_asr.c.

References switch_assert, SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, switch_log_printf(), switch_resample_create, switch_resample_process(), SWITCH_RESAMPLE_QUALITY, SWITCH_STATUS_GENERR, and SWITCH_STATUS_SUCCESS.

Referenced by speech_callback().

240 {
241  switch_size_t orig_len = len;
242  switch_assert(ah != NULL);
243 
244  if (ah->native_rate && ah->samplerate && ah->native_rate != ah->samplerate) {
245  if (!ah->resampler) {
247  ah->samplerate, ah->native_rate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
248  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
249  return SWITCH_STATUS_GENERR;
250  }
251  }
252 
253  switch_resample_process(ah->resampler, data, len / 2);
254  if (ah->resampler->to_len > orig_len) {
255  if (!ah->dbuf) {
256  void *mem;
257  ah->dbuflen = ah->resampler->to_len * 2;
258  mem = realloc(ah->dbuf, ah->dbuflen);
259  switch_assert(mem);
260  ah->dbuf = mem;
261  }
262  switch_assert(ah->resampler->to_len * 2 <= ah->dbuflen);
263  memcpy(ah->dbuf, ah->resampler->to, ah->resampler->to_len * 2);
264  data = ah->dbuf;
265  } else {
266  memcpy(data, ah->resampler->to, ah->resampler->to_len * 2);
267  }
268 
269  len = ah->resampler->to_len;
270  }
271 
272  return ah->asr_interface->asr_feed(ah, data, len, flags);
273 }
#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
#define switch_resample_create(_n, _fr, _tr, _ts, _q, _c)
switch_status_t(* asr_feed)(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
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_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 275 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by speech_on_dtmf().

276 {
278 
279  switch_assert(ah != NULL);
280 
281  if (ah->asr_interface->asr_feed_dtmf) {
282  status = ah->asr_interface->asr_feed_dtmf(ah, dtmf, flags);
283  }
284 
285  return status;
286 }
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
switch_status_t(* asr_feed_dtmf)(switch_asr_handle_t *ah, const switch_dtmf_t *dtmf, switch_asr_flag_t *flags)
#define switch_assert(expr)
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 345 of file switch_core_asr.c.

References switch_assert.

346 {
347  switch_assert(ah != NULL);
348 
349  if (ah->asr_interface->asr_float_param) {
350  ah->asr_interface->asr_float_param(ah, param, val);
351  }
352 }
switch_asr_interface_t * asr_interface
#define switch_assert(expr)
void(* asr_float_param)(switch_asr_handle_t *ah, char *param, double val)
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 302 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by speech_thread().

303 {
304  switch_assert(ah != NULL);
305 
307  return ah->asr_interface->asr_get_result_headers(ah, headers, flags);
308  } else {
309  /* Since this is not always implemented, return success if the function can't be called */
310  return SWITCH_STATUS_SUCCESS;
311  }
312 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_get_result_headers)(switch_asr_handle_t *ah, switch_event_t **headers, switch_asr_flag_t *flags)
#define switch_assert(expr)
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 295 of file switch_core_asr.c.

References switch_assert.

Referenced by speech_thread().

296 {
297  switch_assert(ah != NULL);
298 
299  return ah->asr_interface->asr_get_results(ah, xmlstr, flags);
300 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_get_results)(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
#define switch_assert(expr)
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 93 of file switch_core_asr.c.

References 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().

94 {
96  char *param_string = NULL;
97  char *data = NULL;
98  char *lgrammar = NULL;
99 
100  switch_assert(ah != NULL);
101 
102  if (zstr(grammar)) {
103  status = SWITCH_STATUS_FALSE;
104  goto done;
105  }
106 
107  /* Set ASR parameters from params in the grammar string
108  * Params are defined as follows {name1=val1,name2=val2,name3=val3}grammar text
109  */
110  lgrammar = strdup(grammar);
111  data = lgrammar;
112 
113  /* strip leading spaces */
114  while (data && *data == ' ') {
115  data++;
116  }
117  if (zstr(data)) {
118  status = SWITCH_STATUS_FALSE;
119  goto done;
120  }
121 
122  /* extract params */
123  if (*data == '{') {
124  param_string = data + 1;
125  data = switch_find_end_paren(data, '{', '}');
126  if (zstr(data)) {
127  status = SWITCH_STATUS_FALSE;
128  goto done;
129  } else {
130  *data = '\0';
131  data++;
132  }
133  }
134 
135  /* set ASR params */
136  if (!zstr(param_string)) {
137  char *param[256] = { 0 };
138  int i;
139  int argc = switch_separate_string(param_string, ',', param, (sizeof(param) / sizeof(param[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) {
143  switch_core_asr_text_param(ah, param_pair[0], param_pair[1]);
144  }
145  }
146  }
147 
148  status = ah->asr_interface->asr_load_grammar(ah, data, name);
149 
150  done:
151 
152  switch_safe_free(lgrammar);
153  return status;
154 }
char * switch_find_end_paren(const char *s, char open, char close)
Definition: switch_utils.c:661
switch_asr_interface_t * asr_interface
#define zstr(x)
Definition: switch_utils.h:281
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(* asr_load_grammar)(switch_asr_handle_t *ah, const char *grammar, const char *name)
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_status_t
Common return values.
#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.
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 336 of file switch_core_asr.c.

References switch_assert.

337 {
338  switch_assert(ah != NULL);
339 
340  if (ah->asr_interface->asr_numeric_param) {
341  ah->asr_interface->asr_numeric_param(ah, param, val);
342  }
343 }
switch_asr_interface_t * asr_interface
void(* asr_numeric_param)(switch_asr_handle_t *ah, char *param, int val)
#define switch_assert(expr)
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 buf, switch_cache_db_handle::flags, pool, SWITCH_ASR_FLAG_FREE_POOL, switch_assert, SWITCH_CHANNEL_LOG, switch_core_new_memory_pool, switch_core_strdup, switch_loadable_module_get_asr_interface(), SWITCH_LOG_ERROR, switch_log_printf(), switch_set_flag, switch_set_string, SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, and UNPROTECT_INTERFACE.

Referenced by switch_ivr_detect_speech_init().

43 {
44  switch_status_t status;
45  char buf[256] = "";
46  char *param = NULL;
47 
48  if (strchr(module_name, ':')) {
49  switch_set_string(buf, module_name);
50  if ((param = strchr(buf, ':'))) {
51  *param++ = '\0';
52  module_name = buf;
53  }
54  }
55 
56  switch_assert(ah != NULL);
57 
58  if ((ah->asr_interface = switch_loadable_module_get_asr_interface(module_name)) == 0) {
59  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid ASR module [%s]!\n", module_name);
60  return SWITCH_STATUS_GENERR;
61  }
62 
63  ah->flags = *flags;
64 
65  if (pool) {
66  ah->memory_pool = pool;
67  } else {
70  return status;
71  }
73  }
74 
75  if (param) {
76  ah->param = switch_core_strdup(ah->memory_pool, param);
77  }
78  ah->rate = rate;
79  ah->name = switch_core_strdup(ah->memory_pool, module_name);
80  ah->samplerate = rate;
81  ah->native_rate = rate;
82 
83  status = ah->asr_interface->asr_open(ah, codec, rate, dest, flags);
84 
85  if (status != SWITCH_STATUS_SUCCESS) {
87  }
88 
89  return status;
90 
91 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
switch_memory_pool_t * pool
switch_asr_interface_t * asr_interface
switch_status_t(* asr_open)(switch_asr_handle_t *ah, const char *codec, int rate, const char *dest, switch_asr_flag_t *flags)
#define UNPROTECT_INTERFACE(_it)
switch_byte_t switch_byte_t * buf
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
Common return values.
switch_memory_pool_t * memory_pool
#define switch_set_string(_dst, _src)
Definition: switch_utils.h:665
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_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 205 of file switch_core_asr.c.

References switch_assert.

Referenced by switch_ivr_pause_detect_speech().

206 {
207  switch_assert(ah != NULL);
208 
209  return ah->asr_interface->asr_pause(ah);
210 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_pause)(switch_asr_handle_t *ah)
#define switch_assert(expr)
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 212 of file switch_core_asr.c.

References switch_assert.

Referenced by switch_ivr_resume_detect_speech().

213 {
214  switch_assert(ah != NULL);
215 
216  return ah->asr_interface->asr_resume(ah);
217 }
switch_asr_interface_t * asr_interface
switch_status_t(* asr_resume)(switch_asr_handle_t *ah)
#define switch_assert(expr)
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 314 of file switch_core_asr.c.

References switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_detect_speech_start_input_timers().

315 {
317 
318  switch_assert(ah != NULL);
319 
321  status = ah->asr_interface->asr_start_input_timers(ah);
322  }
323 
324  return status;
325 }
switch_asr_interface_t * asr_interface
switch_status_t
Common return values.
switch_status_t(* asr_start_input_timers)(switch_asr_handle_t *ah)
#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.

Parameters
shthe asr handle
paramthe parameter
valthe value

Definition at line 327 of file switch_core_asr.c.

References switch_assert.

Referenced by switch_core_asr_load_grammar(), and switch_ivr_set_param_detect_speech().

328 {
329  switch_assert(ah != NULL);
330 
331  if (ah->asr_interface->asr_text_param) {
332  ah->asr_interface->asr_text_param(ah, param, val);
333  }
334 }
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_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 156 of file switch_core_asr.c.

References switch_assert.

Referenced by switch_ivr_detect_speech_unload_grammar().

157 {
158  switch_status_t status;
159 
160  switch_assert(ah != NULL);
161  status = ah->asr_interface->asr_unload_grammar(ah, name);
162 
163  return status;
164 }
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.
#define switch_assert(expr)
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_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:640
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:655
switch_speech_interface_t * speech_interface
switch_audio_resampler_t * resampler
switch_status_t
Common return values.
switch_status_t(* speech_close)(switch_speech_handle_t *, switch_speech_flag_t *flags)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
switch_status_t switch_core_speech_feed_tts ( switch_speech_handle_t sh,
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_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:661
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:281
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:789
switch_speech_interface_t * speech_interface
switch_status_t
Common return values.
#define switch_assert(expr)
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_assert.

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

Referenced by switch_ivr_speak_text_handle().

163 {
164  switch_assert(sh != NULL);
165 
168  }
169 }
switch_speech_interface_t * speech_interface
void(* speech_flush_tts)(switch_speech_handle_t *sh)
#define switch_assert(expr)
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_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_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_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_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, and switch_test_flag.

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:631
#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:655
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
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.
switch_status_t(* speech_read_tts)(switch_speech_handle_t *sh, void *data, switch_size_t *datalen, switch_speech_flag_t *flags)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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.
#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.
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_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 }
switch_speech_interface_t * speech_interface
void(* speech_text_param_tts)(switch_speech_handle_t *sh, char *param, const char *val)
#define switch_assert(expr)