Speech Recognition Utility Applications. More...
#include "asterisk.h"#include "asterisk/file.h"#include "asterisk/channel.h"#include "asterisk/pbx.h"#include "asterisk/module.h"#include "asterisk/lock.h"#include "asterisk/app.h"#include "asterisk/speech.h"
Go to the source code of this file.
Enumerations | |
| enum | { SB_OPT_NOANSWER = (1 << 0) } |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| ASTERISK_FILE_VERSION (__FILE__,"$Revision: 362815 $") | |
| static void | destroy_callback (void *data) |
| Helper function used by datastores to destroy the speech structure upon hangup. | |
| static struct ast_speech_result * | find_result (struct ast_speech_result *results, char *result_num) |
| static struct ast_speech * | find_speech (struct ast_channel *chan) |
| Helper function used to find the speech structure attached to a channel. | |
| static int | load_module (void) |
| static int | speech_activate (struct ast_channel *chan, const char *data) |
| SpeechActivateGrammar(Grammar Name) Dialplan Application. | |
| static int | speech_background (struct ast_channel *chan, const char *data) |
| SpeechBackground(Sound File,Timeout) Dialplan Application. | |
| static int | speech_create (struct ast_channel *chan, const char *data) |
| SpeechCreate() Dialplan Application. | |
| static int | speech_deactivate (struct ast_channel *chan, const char *data) |
| SpeechDeactivateGrammar(Grammar Name) Dialplan Application. | |
| static int | speech_destroy (struct ast_channel *chan, const char *data) |
| SpeechDestroy() Dialplan Application. | |
| static int | speech_engine_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| SPEECH_ENGINE() Dialplan Function. | |
| static int | speech_grammar (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| SPEECH_GRAMMAR() Dialplan Function. | |
| static int | speech_load (struct ast_channel *chan, const char *vdata) |
| SpeechLoadGrammar(Grammar Name,Path) Dialplan Application. | |
| static int | speech_processing_sound (struct ast_channel *chan, const char *data) |
| SpeechProcessingSound(Sound File) Dialplan Application. | |
| static int | speech_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| SPEECH() Dialplan Function. | |
| static int | speech_results_type_write (struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| SPEECH_RESULTS_TYPE() Dialplan Function. | |
| static int | speech_score (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| SPEECH_SCORE() Dialplan Function. | |
| static int | speech_start (struct ast_channel *chan, const char *data) |
| SpeechStart() Dialplan Application. | |
| static int | speech_streamfile (struct ast_channel *chan, const char *filename, const char *preflang) |
| Helper function used by speech_background to playback a soundfile. | |
| static int | speech_text (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| SPEECH_TEXT() Dialplan Function. | |
| static int | speech_unload (struct ast_channel *chan, const char *data) |
| SpeechUnloadGrammar(Grammar Name) Dialplan Application. | |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Dialplan Speech Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "95089850e3c922fa176f9bd274fd8109" , .load = load_module, .unload = unload_module, .nonoptreq = "res_speech", } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct ast_app_option | speech_background_options [128] = { [ 'n' ] = { .flag = SB_OPT_NOANSWER }, } |
| static struct ast_datastore_info | speech_datastore |
| Static structure for datastore information. | |
| static struct ast_custom_function | speech_engine_function |
| static struct ast_custom_function | speech_function |
| static struct ast_custom_function | speech_grammar_function |
| static struct ast_custom_function | speech_results_type_function |
| static struct ast_custom_function | speech_score_function |
| static struct ast_custom_function | speech_text_function |
Speech Recognition Utility Applications.
Definition in file app_speech_utils.c.
| anonymous enum |
Definition at line 643 of file app_speech_utils.c.
{
SB_OPT_NOANSWER = (1 << 0),
};
| static void __reg_module | ( | void | ) | [static] |
Definition at line 975 of file app_speech_utils.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 975 of file app_speech_utils.c.
| ASTERISK_FILE_VERSION | ( | __FILE__ | , |
| "$Revision: 362815 $" | |||
| ) |
| static void destroy_callback | ( | void * | data | ) | [static] |
Helper function used by datastores to destroy the speech structure upon hangup.
Definition at line 262 of file app_speech_utils.c.
References ast_speech_destroy().
{
struct ast_speech *speech = (struct ast_speech*)data;
if (speech == NULL) {
return;
}
/* Deallocate now */
ast_speech_destroy(speech);
return;
}
| static struct ast_speech_result* find_result | ( | struct ast_speech_result * | results, |
| char * | result_num | ||
| ) | [static, read] |
Definition at line 298 of file app_speech_utils.c.
References ast_speech_result::nbest_num, AST_LIST_NEXT, and ast_speech_result::list.
Referenced by speech_score(), speech_text(), and speech_grammar().
{
struct ast_speech_result *result = results;
char *tmp = NULL;
int nbest_num = 0, wanted_num = 0, i = 0;
if (!result) {
return NULL;
}
if ((tmp = strchr(result_num, '/'))) {
*tmp++ = '\0';
nbest_num = atoi(result_num);
wanted_num = atoi(tmp);
} else {
wanted_num = atoi(result_num);
}
do {
if (result->nbest_num != nbest_num)
continue;
if (i == wanted_num)
break;
i++;
} while ((result = AST_LIST_NEXT(result, list)));
return result;
}
| static struct ast_speech* find_speech | ( | struct ast_channel * | chan | ) | [static, read] |
Helper function used to find the speech structure attached to a channel.
Definition at line 283 of file app_speech_utils.c.
References ast_channel_datastore_find(), and ast_datastore::data.
Referenced by speech_score(), speech_text(), speech_grammar(), speech_engine_write(), speech_results_type_write(), speech_read(), speech_load(), speech_unload(), speech_deactivate(), speech_activate(), speech_start(), speech_processing_sound(), speech_background(), and speech_destroy().
{
struct ast_speech *speech = NULL;
struct ast_datastore *datastore = NULL;
datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
if (datastore == NULL) {
return NULL;
}
speech = datastore->data;
return speech;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 948 of file app_speech_utils.c.
References ast_register_application_xml, speech_create(), speech_load(), speech_unload(), speech_activate(), speech_deactivate(), speech_start(), speech_background(), speech_destroy(), speech_processing_sound(), and ast_custom_function_register.
{
int res = 0;
res = ast_register_application_xml("SpeechCreate", speech_create);
res |= ast_register_application_xml("SpeechLoadGrammar", speech_load);
res |= ast_register_application_xml("SpeechUnloadGrammar", speech_unload);
res |= ast_register_application_xml("SpeechActivateGrammar", speech_activate);
res |= ast_register_application_xml("SpeechDeactivateGrammar", speech_deactivate);
res |= ast_register_application_xml("SpeechStart", speech_start);
res |= ast_register_application_xml("SpeechBackground", speech_background);
res |= ast_register_application_xml("SpeechDestroy", speech_destroy);
res |= ast_register_application_xml("SpeechProcessingSound", speech_processing_sound);
res |= ast_custom_function_register(&speech_function);
res |= ast_custom_function_register(&speech_score_function);
res |= ast_custom_function_register(&speech_text_function);
res |= ast_custom_function_register(&speech_grammar_function);
res |= ast_custom_function_register(&speech_engine_function);
res |= ast_custom_function_register(&speech_results_type_function);
return res;
}
| static int speech_activate | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechActivateGrammar(Grammar Name) Dialplan Application.
Definition at line 580 of file app_speech_utils.c.
References find_speech(), and ast_speech_grammar_activate().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
if (speech == NULL)
return -1;
/* Activate the grammar on the speech object */
res = ast_speech_grammar_activate(speech, data);
return res;
}
| static int speech_background | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechBackground(Sound File,Timeout) Dialplan Application.
Definition at line 652 of file app_speech_utils.c.
References find_speech(), f, AST_FORMAT_SLINEAR, AST_MAX_EXTENSION, parse(), AST_DECLARE_APP_ARGS, args, AST_APP_ARG, ast_strdupa, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_app_parse_options(), speech_background_options, ast_channel::_state, AST_STATE_UP, ast_test_flag, SB_OPT_NOANSWER, ast_answer(), ast_channel::readformat, ast_set_read_format(), ast_speech::format, ast_channel_lock, pbx_builtin_getvar_helper(), ast_channel_unlock, ast_speech::state, AST_SPEECH_STATE_NOT_READY, AST_SPEECH_STATE_DONE, ast_speech_change_state(), ast_speech_start(), ast_stopstream(), ast_channel::streamid, ast_channel::timingfunc, strsep(), speech_streamfile(), ast_channel::language, ast_sched_runq(), ast_channel::sched, ast_sched_wait(), ast_waitfor(), ast_read(), ast_tvnow(), ast_tvdiff_ms(), ast_frfree, ast_mutex_lock, ast_speech::lock, AST_SPEECH_QUIET, ast_channel::stream, ast_clear_flag, AST_SPEECH_STATE_READY, ast_frame::frametype, AST_FRAME_VOICE, ast_speech_write(), ast_frame::data, ast_frame::ptr, ast_frame::datalen, AST_SPEECH_STATE_WAIT, ast_speech::processing_sound, ast_speech::results, ast_speech_results_get(), ast_mutex_unlock, AST_FRAME_DTMF, ast_frame::subclass, ast_frame_subclass::integer, ast_channel::pbx, ast_pbx::dtimeoutms, AST_FRAME_CONTROL, AST_CONTROL_HANGUP, ast_calloc, ast_speech_dtmf(), ast_speech_result::score, ast_speech_result::text, ast_strdup, ast_speech_result::grammar, ast_speech_destroy(), ast_channel_datastore_find(), and ast_channel_datastore_remove().
Referenced by load_module().
{
unsigned int timeout = 0;
int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0;
struct ast_speech *speech = find_speech(chan);
struct ast_frame *f = NULL;
int oldreadformat = AST_FORMAT_SLINEAR;
char dtmf[AST_MAX_EXTENSION] = "";
struct timeval start = { 0, 0 }, current;
struct ast_datastore *datastore = NULL;
char *parse, *filename_tmp = NULL, *filename = NULL, tmp[2] = "", dtmf_terminator = '#';
const char *tmp2 = NULL;
struct ast_flags options = { 0 };
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(soundfile);
AST_APP_ARG(timeout);
AST_APP_ARG(options);
);
parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (speech == NULL)
return -1;
if (!ast_strlen_zero(args.options)) {
char *options_buf = ast_strdupa(args.options);
ast_app_parse_options(speech_background_options, &options, NULL, options_buf);
}
/* If channel is not already answered, then answer it */
if (chan->_state != AST_STATE_UP && !ast_test_flag(&options, SB_OPT_NOANSWER)
&& ast_answer(chan)) {
return -1;
}
/* Record old read format */
oldreadformat = chan->readformat;
/* Change read format to be signed linear */
if (ast_set_read_format(chan, speech->format))
return -1;
if (!ast_strlen_zero(args.soundfile)) {
/* Yay sound file */
filename_tmp = ast_strdupa(args.soundfile);
if (!ast_strlen_zero(args.timeout)) {
if ((timeout = atof(args.timeout) * 1000.0) == 0)
timeout = -1;
} else
timeout = 0;
}
/* See if the maximum DTMF length variable is set... we use a variable in case they want to carry it through their entire dialplan */
ast_channel_lock(chan);
if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_MAXLEN")) && !ast_strlen_zero(tmp2)) {
max_dtmf_len = atoi(tmp2);
}
/* See if a terminator is specified */
if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_TERMINATOR"))) {
if (ast_strlen_zero(tmp2))
dtmf_terminator = '\0';
else
dtmf_terminator = tmp2[0];
}
ast_channel_unlock(chan);
/* Before we go into waiting for stuff... make sure the structure is ready, if not - start it again */
if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) {
ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
ast_speech_start(speech);
}
/* Ensure no streams are currently running */
ast_stopstream(chan);
/* Okay it's streaming so go into a loop grabbing frames! */
while (done == 0) {
/* If the filename is null and stream is not running, start up a new sound file */
if (!quieted && (chan->streamid == -1 && chan->timingfunc == NULL) && (filename = strsep(&filename_tmp, "&"))) {
/* Discard old stream information */
ast_stopstream(chan);
/* Start new stream */
speech_streamfile(chan, filename, chan->language);
}
/* Run scheduled stuff */
ast_sched_runq(chan->sched);
/* Yay scheduling */
res = ast_sched_wait(chan->sched);
if (res < 0)
res = 1000;
/* If there is a frame waiting, get it - if not - oh well */
if (ast_waitfor(chan, res) > 0) {
f = ast_read(chan);
if (f == NULL) {
/* The channel has hung up most likely */
done = 3;
break;
}
}
/* Do timeout check (shared between audio/dtmf) */
if ((!quieted || strlen(dtmf)) && started == 1) {
current = ast_tvnow();
if ((ast_tvdiff_ms(current, start)) >= timeout) {
done = 1;
if (f)
ast_frfree(f);
break;
}
}
/* Do checks on speech structure to see if it's changed */
ast_mutex_lock(&speech->lock);
if (ast_test_flag(speech, AST_SPEECH_QUIET)) {
if (chan->stream)
ast_stopstream(chan);
ast_clear_flag(speech, AST_SPEECH_QUIET);
quieted = 1;
}
/* Check state so we can see what to do */
switch (speech->state) {
case AST_SPEECH_STATE_READY:
/* If audio playback has stopped do a check for timeout purposes */
if (chan->streamid == -1 && chan->timingfunc == NULL)
ast_stopstream(chan);
if (!quieted && chan->stream == NULL && timeout && started == 0 && !filename_tmp) {
if (timeout == -1) {
done = 1;
if (f)
ast_frfree(f);
break;
}
start = ast_tvnow();
started = 1;
}
/* Write audio frame out to speech engine if no DTMF has been received */
if (!strlen(dtmf) && f != NULL && f->frametype == AST_FRAME_VOICE) {
ast_speech_write(speech, f->data.ptr, f->datalen);
}
break;
case AST_SPEECH_STATE_WAIT:
/* Cue up waiting sound if not already playing */
if (!strlen(dtmf)) {
if (chan->stream == NULL) {
if (speech->processing_sound != NULL) {
if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound, "none")) {
speech_streamfile(chan, speech->processing_sound, chan->language);
}
}
} else if (chan->streamid == -1 && chan->timingfunc == NULL) {
ast_stopstream(chan);
if (speech->processing_sound != NULL) {
if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound, "none")) {
speech_streamfile(chan, speech->processing_sound, chan->language);
}
}
}
}
break;
case AST_SPEECH_STATE_DONE:
/* Now that we are done... let's switch back to not ready state */
ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
if (!strlen(dtmf)) {
/* Copy to speech structure the results, if available */
speech->results = ast_speech_results_get(speech);
/* Break out of our background too */
done = 1;
/* Stop audio playback */
if (chan->stream != NULL) {
ast_stopstream(chan);
}
}
break;
default:
break;
}
ast_mutex_unlock(&speech->lock);
/* Deal with other frame types */
if (f != NULL) {
/* Free the frame we received */
switch (f->frametype) {
case AST_FRAME_DTMF:
if (dtmf_terminator != '\0' && f->subclass.integer == dtmf_terminator) {
done = 1;
} else {
quieted = 1;
if (chan->stream != NULL) {
ast_stopstream(chan);
}
if (!started) {
/* Change timeout to be 5 seconds for DTMF input */
timeout = (chan->pbx && chan->pbx->dtimeoutms) ? chan->pbx->dtimeoutms : 5000;
started = 1;
}
start = ast_tvnow();
snprintf(tmp, sizeof(tmp), "%c", f->subclass.integer);
strncat(dtmf, tmp, sizeof(dtmf) - strlen(dtmf) - 1);
/* If the maximum length of the DTMF has been reached, stop now */
if (max_dtmf_len && strlen(dtmf) == max_dtmf_len)
done = 1;
}
break;
case AST_FRAME_CONTROL:
switch (f->subclass.integer) {
case AST_CONTROL_HANGUP:
/* Since they hung up we should destroy the speech structure */
done = 3;
default:
break;
}
default:
break;
}
ast_frfree(f);
f = NULL;
}
}
if (!ast_strlen_zero(dtmf)) {
/* We sort of make a results entry */
speech->results = ast_calloc(1, sizeof(*speech->results));
if (speech->results != NULL) {
ast_speech_dtmf(speech, dtmf);
speech->results->score = 1000;
speech->results->text = ast_strdup(dtmf);
speech->results->grammar = ast_strdup("dtmf");
}
ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
}
/* See if it was because they hung up */
if (done == 3) {
/* Destroy speech structure */
ast_speech_destroy(speech);
datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
if (datastore != NULL)
ast_channel_datastore_remove(chan, datastore);
} else {
/* Channel is okay so restore read format */
ast_set_read_format(chan, oldreadformat);
}
return 0;
}
| static int speech_create | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechCreate() Dialplan Application.
Definition at line 497 of file app_speech_utils.c.
References ast_speech_new(), ast_channel::nativeformats, pbx_builtin_setvar_helper(), ast_datastore_alloc(), ast_speech_destroy(), ast_datastore::data, and ast_channel_datastore_add().
Referenced by load_module().
{
struct ast_speech *speech = NULL;
struct ast_datastore *datastore = NULL;
/* Request a speech object */
speech = ast_speech_new(data, chan->nativeformats);
if (speech == NULL) {
/* Not available */
pbx_builtin_setvar_helper(chan, "ERROR", "1");
return 0;
}
datastore = ast_datastore_alloc(&speech_datastore, NULL);
if (datastore == NULL) {
ast_speech_destroy(speech);
pbx_builtin_setvar_helper(chan, "ERROR", "1");
return 0;
}
pbx_builtin_setvar_helper(chan, "ERROR", NULL);
datastore->data = speech;
ast_channel_datastore_add(chan, datastore);
return 0;
}
| static int speech_deactivate | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechDeactivateGrammar(Grammar Name) Dialplan Application.
Definition at line 565 of file app_speech_utils.c.
References find_speech(), and ast_speech_grammar_deactivate().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
if (speech == NULL)
return -1;
/* Deactivate the grammar on the speech object */
res = ast_speech_grammar_deactivate(speech, data);
return res;
}
| static int speech_destroy | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechDestroy() Dialplan Application.
Definition at line 905 of file app_speech_utils.c.
References find_speech(), ast_speech_destroy(), ast_channel_datastore_find(), and ast_channel_datastore_remove().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
struct ast_datastore *datastore = NULL;
if (speech == NULL)
return -1;
/* Destroy speech structure */
ast_speech_destroy(speech);
datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL);
if (datastore != NULL) {
ast_channel_datastore_remove(chan, datastore);
}
return res;
}
| static int speech_engine_write | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| const char * | value | ||
| ) | [static] |
SPEECH_ENGINE() Dialplan Function.
Definition at line 405 of file app_speech_utils.c.
References find_speech(), and ast_speech_change().
{
struct ast_speech *speech = find_speech(chan);
if (data == NULL || speech == NULL) {
return -1;
}
ast_speech_change(speech, data, value);
return 0;
}
| static int speech_grammar | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
SPEECH_GRAMMAR() Dialplan Function.
Definition at line 379 of file app_speech_utils.c.
References find_speech(), find_result(), ast_speech::results, ast_speech_result::grammar, and ast_copy_string().
{
struct ast_speech_result *result = NULL;
struct ast_speech *speech = find_speech(chan);
if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) {
return -1;
}
if (result->grammar != NULL) {
ast_copy_string(buf, result->grammar, len);
} else {
buf[0] = '\0';
}
return 0;
}
| static int speech_load | ( | struct ast_channel * | chan, |
| const char * | vdata | ||
| ) | [static] |
SpeechLoadGrammar(Grammar Name,Path) Dialplan Application.
Definition at line 524 of file app_speech_utils.c.
References find_speech(), ast_speech::data, AST_DECLARE_APP_ARGS, args, AST_APP_ARG, ast_strdupa, AST_STANDARD_APP_ARGS, and ast_speech_grammar_load().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
char *data;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(grammar);
AST_APP_ARG(path);
);
data = ast_strdupa(vdata);
AST_STANDARD_APP_ARGS(args, data);
if (speech == NULL)
return -1;
if (args.argc != 2)
return -1;
/* Load the grammar locally on the object */
res = ast_speech_grammar_load(speech, args.grammar, args.path);
return res;
}
| static int speech_processing_sound | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechProcessingSound(Sound File) Dialplan Application.
Definition at line 609 of file app_speech_utils.c.
References find_speech(), ast_speech::processing_sound, ast_free, and ast_strdup.
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
if (speech == NULL)
return -1;
if (speech->processing_sound != NULL) {
ast_free(speech->processing_sound);
speech->processing_sound = NULL;
}
speech->processing_sound = ast_strdup(data);
return res;
}
| static int speech_read | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
SPEECH() Dialplan Function.
Definition at line 447 of file app_speech_utils.c.
References find_speech(), ast_copy_string(), ast_test_flag, AST_SPEECH_SPOKE, ast_speech::results, and AST_LIST_NEXT.
{
int results = 0;
struct ast_speech_result *result = NULL;
struct ast_speech *speech = find_speech(chan);
char tmp[128] = "";
/* Now go for the various options */
if (!strcasecmp(data, "status")) {
if (speech != NULL)
ast_copy_string(buf, "1", len);
else
ast_copy_string(buf, "0", len);
return 0;
}
/* Make sure we have a speech structure for everything else */
if (speech == NULL) {
return -1;
}
/* Check to see if they are checking for silence */
if (!strcasecmp(data, "spoke")) {
if (ast_test_flag(speech, AST_SPEECH_SPOKE))
ast_copy_string(buf, "1", len);
else
ast_copy_string(buf, "0", len);
} else if (!strcasecmp(data, "results")) {
/* Count number of results */
for (result = speech->results; result; result = AST_LIST_NEXT(result, list))
results++;
snprintf(tmp, sizeof(tmp), "%d", results);
ast_copy_string(buf, tmp, len);
} else {
buf[0] = '\0';
}
return 0;
}
| static int speech_results_type_write | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| const char * | value | ||
| ) | [static] |
SPEECH_RESULTS_TYPE() Dialplan Function.
Definition at line 425 of file app_speech_utils.c.
References find_speech(), ast_speech_change_results_type(), AST_SPEECH_RESULTS_TYPE_NORMAL, and AST_SPEECH_RESULTS_TYPE_NBEST.
{
struct ast_speech *speech = find_speech(chan);
if (data == NULL || speech == NULL)
return -1;
if (!strcasecmp(value, "normal"))
ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NORMAL);
else if (!strcasecmp(value, "nbest"))
ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NBEST);
return 0;
}
| static int speech_score | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
SPEECH_SCORE() Dialplan Function.
Definition at line 328 of file app_speech_utils.c.
References find_speech(), find_result(), ast_speech::results, ast_speech_result::score, and ast_copy_string().
{
struct ast_speech_result *result = NULL;
struct ast_speech *speech = find_speech(chan);
char tmp[128] = "";
if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) {
return -1;
}
snprintf(tmp, sizeof(tmp), "%d", result->score);
ast_copy_string(buf, tmp, len);
return 0;
}
| static int speech_start | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechStart() Dialplan Application.
Definition at line 595 of file app_speech_utils.c.
References find_speech(), and ast_speech_start().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
if (speech == NULL)
return -1;
ast_speech_start(speech);
return res;
}
| static int speech_streamfile | ( | struct ast_channel * | chan, |
| const char * | filename, | ||
| const char * | preflang | ||
| ) | [static] |
Helper function used by speech_background to playback a soundfile.
Definition at line 628 of file app_speech_utils.c.
References ast_openstream(), ast_applystream(), and ast_playstream().
Referenced by speech_background().
{
struct ast_filestream *fs = NULL;
if (!(fs = ast_openstream(chan, filename, preflang)))
return -1;
if (ast_applystream(chan, fs))
return -1;
ast_playstream(fs);
return 0;
}
| static int speech_text | ( | struct ast_channel * | chan, |
| const char * | cmd, | ||
| char * | data, | ||
| char * | buf, | ||
| size_t | len | ||
| ) | [static] |
SPEECH_TEXT() Dialplan Function.
Definition at line 353 of file app_speech_utils.c.
References find_speech(), find_result(), ast_speech::results, ast_speech_result::text, and ast_copy_string().
{
struct ast_speech_result *result = NULL;
struct ast_speech *speech = find_speech(chan);
if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) {
return -1;
}
if (result->text != NULL) {
ast_copy_string(buf, result->text, len);
} else {
buf[0] = '\0';
}
return 0;
}
| static int speech_unload | ( | struct ast_channel * | chan, |
| const char * | data | ||
| ) | [static] |
SpeechUnloadGrammar(Grammar Name) Dialplan Application.
Definition at line 550 of file app_speech_utils.c.
References find_speech(), and ast_speech_grammar_unload().
Referenced by load_module().
{
int res = 0;
struct ast_speech *speech = find_speech(chan);
if (speech == NULL)
return -1;
/* Unload the grammar */
res = ast_speech_grammar_unload(speech, data);
return res;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 925 of file app_speech_utils.c.
References ast_unregister_application(), and ast_custom_function_unregister().
{
int res = 0;
res = ast_unregister_application("SpeechCreate");
res |= ast_unregister_application("SpeechLoadGrammar");
res |= ast_unregister_application("SpeechUnloadGrammar");
res |= ast_unregister_application("SpeechActivateGrammar");
res |= ast_unregister_application("SpeechDeactivateGrammar");
res |= ast_unregister_application("SpeechStart");
res |= ast_unregister_application("SpeechBackground");
res |= ast_unregister_application("SpeechDestroy");
res |= ast_unregister_application("SpeechProcessingSound");
res |= ast_custom_function_unregister(&speech_function);
res |= ast_custom_function_unregister(&speech_score_function);
res |= ast_custom_function_unregister(&speech_text_function);
res |= ast_custom_function_unregister(&speech_grammar_function);
res |= ast_custom_function_unregister(&speech_engine_function);
res |= ast_custom_function_unregister(&speech_results_type_function);
return res;
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Dialplan Speech Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "95089850e3c922fa176f9bd274fd8109" , .load = load_module, .unload = unload_module, .nonoptreq = "res_speech", } [static] |
Definition at line 975 of file app_speech_utils.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 975 of file app_speech_utils.c.
struct ast_app_option speech_background_options[128] = { [ 'n' ] = { .flag = SB_OPT_NOANSWER }, } [static] |
Definition at line 649 of file app_speech_utils.c.
Referenced by speech_background().
struct ast_datastore_info speech_datastore [static] |
{
.type = "speech",
.destroy = destroy_callback
}
Static structure for datastore information.
Definition at line 277 of file app_speech_utils.c.
struct ast_custom_function speech_engine_function [static] |
{
.name = "SPEECH_ENGINE",
.read = NULL,
.write = speech_engine_write,
}
Definition at line 418 of file app_speech_utils.c.
struct ast_custom_function speech_function [static] |
{
.name = "SPEECH",
.read = speech_read,
.write = NULL,
}
Definition at line 488 of file app_speech_utils.c.
struct ast_custom_function speech_grammar_function [static] |
{
.name = "SPEECH_GRAMMAR",
.read = speech_grammar,
.write = NULL,
}
Definition at line 398 of file app_speech_utils.c.
struct ast_custom_function speech_results_type_function [static] |
{
.name = "SPEECH_RESULTS_TYPE",
.read = NULL,
.write = speech_results_type_write,
}
Definition at line 440 of file app_speech_utils.c.
struct ast_custom_function speech_score_function [static] |
{
.name = "SPEECH_SCORE",
.read = speech_score,
.write = NULL,
}
Definition at line 346 of file app_speech_utils.c.
struct ast_custom_function speech_text_function [static] |
{
.name = "SPEECH_TEXT",
.read = speech_text,
.write = NULL,
}
Definition at line 372 of file app_speech_utils.c.