40 const
char *module_name,
41 const
char *voice_name,
42 unsigned int rate,
unsigned int interval,
unsigned int channels,
49 if (!sh || !flags ||
zstr(module_name)) {
53 if (strchr(module_name,
':')) {
55 if ((param = strchr(buf,
':'))) {
68 sh->memory_pool =
pool;
85 sh->samplerate = rate;
86 sh->native_rate = rate;
87 sh->channels = channels;
88 sh->real_channels = 1;
90 if ((status = sh->speech_interface->speech_open(sh, voice_name, rate, channels, flags)) ==
SWITCH_STATUS_SUCCESS) {
102 char *param_string = NULL;
116 ltext = strdup(text);
120 while (data && *data ==
' ') {
130 param_string = data + 1;
142 if (!
zstr(param_string)) {
143 char *param[256] = { 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) {
154 status = sh->speech_interface->speech_feed_tts(sh, data, flags);
166 if (sh->speech_interface->speech_flush_tts) {
167 sh->speech_interface->speech_flush_tts(sh);
175 if (sh->speech_interface->speech_text_param_tts) {
176 sh->speech_interface->speech_text_param_tts(sh, param, val);
184 if (sh->speech_interface->speech_numeric_param_tts) {
185 sh->speech_interface->speech_numeric_param_tts(sh, param, val);
193 if (sh->speech_interface->speech_float_param_tts) {
194 sh->speech_interface->speech_float_param_tts(sh, param, val);
224 *datalen = orig_len / sh->channels;
226 if ((status = sh->speech_interface->speech_read_tts(sh, data, datalen, flags)) !=
SWITCH_STATUS_SUCCESS) {
231 if (sh->native_rate && sh->samplerate && sh->native_rate != sh->samplerate) {
232 if (!sh->resampler) {
241 if (sh->resampler->to_len < want / 2 || sh->resampler->to_len > orig_len / 2) {
243 int factor = sh->resampler->to_len * sh->samplerate / 1000;
247 if (!sh->dbuf || sh->dbuflen < sh->resampler->to_len * 2) {
248 sh->dbuflen = sh->resampler->to_len * 2;
253 memcpy((int16_t *) sh->dbuf, sh->resampler->to, sh->resampler->to_len * 2);
263 memcpy(data, sh->resampler->to, sh->resampler->to_len * 2);
264 *datalen = sh->resampler->to_len * 2;
272 if (sh->channels != sh->real_channels) {
273 uint32_t rlen = *datalen / 2;
275 *datalen = rlen * 2 * sh->channels;
285 switch_status_t status = sh->speech_interface->speech_close(sh, flags);
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.
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#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...
char * switch_find_end_paren(const char *s, char open, char close)
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.
uint32_t switch_speech_flag_t
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
void switch_core_speech_float_param_tts(switch_speech_handle_t *sh, char *param, double val)
Set a float parameter on a TTS handle.
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.
#define SWITCH_RESAMPLE_QUALITY
void switch_core_speech_numeric_param_tts(switch_speech_handle_t *sh, char *param, int val)
Set a numeric parameter on a TTS 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.
void switch_resample_destroy(switch_audio_resampler_t **resampler)
Destroy an existing resampler handle.
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.
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
switch_status_t switch_core_speech_close(switch_speech_handle_t *sh, switch_speech_flag_t *flags)
Close an open speech handle.
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.
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
#define switch_samples_per_packet(rate, interval)
void switch_core_speech_flush_tts(switch_speech_handle_t *sh)
Flush TTS audio on a given handle.
void switch_mux_channels(int16_t *data, switch_size_t samples, uint32_t orig_channels, uint32_t channels)
switch_status_t
Common return values.
switch_status_t switch_core_speech_open(switch_speech_handle_t *sh, const char *module_name, const char *voice_name, unsigned int rate, unsigned int interval, unsigned int channels, switch_speech_flag_t *flags, switch_memory_pool_t *pool)
#define switch_set_string(_dst, _src)
struct apr_pool_t switch_memory_pool_t
#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_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
#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_speech_interface_t * switch_loadable_module_get_speech_interface(const char *name)
Retrieve the speech interface by it's registered name.