#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: 177385 $") | |
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, void *data) |
SpeechActivateGrammar(Grammar Name) Dialplan Application. | |
static int | speech_background (struct ast_channel *chan, void *data) |
SpeechBackground(Sound File,Timeout) Dialplan Application. | |
static int | speech_create (struct ast_channel *chan, void *data) |
SpeechCreate() Dialplan Application. | |
static int | speech_deactivate (struct ast_channel *chan, void *data) |
SpeechDeactivateGrammar(Grammar Name) Dialplan Application. | |
static int | speech_destroy (struct ast_channel *chan, void *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, void *vdata) |
SpeechLoadGrammar(Grammar Name,Path) Dialplan Application. | |
static int | speech_processing_sound (struct ast_channel *chan, void *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, void *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, void *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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } |
static const 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 |
static char * | speechactivategrammar_descrip |
static char * | speechbackground_descrip |
static char * | speechcreate_descrip |
static char * | speechdeactivategrammar_descrip |
static char * | speechdestroy_descrip |
static char * | speechload_descrip |
static char * | speechprocessingsound_descrip |
static char * | speechstart_descrip |
static char * | speechunload_descrip |
Definition in file app_speech_utils.c.
anonymous enum |
Definition at line 493 of file app_speech_utils.c.
00493 { 00494 SB_OPT_NOANSWER = (1 << 0), 00495 };
static void __reg_module | ( | void | ) | [static] |
Definition at line 817 of file app_speech_utils.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 817 of file app_speech_utils.c.
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 177385 $" | ||||
) |
static void destroy_callback | ( | void * | data | ) | [static] |
Helper function used by datastores to destroy the speech structure upon hangup.
Definition at line 98 of file app_speech_utils.c.
References ast_speech_destroy().
00099 { 00100 struct ast_speech *speech = (struct ast_speech*)data; 00101 00102 if (speech == NULL) { 00103 return; 00104 } 00105 00106 /* Deallocate now */ 00107 ast_speech_destroy(speech); 00108 00109 return; 00110 }
static struct ast_speech_result* find_result | ( | struct ast_speech_result * | results, | |
char * | result_num | |||
) | [static] |
Definition at line 134 of file app_speech_utils.c.
References AST_LIST_NEXT, and ast_speech_result::nbest_num.
Referenced by speech_grammar(), speech_score(), and speech_text().
00135 { 00136 struct ast_speech_result *result = results; 00137 char *tmp = NULL; 00138 int nbest_num = 0, wanted_num = 0, i = 0; 00139 00140 if (!result) 00141 return NULL; 00142 00143 if ((tmp = strchr(result_num, '/'))) { 00144 *tmp++ = '\0'; 00145 nbest_num = atoi(result_num); 00146 wanted_num = atoi(tmp); 00147 } else { 00148 wanted_num = atoi(result_num); 00149 } 00150 00151 do { 00152 if (result->nbest_num != nbest_num) 00153 continue; 00154 if (i == wanted_num) 00155 break; 00156 i++; 00157 } while ((result = AST_LIST_NEXT(result, list))); 00158 00159 return result; 00160 }
static struct ast_speech* find_speech | ( | struct ast_channel * | chan | ) | [static] |
Helper function used to find the speech structure attached to a channel.
Definition at line 119 of file app_speech_utils.c.
References ast_channel_datastore_find(), chan, ast_datastore::data, and speech_datastore.
Referenced by speech_activate(), speech_background(), speech_deactivate(), speech_destroy(), speech_engine_write(), speech_grammar(), speech_load(), speech_processing_sound(), speech_read(), speech_results_type_write(), speech_score(), speech_start(), speech_text(), and speech_unload().
00120 { 00121 struct ast_speech *speech = NULL; 00122 struct ast_datastore *datastore = NULL; 00123 00124 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00125 if (datastore == NULL) { 00126 return NULL; 00127 } 00128 speech = datastore->data; 00129 00130 return speech; 00131 }
static int load_module | ( | void | ) | [static] |
Definition at line 794 of file app_speech_utils.c.
References ast_custom_function_register, ast_register_application, speech_activate(), speech_background(), speech_create(), speech_deactivate(), speech_destroy(), speech_engine_function, speech_function, speech_grammar_function, speech_load(), speech_processing_sound(), speech_results_type_function, speech_score_function, speech_start(), speech_text_function, speech_unload(), speechactivategrammar_descrip, speechbackground_descrip, speechcreate_descrip, speechdeactivategrammar_descrip, speechdestroy_descrip, speechload_descrip, speechprocessingsound_descrip, speechstart_descrip, and speechunload_descrip.
00795 { 00796 int res = 0; 00797 00798 res = ast_register_application("SpeechCreate", speech_create, "Create a Speech Structure", speechcreate_descrip); 00799 res |= ast_register_application("SpeechLoadGrammar", speech_load, "Load a Grammar", speechload_descrip); 00800 res |= ast_register_application("SpeechUnloadGrammar", speech_unload, "Unload a Grammar", speechunload_descrip); 00801 res |= ast_register_application("SpeechActivateGrammar", speech_activate, "Activate a Grammar", speechactivategrammar_descrip); 00802 res |= ast_register_application("SpeechDeactivateGrammar", speech_deactivate, "Deactivate a Grammar", speechdeactivategrammar_descrip); 00803 res |= ast_register_application("SpeechStart", speech_start, "Start recognizing voice in the audio stream", speechstart_descrip); 00804 res |= ast_register_application("SpeechBackground", speech_background, "Play a sound file and wait for speech to be recognized", speechbackground_descrip); 00805 res |= ast_register_application("SpeechDestroy", speech_destroy, "End speech recognition", speechdestroy_descrip); 00806 res |= ast_register_application("SpeechProcessingSound", speech_processing_sound, "Change background processing sound", speechprocessingsound_descrip); 00807 res |= ast_custom_function_register(&speech_function); 00808 res |= ast_custom_function_register(&speech_score_function); 00809 res |= ast_custom_function_register(&speech_text_function); 00810 res |= ast_custom_function_register(&speech_grammar_function); 00811 res |= ast_custom_function_register(&speech_engine_function); 00812 res |= ast_custom_function_register(&speech_results_type_function); 00813 00814 return res; 00815 }
static int speech_activate | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechActivateGrammar(Grammar Name) Dialplan Application.
Definition at line 430 of file app_speech_utils.c.
References ast_speech_grammar_activate(), chan, and find_speech().
Referenced by load_module().
00431 { 00432 int res = 0; 00433 struct ast_speech *speech = find_speech(chan); 00434 00435 if (speech == NULL) 00436 return -1; 00437 00438 /* Activate the grammar on the speech object */ 00439 res = ast_speech_grammar_activate(speech, data); 00440 00441 return res; 00442 }
static int speech_background | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechBackground(Sound File,Timeout) Dialplan Application.
Definition at line 502 of file app_speech_utils.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_calloc, ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_clear_flag, AST_CONTROL_HANGUP, AST_DECLARE_APP_ARGS, AST_FORMAT_SLINEAR, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree, AST_MAX_EXTENSION, ast_mutex_lock(), ast_mutex_unlock(), ast_read(), ast_sched_runq(), ast_sched_wait(), ast_set_read_format(), ast_speech_change_state(), ast_speech_destroy(), ast_speech_dtmf(), AST_SPEECH_QUIET, ast_speech_results_get(), ast_speech_start(), AST_SPEECH_STATE_DONE, AST_SPEECH_STATE_NOT_READY, AST_SPEECH_STATE_READY, AST_SPEECH_STATE_WAIT, ast_speech_write(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdup, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_waitfor(), chan, ast_pbx::dtimeout, f, find_speech(), ast_speech::format, ast_channel::language, ast_speech::lock, parse(), ast_channel::pbx, pbx_builtin_getvar_helper(), ast_speech::processing_sound, ast_channel::readformat, ast_speech::results, SB_OPT_NOANSWER, ast_channel::sched, speech_background_options, speech_datastore, speech_streamfile(), ast_speech::state, ast_channel::stream, ast_channel::streamid, strsep(), and ast_channel::timingfunc.
Referenced by load_module().
00503 { 00504 unsigned int timeout = 0; 00505 int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0; 00506 struct ast_speech *speech = find_speech(chan); 00507 struct ast_frame *f = NULL; 00508 int oldreadformat = AST_FORMAT_SLINEAR; 00509 char dtmf[AST_MAX_EXTENSION] = ""; 00510 time_t start, current; 00511 struct ast_datastore *datastore = NULL; 00512 char *parse, *filename_tmp = NULL, *filename = NULL, tmp[2] = "", dtmf_terminator = '#'; 00513 const char *tmp2 = NULL; 00514 struct ast_flags options = { 0 }; 00515 AST_DECLARE_APP_ARGS(args, 00516 AST_APP_ARG(soundfile); 00517 AST_APP_ARG(timeout); 00518 AST_APP_ARG(options); 00519 ); 00520 00521 parse = ast_strdupa(data); 00522 AST_STANDARD_APP_ARGS(args, parse); 00523 00524 if (speech == NULL) 00525 return -1; 00526 00527 if (!ast_strlen_zero(args.options)) { 00528 char *options_buf = ast_strdupa(args.options); 00529 ast_app_parse_options(speech_background_options, &options, NULL, options_buf); 00530 } 00531 00532 /* If channel is not already answered, then answer it */ 00533 if (chan->_state != AST_STATE_UP && !ast_test_flag(&options, SB_OPT_NOANSWER) 00534 && ast_answer(chan)) { 00535 return -1; 00536 } 00537 00538 /* Record old read format */ 00539 oldreadformat = chan->readformat; 00540 00541 /* Change read format to be signed linear */ 00542 if (ast_set_read_format(chan, speech->format)) 00543 return -1; 00544 00545 if (!ast_strlen_zero(args.soundfile)) { 00546 /* Yay sound file */ 00547 filename_tmp = ast_strdupa(args.soundfile); 00548 if (!ast_strlen_zero(args.timeout)) { 00549 if ((timeout = atoi(args.timeout)) == 0) 00550 timeout = -1; 00551 } else 00552 timeout = 0; 00553 } 00554 00555 /* See if the maximum DTMF length variable is set... we use a variable in case they want to carry it through their entire dialplan */ 00556 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_MAXLEN")) && !ast_strlen_zero(tmp2)) 00557 max_dtmf_len = atoi(tmp2); 00558 00559 /* See if a terminator is specified */ 00560 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_TERMINATOR"))) { 00561 if (ast_strlen_zero(tmp2)) 00562 dtmf_terminator = '\0'; 00563 else 00564 dtmf_terminator = tmp2[0]; 00565 } 00566 00567 /* Before we go into waiting for stuff... make sure the structure is ready, if not - start it again */ 00568 if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) { 00569 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00570 ast_speech_start(speech); 00571 } 00572 00573 /* Ensure no streams are currently running */ 00574 ast_stopstream(chan); 00575 00576 /* Okay it's streaming so go into a loop grabbing frames! */ 00577 while (done == 0) { 00578 /* If the filename is null and stream is not running, start up a new sound file */ 00579 if (!quieted && (chan->streamid == -1 && chan->timingfunc == NULL) && (filename = strsep(&filename_tmp, "&"))) { 00580 /* Discard old stream information */ 00581 ast_stopstream(chan); 00582 /* Start new stream */ 00583 speech_streamfile(chan, filename, chan->language); 00584 } 00585 00586 /* Run scheduled stuff */ 00587 ast_sched_runq(chan->sched); 00588 00589 /* Yay scheduling */ 00590 res = ast_sched_wait(chan->sched); 00591 if (res < 0) 00592 res = 1000; 00593 00594 /* If there is a frame waiting, get it - if not - oh well */ 00595 if (ast_waitfor(chan, res) > 0) { 00596 f = ast_read(chan); 00597 if (f == NULL) { 00598 /* The channel has hung up most likely */ 00599 done = 3; 00600 break; 00601 } 00602 } 00603 00604 /* Do timeout check (shared between audio/dtmf) */ 00605 if ((!quieted || strlen(dtmf)) && started == 1) { 00606 time(¤t); 00607 if ((current-start) >= timeout) { 00608 done = 1; 00609 if (f) 00610 ast_frfree(f); 00611 break; 00612 } 00613 } 00614 00615 /* Do checks on speech structure to see if it's changed */ 00616 ast_mutex_lock(&speech->lock); 00617 if (ast_test_flag(speech, AST_SPEECH_QUIET)) { 00618 if (chan->stream) 00619 ast_stopstream(chan); 00620 ast_clear_flag(speech, AST_SPEECH_QUIET); 00621 quieted = 1; 00622 } 00623 /* Check state so we can see what to do */ 00624 switch (speech->state) { 00625 case AST_SPEECH_STATE_READY: 00626 /* If audio playback has stopped do a check for timeout purposes */ 00627 if (chan->streamid == -1 && chan->timingfunc == NULL) 00628 ast_stopstream(chan); 00629 if (!quieted && chan->stream == NULL && timeout && started == 0 && !filename_tmp) { 00630 if (timeout == -1) { 00631 done = 1; 00632 if (f) 00633 ast_frfree(f); 00634 break; 00635 } 00636 time(&start); 00637 started = 1; 00638 } 00639 /* Write audio frame out to speech engine if no DTMF has been received */ 00640 if (!strlen(dtmf) && f != NULL && f->frametype == AST_FRAME_VOICE) { 00641 ast_speech_write(speech, f->data, f->datalen); 00642 } 00643 break; 00644 case AST_SPEECH_STATE_WAIT: 00645 /* Cue up waiting sound if not already playing */ 00646 if (!strlen(dtmf)) { 00647 if (chan->stream == NULL) { 00648 if (speech->processing_sound != NULL) { 00649 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound,"none")) { 00650 speech_streamfile(chan, speech->processing_sound, chan->language); 00651 } 00652 } 00653 } else if (chan->streamid == -1 && chan->timingfunc == NULL) { 00654 ast_stopstream(chan); 00655 if (speech->processing_sound != NULL) { 00656 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound,"none")) { 00657 speech_streamfile(chan, speech->processing_sound, chan->language); 00658 } 00659 } 00660 } 00661 } 00662 break; 00663 case AST_SPEECH_STATE_DONE: 00664 /* Now that we are done... let's switch back to not ready state */ 00665 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00666 if (!strlen(dtmf)) { 00667 /* Copy to speech structure the results, if available */ 00668 speech->results = ast_speech_results_get(speech); 00669 /* Break out of our background too */ 00670 done = 1; 00671 /* Stop audio playback */ 00672 if (chan->stream != NULL) { 00673 ast_stopstream(chan); 00674 } 00675 } 00676 break; 00677 default: 00678 break; 00679 } 00680 ast_mutex_unlock(&speech->lock); 00681 00682 /* Deal with other frame types */ 00683 if (f != NULL) { 00684 /* Free the frame we received */ 00685 switch (f->frametype) { 00686 case AST_FRAME_DTMF: 00687 if (dtmf_terminator != '\0' && f->subclass == dtmf_terminator) { 00688 done = 1; 00689 } else { 00690 if (chan->stream != NULL) { 00691 ast_stopstream(chan); 00692 } 00693 if (!started) { 00694 /* Change timeout to be 5 seconds for DTMF input */ 00695 timeout = (chan->pbx && chan->pbx->dtimeout) ? chan->pbx->dtimeout : 5; 00696 started = 1; 00697 } 00698 time(&start); 00699 snprintf(tmp, sizeof(tmp), "%c", f->subclass); 00700 strncat(dtmf, tmp, sizeof(dtmf) - strlen(dtmf) - 1); 00701 /* If the maximum length of the DTMF has been reached, stop now */ 00702 if (max_dtmf_len && strlen(dtmf) == max_dtmf_len) 00703 done = 1; 00704 } 00705 break; 00706 case AST_FRAME_CONTROL: 00707 switch (f->subclass) { 00708 case AST_CONTROL_HANGUP: 00709 /* Since they hung up we should destroy the speech structure */ 00710 done = 3; 00711 default: 00712 break; 00713 } 00714 default: 00715 break; 00716 } 00717 ast_frfree(f); 00718 f = NULL; 00719 } 00720 } 00721 00722 if (!ast_strlen_zero(dtmf)) { 00723 /* We sort of make a results entry */ 00724 speech->results = ast_calloc(1, sizeof(*speech->results)); 00725 if (speech->results != NULL) { 00726 ast_speech_dtmf(speech, dtmf); 00727 speech->results->score = 1000; 00728 speech->results->text = ast_strdup(dtmf); 00729 speech->results->grammar = ast_strdup("dtmf"); 00730 } 00731 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00732 } 00733 00734 /* See if it was because they hung up */ 00735 if (done == 3) { 00736 /* Destroy speech structure */ 00737 ast_speech_destroy(speech); 00738 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00739 if (datastore != NULL) 00740 ast_channel_datastore_remove(chan, datastore); 00741 } else { 00742 /* Channel is okay so restore read format */ 00743 ast_set_read_format(chan, oldreadformat); 00744 } 00745 00746 return 0; 00747 }
static int speech_create | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechCreate() Dialplan Application.
Definition at line 347 of file app_speech_utils.c.
References ast_channel_datastore_add(), ast_channel_datastore_alloc(), ast_speech_destroy(), ast_speech_new(), chan, ast_datastore::data, ast_channel::nativeformats, pbx_builtin_setvar_helper(), and speech_datastore.
Referenced by load_module().
00348 { 00349 struct ast_speech *speech = NULL; 00350 struct ast_datastore *datastore = NULL; 00351 00352 /* Request a speech object */ 00353 speech = ast_speech_new(data, chan->nativeformats); 00354 if (speech == NULL) { 00355 /* Not available */ 00356 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00357 return 0; 00358 } 00359 00360 datastore = ast_channel_datastore_alloc(&speech_datastore, NULL); 00361 if (datastore == NULL) { 00362 ast_speech_destroy(speech); 00363 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00364 return 0; 00365 } 00366 pbx_builtin_setvar_helper(chan, "ERROR", NULL); 00367 datastore->data = speech; 00368 ast_channel_datastore_add(chan, datastore); 00369 00370 return 0; 00371 }
static int speech_deactivate | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechDeactivateGrammar(Grammar Name) Dialplan Application.
Definition at line 415 of file app_speech_utils.c.
References ast_speech_grammar_deactivate(), chan, and find_speech().
Referenced by load_module().
00416 { 00417 int res = 0; 00418 struct ast_speech *speech = find_speech(chan); 00419 00420 if (speech == NULL) 00421 return -1; 00422 00423 /* Deactivate the grammar on the speech object */ 00424 res = ast_speech_grammar_deactivate(speech, data); 00425 00426 return res; 00427 }
static int speech_destroy | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechDestroy() Dialplan Application.
Definition at line 751 of file app_speech_utils.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_speech_destroy(), chan, find_speech(), and speech_datastore.
Referenced by load_module().
00752 { 00753 int res = 0; 00754 struct ast_speech *speech = find_speech(chan); 00755 struct ast_datastore *datastore = NULL; 00756 00757 if (speech == NULL) 00758 return -1; 00759 00760 /* Destroy speech structure */ 00761 ast_speech_destroy(speech); 00762 00763 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00764 if (datastore != NULL) { 00765 ast_channel_datastore_remove(chan, datastore); 00766 } 00767 00768 return res; 00769 }
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 243 of file app_speech_utils.c.
References ast_speech_change(), chan, and find_speech().
00244 { 00245 struct ast_speech *speech = find_speech(chan); 00246 00247 if (data == NULL || speech == NULL) 00248 return -1; 00249 00250 ast_speech_change(speech, data, value); 00251 00252 return 0; 00253 }
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 217 of file app_speech_utils.c.
References ast_copy_string(), chan, find_result(), find_speech(), ast_speech_result::grammar, and ast_speech::results.
00219 { 00220 struct ast_speech_result *result = NULL; 00221 struct ast_speech *speech = find_speech(chan); 00222 00223 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00224 return -1; 00225 00226 if (result->grammar != NULL) 00227 ast_copy_string(buf, result->grammar, len); 00228 00229 return 0; 00230 }
static int speech_load | ( | struct ast_channel * | chan, | |
void * | vdata | |||
) | [static] |
SpeechLoadGrammar(Grammar Name,Path) Dialplan Application.
Definition at line 374 of file app_speech_utils.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_speech_grammar_load(), AST_STANDARD_APP_ARGS, ast_strdupa, chan, ast_speech::data, and find_speech().
Referenced by load_module().
00375 { 00376 int res = 0; 00377 struct ast_speech *speech = find_speech(chan); 00378 char *data; 00379 AST_DECLARE_APP_ARGS(args, 00380 AST_APP_ARG(grammar); 00381 AST_APP_ARG(path); 00382 ); 00383 00384 data = ast_strdupa(vdata); 00385 AST_STANDARD_APP_ARGS(args, data); 00386 00387 if (speech == NULL) 00388 return -1; 00389 00390 if (args.argc != 2) 00391 return -1; 00392 00393 /* Load the grammar locally on the object */ 00394 res = ast_speech_grammar_load(speech, args.grammar, args.path); 00395 00396 return res; 00397 }
static int speech_processing_sound | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechProcessingSound(Sound File) Dialplan Application.
Definition at line 459 of file app_speech_utils.c.
References ast_free, ast_strdup, chan, find_speech(), and ast_speech::processing_sound.
Referenced by load_module().
00460 { 00461 int res = 0; 00462 struct ast_speech *speech = find_speech(chan); 00463 00464 if (speech == NULL) 00465 return -1; 00466 00467 if (speech->processing_sound != NULL) { 00468 ast_free(speech->processing_sound); 00469 speech->processing_sound = NULL; 00470 } 00471 00472 speech->processing_sound = ast_strdup(data); 00473 00474 return res; 00475 }
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 292 of file app_speech_utils.c.
References ast_copy_string(), AST_LIST_NEXT, AST_SPEECH_SPOKE, ast_test_flag, chan, find_speech(), and ast_speech::results.
00294 { 00295 int results = 0; 00296 struct ast_speech_result *result = NULL; 00297 struct ast_speech *speech = find_speech(chan); 00298 char tmp[128] = ""; 00299 00300 /* Now go for the various options */ 00301 if (!strcasecmp(data, "status")) { 00302 if (speech != NULL) 00303 ast_copy_string(buf, "1", len); 00304 else 00305 ast_copy_string(buf, "0", len); 00306 return 0; 00307 } 00308 00309 /* Make sure we have a speech structure for everything else */ 00310 if (speech == NULL) { 00311 return -1; 00312 } 00313 00314 /* Check to see if they are checking for silence */ 00315 if (!strcasecmp(data, "spoke")) { 00316 if (ast_test_flag(speech, AST_SPEECH_SPOKE)) 00317 ast_copy_string(buf, "1", len); 00318 else 00319 ast_copy_string(buf, "0", len); 00320 } else if (!strcasecmp(data, "results")) { 00321 /* Count number of results */ 00322 for (result = speech->results; result; result = AST_LIST_NEXT(result, list)) 00323 results++; 00324 snprintf(tmp, sizeof(tmp), "%d", results); 00325 ast_copy_string(buf, tmp, len); 00326 } 00327 00328 return 0; 00329 }
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 266 of file app_speech_utils.c.
References ast_speech_change_results_type(), AST_SPEECH_RESULTS_TYPE_NBEST, AST_SPEECH_RESULTS_TYPE_NORMAL, chan, and find_speech().
00267 { 00268 struct ast_speech *speech = find_speech(chan); 00269 00270 if (data == NULL || speech == NULL) 00271 return -1; 00272 00273 if (!strcasecmp(value, "normal")) 00274 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NORMAL); 00275 else if (!strcasecmp(value, "nbest")) 00276 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NBEST); 00277 00278 return 0; 00279 }
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 163 of file app_speech_utils.c.
References ast_copy_string(), chan, find_result(), find_speech(), ast_speech::results, and ast_speech_result::score.
00165 { 00166 struct ast_speech_result *result = NULL; 00167 struct ast_speech *speech = find_speech(chan); 00168 char tmp[128] = ""; 00169 00170 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00171 return -1; 00172 00173 snprintf(tmp, sizeof(tmp), "%d", result->score); 00174 00175 ast_copy_string(buf, tmp, len); 00176 00177 return 0; 00178 }
static int speech_start | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechStart() Dialplan Application.
Definition at line 445 of file app_speech_utils.c.
References ast_speech_start(), chan, and find_speech().
Referenced by load_module().
00446 { 00447 int res = 0; 00448 struct ast_speech *speech = find_speech(chan); 00449 00450 if (speech == NULL) 00451 return -1; 00452 00453 ast_speech_start(speech); 00454 00455 return res; 00456 }
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 478 of file app_speech_utils.c.
References ast_applystream(), ast_openstream(), ast_playstream(), and chan.
Referenced by handle_speechrecognize(), and speech_background().
00479 { 00480 struct ast_filestream *fs = NULL; 00481 00482 if (!(fs = ast_openstream(chan, filename, preflang))) 00483 return -1; 00484 00485 if (ast_applystream(chan, fs)) 00486 return -1; 00487 00488 ast_playstream(fs); 00489 00490 return 0; 00491 }
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 191 of file app_speech_utils.c.
References ast_copy_string(), chan, find_result(), find_speech(), ast_speech::results, and ast_speech_result::text.
00193 { 00194 struct ast_speech_result *result = NULL; 00195 struct ast_speech *speech = find_speech(chan); 00196 00197 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00198 return -1; 00199 00200 if (result->text != NULL) 00201 ast_copy_string(buf, result->text, len); 00202 00203 return 0; 00204 }
static int speech_unload | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechUnloadGrammar(Grammar Name) Dialplan Application.
Definition at line 400 of file app_speech_utils.c.
References ast_speech_grammar_unload(), chan, and find_speech().
Referenced by load_module().
00401 { 00402 int res = 0; 00403 struct ast_speech *speech = find_speech(chan); 00404 00405 if (speech == NULL) 00406 return -1; 00407 00408 /* Unload the grammar */ 00409 res = ast_speech_grammar_unload(speech, data); 00410 00411 return res; 00412 }
static int unload_module | ( | void | ) | [static] |
Definition at line 771 of file app_speech_utils.c.
References ast_custom_function_unregister(), ast_unregister_application(), speech_engine_function, speech_function, speech_grammar_function, speech_results_type_function, speech_score_function, and speech_text_function.
00772 { 00773 int res = 0; 00774 00775 res = ast_unregister_application("SpeechCreate"); 00776 res |= ast_unregister_application("SpeechLoadGrammar"); 00777 res |= ast_unregister_application("SpeechUnloadGrammar"); 00778 res |= ast_unregister_application("SpeechActivateGrammar"); 00779 res |= ast_unregister_application("SpeechDeactivateGrammar"); 00780 res |= ast_unregister_application("SpeechStart"); 00781 res |= ast_unregister_application("SpeechBackground"); 00782 res |= ast_unregister_application("SpeechDestroy"); 00783 res |= ast_unregister_application("SpeechProcessingSound"); 00784 res |= ast_custom_function_unregister(&speech_function); 00785 res |= ast_custom_function_unregister(&speech_score_function); 00786 res |= ast_custom_function_unregister(&speech_text_function); 00787 res |= ast_custom_function_unregister(&speech_grammar_function); 00788 res |= ast_custom_function_unregister(&speech_engine_function); 00789 res |= ast_custom_function_unregister(&speech_results_type_function); 00790 00791 return res; 00792 }
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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 817 of file app_speech_utils.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 817 of file app_speech_utils.c.
struct ast_app_option speech_background_options[128] = { [ 'n' ] = { .flag = SB_OPT_NOANSWER }, } [static] |
struct ast_datastore_info speech_datastore [static] |
Initial value:
{ .type = "speech", .destroy = destroy_callback }
Definition at line 113 of file app_speech_utils.c.
Referenced by find_speech(), speech_background(), speech_create(), and speech_destroy().
struct ast_custom_function speech_engine_function [static] |
Definition at line 255 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_function [static] |
Definition at line 331 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_grammar_function [static] |
Definition at line 232 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_results_type_function [static] |
Definition at line 281 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_score_function [static] |
Definition at line 180 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_text_function [static] |
Definition at line 206 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
char* speechactivategrammar_descrip [static] |
Initial value:
" SpeechActivateGrammar(Grammar Name):\n" "This activates the specified grammar to be recognized by the engine.\n" "A grammar tells the speech recognition engine what to recognize, and how to portray it back to you \n" "in the dialplan. The grammar name is the only argument to this application.\n"
Definition at line 47 of file app_speech_utils.c.
Referenced by load_module().
char* speechbackground_descrip [static] |
char* speechcreate_descrip [static] |
Initial value:
" SpeechCreate(engine name):\n" "This application creates information to be used by all the other applications.\n" "It must be called before doing any speech recognition activities such as activating a grammar.\n" "It takes the engine name to use as the argument, if not specified the default engine will be used.\n"
Definition at line 41 of file app_speech_utils.c.
Referenced by load_module().
char* speechdeactivategrammar_descrip [static] |
Initial value:
" SpeechDeactivateGrammar(Grammar Name):\n" "This deactivates the specified grammar so that it is no longer recognized.\n" "The only argument is the grammar name to deactivate.\n"
Definition at line 71 of file app_speech_utils.c.
Referenced by load_module().
char* speechdestroy_descrip [static] |
Initial value:
" SpeechDestroy():\n" "This destroys the information used by all the other speech recognition applications.\n" "If you call this application but end up wanting to recognize more speech, you must call SpeechCreate\n" "again before calling any other application. It takes no arguments.\n"
Definition at line 82 of file app_speech_utils.c.
Referenced by load_module().
char* speechload_descrip [static] |
Initial value:
" SpeechLoadGrammar(Grammar Name,Path):\n" "Load a grammar only on the channel, not globally.\n" "It takes the grammar name as first argument and path as second.\n"
Definition at line 88 of file app_speech_utils.c.
Referenced by load_module().
char* speechprocessingsound_descrip [static] |
Initial value:
" SpeechProcessingSound(Sound File):\n" "This changes the processing sound that SpeechBackground plays back when the speech recognition engine is\n" "processing and working to get results.\n" "It takes the sound file as the only argument.\n"
Definition at line 76 of file app_speech_utils.c.
Referenced by load_module().
char* speechstart_descrip [static] |
Initial value:
" SpeechStart():\n" "Tell the speech recognition engine that it should start trying to get results from audio being \n" "fed to it. This has no arguments.\n"
Definition at line 53 of file app_speech_utils.c.
Referenced by load_module().
char* speechunload_descrip [static] |
Initial value:
" SpeechUnloadGrammar(Grammar Name):\n" "Unload a grammar. It takes the grammar name as the only argument.\n"
Definition at line 93 of file app_speech_utils.c.
Referenced by load_module().