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 | |
AST_APP_OPTIONS (speech_background_options, BEGIN_OPTIONS AST_APP_OPTION('n', SB_OPT_NOANSWER), END_OPTIONS) | |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Dialplan Speech Applications",.load=load_module,.unload=unload_module,.nonoptreq="res_speech",) | |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 419684 $") | |
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_datastore_destroy (struct ast_channel *chan) |
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_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 680 of file app_speech_utils.c.
00680 { 00681 SB_OPT_NOANSWER = (1 << 0), 00682 };
AST_APP_OPTIONS | ( | speech_background_options | , | |
BEGIN_OPTIONS | AST_APP_OPTION'n', SB_OPT_NOANSWER, | |||
END_OPTIONS | ||||
) |
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_DEFAULT | , | |||
"Dialplan Speech Applications" | , | |||
. | load = load_module , |
|||
. | unload = unload_module , |
|||
. | nonoptreq = "res_speech" | |||
) |
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 419684 $" | ||||
) |
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().
00263 { 00264 struct ast_speech *speech = (struct ast_speech*)data; 00265 00266 if (speech == NULL) { 00267 return; 00268 } 00269 00270 /* Deallocate now */ 00271 ast_speech_destroy(speech); 00272 00273 return; 00274 }
static struct ast_speech_result* find_result | ( | struct ast_speech_result * | results, | |
char * | result_num | |||
) | [static, read] |
Definition at line 333 of file app_speech_utils.c.
References AST_LIST_NEXT, ast_speech_result::list, and ast_speech_result::nbest_num.
Referenced by speech_grammar(), speech_score(), and speech_text().
00334 { 00335 struct ast_speech_result *result = results; 00336 char *tmp = NULL; 00337 int nbest_num = 0, wanted_num = 0, i = 0; 00338 00339 if (!result) { 00340 return NULL; 00341 } 00342 00343 if ((tmp = strchr(result_num, '/'))) { 00344 *tmp++ = '\0'; 00345 nbest_num = atoi(result_num); 00346 wanted_num = atoi(tmp); 00347 } else { 00348 wanted_num = atoi(result_num); 00349 } 00350 00351 do { 00352 if (result->nbest_num != nbest_num) 00353 continue; 00354 if (i == wanted_num) 00355 break; 00356 i++; 00357 } while ((result = AST_LIST_NEXT(result, list))); 00358 00359 return result; 00360 }
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(), ast_channel_lock, ast_channel_unlock, and ast_datastore::data.
Referenced by speech_activate(), speech_background(), speech_deactivate(), 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().
00284 { 00285 struct ast_speech *speech = NULL; 00286 struct ast_datastore *datastore = NULL; 00287 00288 if (!chan) { 00289 return NULL; 00290 } 00291 00292 ast_channel_lock(chan); 00293 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00294 ast_channel_unlock(chan); 00295 if (datastore == NULL) { 00296 return NULL; 00297 } 00298 speech = datastore->data; 00299 00300 return speech; 00301 }
static int load_module | ( | void | ) | [static] |
Definition at line 968 of file app_speech_utils.c.
References ast_custom_function_register, ast_register_application_xml, speech_activate(), speech_background(), speech_create(), speech_deactivate(), speech_destroy(), speech_load(), speech_processing_sound(), speech_start(), and speech_unload().
00969 { 00970 int res = 0; 00971 00972 res = ast_register_application_xml("SpeechCreate", speech_create); 00973 res |= ast_register_application_xml("SpeechLoadGrammar", speech_load); 00974 res |= ast_register_application_xml("SpeechUnloadGrammar", speech_unload); 00975 res |= ast_register_application_xml("SpeechActivateGrammar", speech_activate); 00976 res |= ast_register_application_xml("SpeechDeactivateGrammar", speech_deactivate); 00977 res |= ast_register_application_xml("SpeechStart", speech_start); 00978 res |= ast_register_application_xml("SpeechBackground", speech_background); 00979 res |= ast_register_application_xml("SpeechDestroy", speech_destroy); 00980 res |= ast_register_application_xml("SpeechProcessingSound", speech_processing_sound); 00981 res |= ast_custom_function_register(&speech_function); 00982 res |= ast_custom_function_register(&speech_score_function); 00983 res |= ast_custom_function_register(&speech_text_function); 00984 res |= ast_custom_function_register(&speech_grammar_function); 00985 res |= ast_custom_function_register(&speech_engine_function); 00986 res |= ast_custom_function_register(&speech_results_type_function); 00987 00988 return res; 00989 }
static int speech_activate | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechActivateGrammar(Grammar Name) Dialplan Application.
Definition at line 617 of file app_speech_utils.c.
References ast_speech_grammar_activate(), and find_speech().
Referenced by load_module().
00618 { 00619 int res = 0; 00620 struct ast_speech *speech = find_speech(chan); 00621 00622 if (speech == NULL) 00623 return -1; 00624 00625 /* Activate the grammar on the speech object */ 00626 res = ast_speech_grammar_activate(speech, data); 00627 00628 return res; 00629 }
static int speech_background | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechBackground(Sound File,Timeout) Dialplan Application.
Definition at line 689 of file app_speech_utils.c.
References ast_channel::_state, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_calloc, ast_channel_lock, ast_channel_unlock, 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_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_tvdiff_ms(), ast_tvnow(), ast_waitfor(), ast_frame::data, ast_frame::datalen, ast_pbx::dtimeoutms, f, find_speech(), ast_speech::format, ast_frame::frametype, ast_speech_result::grammar, ast_frame_subclass::integer, ast_speech::lock, parse(), ast_channel::pbx, pbx_builtin_getvar_helper(), ast_speech::processing_sound, ast_frame::ptr, ast_channel::readformat, ast_speech::results, SB_OPT_NOANSWER, ast_channel::sched, ast_speech_result::score, speech_datastore_destroy(), speech_streamfile(), ast_speech::state, ast_channel::stream, ast_channel::streamid, ast_frame::subclass, ast_speech_result::text, and ast_channel::timingfunc.
Referenced by load_module().
00690 { 00691 unsigned int timeout = 0; 00692 int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0; 00693 struct ast_speech *speech = find_speech(chan); 00694 struct ast_frame *f = NULL; 00695 int oldreadformat = AST_FORMAT_SLINEAR; 00696 char dtmf[AST_MAX_EXTENSION] = ""; 00697 struct timeval start = { 0, 0 }, current; 00698 char *parse, *filename_tmp = NULL, *filename = NULL, tmp[2] = "", dtmf_terminator = '#'; 00699 const char *tmp2 = NULL; 00700 struct ast_flags options = { 0 }; 00701 AST_DECLARE_APP_ARGS(args, 00702 AST_APP_ARG(soundfile); 00703 AST_APP_ARG(timeout); 00704 AST_APP_ARG(options); 00705 ); 00706 00707 parse = ast_strdupa(data); 00708 AST_STANDARD_APP_ARGS(args, parse); 00709 00710 if (speech == NULL) 00711 return -1; 00712 00713 if (!ast_strlen_zero(args.options)) { 00714 char *options_buf = ast_strdupa(args.options); 00715 ast_app_parse_options(speech_background_options, &options, NULL, options_buf); 00716 } 00717 00718 /* If channel is not already answered, then answer it */ 00719 if (chan->_state != AST_STATE_UP && !ast_test_flag(&options, SB_OPT_NOANSWER) 00720 && ast_answer(chan)) { 00721 return -1; 00722 } 00723 00724 /* Record old read format */ 00725 oldreadformat = chan->readformat; 00726 00727 /* Change read format to be signed linear */ 00728 if (ast_set_read_format(chan, speech->format)) 00729 return -1; 00730 00731 if (!ast_strlen_zero(args.soundfile)) { 00732 /* Yay sound file */ 00733 filename_tmp = ast_strdupa(args.soundfile); 00734 if (!ast_strlen_zero(args.timeout)) { 00735 if ((timeout = atof(args.timeout) * 1000.0) == 0) 00736 timeout = -1; 00737 } else 00738 timeout = 0; 00739 } 00740 00741 /* See if the maximum DTMF length variable is set... we use a variable in case they want to carry it through their entire dialplan */ 00742 ast_channel_lock(chan); 00743 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_MAXLEN")) && !ast_strlen_zero(tmp2)) { 00744 max_dtmf_len = atoi(tmp2); 00745 } 00746 00747 /* See if a terminator is specified */ 00748 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_TERMINATOR"))) { 00749 if (ast_strlen_zero(tmp2)) 00750 dtmf_terminator = '\0'; 00751 else 00752 dtmf_terminator = tmp2[0]; 00753 } 00754 ast_channel_unlock(chan); 00755 00756 /* Before we go into waiting for stuff... make sure the structure is ready, if not - start it again */ 00757 if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) { 00758 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00759 ast_speech_start(speech); 00760 } 00761 00762 /* Ensure no streams are currently running */ 00763 ast_stopstream(chan); 00764 00765 /* Okay it's streaming so go into a loop grabbing frames! */ 00766 while (done == 0) { 00767 /* If the filename is null and stream is not running, start up a new sound file */ 00768 if (!quieted && (chan->streamid == -1 && chan->timingfunc == NULL) && (filename = strsep(&filename_tmp, "&"))) { 00769 /* Discard old stream information */ 00770 ast_stopstream(chan); 00771 /* Start new stream */ 00772 speech_streamfile(chan, filename, chan->language); 00773 } 00774 00775 /* Run scheduled stuff */ 00776 ast_sched_runq(chan->sched); 00777 00778 /* Yay scheduling */ 00779 res = ast_sched_wait(chan->sched); 00780 if (res < 0) 00781 res = 1000; 00782 00783 /* If there is a frame waiting, get it - if not - oh well */ 00784 if (ast_waitfor(chan, res) > 0) { 00785 f = ast_read(chan); 00786 if (f == NULL) { 00787 /* The channel has hung up most likely */ 00788 done = 3; 00789 break; 00790 } 00791 } 00792 00793 /* Do timeout check (shared between audio/dtmf) */ 00794 if ((!quieted || strlen(dtmf)) && started == 1) { 00795 current = ast_tvnow(); 00796 if ((ast_tvdiff_ms(current, start)) >= timeout) { 00797 done = 1; 00798 if (f) 00799 ast_frfree(f); 00800 break; 00801 } 00802 } 00803 00804 /* Do checks on speech structure to see if it's changed */ 00805 ast_mutex_lock(&speech->lock); 00806 if (ast_test_flag(speech, AST_SPEECH_QUIET)) { 00807 if (chan->stream) 00808 ast_stopstream(chan); 00809 ast_clear_flag(speech, AST_SPEECH_QUIET); 00810 quieted = 1; 00811 } 00812 /* Check state so we can see what to do */ 00813 switch (speech->state) { 00814 case AST_SPEECH_STATE_READY: 00815 /* If audio playback has stopped do a check for timeout purposes */ 00816 if (chan->streamid == -1 && chan->timingfunc == NULL) 00817 ast_stopstream(chan); 00818 if (!quieted && chan->stream == NULL && timeout && started == 0 && !filename_tmp) { 00819 if (timeout == -1) { 00820 done = 1; 00821 if (f) 00822 ast_frfree(f); 00823 break; 00824 } 00825 start = ast_tvnow(); 00826 started = 1; 00827 } 00828 /* Write audio frame out to speech engine if no DTMF has been received */ 00829 if (!strlen(dtmf) && f != NULL && f->frametype == AST_FRAME_VOICE) { 00830 ast_speech_write(speech, f->data.ptr, f->datalen); 00831 } 00832 break; 00833 case AST_SPEECH_STATE_WAIT: 00834 /* Cue up waiting sound if not already playing */ 00835 if (!strlen(dtmf)) { 00836 if (chan->stream == NULL) { 00837 if (speech->processing_sound != NULL) { 00838 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound, "none")) { 00839 speech_streamfile(chan, speech->processing_sound, chan->language); 00840 } 00841 } 00842 } else if (chan->streamid == -1 && chan->timingfunc == NULL) { 00843 ast_stopstream(chan); 00844 if (speech->processing_sound != NULL) { 00845 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound, "none")) { 00846 speech_streamfile(chan, speech->processing_sound, chan->language); 00847 } 00848 } 00849 } 00850 } 00851 break; 00852 case AST_SPEECH_STATE_DONE: 00853 /* Now that we are done... let's switch back to not ready state */ 00854 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00855 if (!strlen(dtmf)) { 00856 /* Copy to speech structure the results, if available */ 00857 speech->results = ast_speech_results_get(speech); 00858 /* Break out of our background too */ 00859 done = 1; 00860 /* Stop audio playback */ 00861 if (chan->stream != NULL) { 00862 ast_stopstream(chan); 00863 } 00864 } 00865 break; 00866 default: 00867 break; 00868 } 00869 ast_mutex_unlock(&speech->lock); 00870 00871 /* Deal with other frame types */ 00872 if (f != NULL) { 00873 /* Free the frame we received */ 00874 switch (f->frametype) { 00875 case AST_FRAME_DTMF: 00876 if (dtmf_terminator != '\0' && f->subclass.integer == dtmf_terminator) { 00877 done = 1; 00878 } else { 00879 quieted = 1; 00880 if (chan->stream != NULL) { 00881 ast_stopstream(chan); 00882 } 00883 if (!started) { 00884 /* Change timeout to be 5 seconds for DTMF input */ 00885 timeout = (chan->pbx && chan->pbx->dtimeoutms) ? chan->pbx->dtimeoutms : 5000; 00886 started = 1; 00887 } 00888 start = ast_tvnow(); 00889 snprintf(tmp, sizeof(tmp), "%c", f->subclass.integer); 00890 strncat(dtmf, tmp, sizeof(dtmf) - strlen(dtmf) - 1); 00891 /* If the maximum length of the DTMF has been reached, stop now */ 00892 if (max_dtmf_len && strlen(dtmf) == max_dtmf_len) 00893 done = 1; 00894 } 00895 break; 00896 case AST_FRAME_CONTROL: 00897 switch (f->subclass.integer) { 00898 case AST_CONTROL_HANGUP: 00899 /* Since they hung up we should destroy the speech structure */ 00900 done = 3; 00901 default: 00902 break; 00903 } 00904 default: 00905 break; 00906 } 00907 ast_frfree(f); 00908 f = NULL; 00909 } 00910 } 00911 00912 if (!ast_strlen_zero(dtmf)) { 00913 /* We sort of make a results entry */ 00914 speech->results = ast_calloc(1, sizeof(*speech->results)); 00915 if (speech->results != NULL) { 00916 ast_speech_dtmf(speech, dtmf); 00917 speech->results->score = 1000; 00918 speech->results->text = ast_strdup(dtmf); 00919 speech->results->grammar = ast_strdup("dtmf"); 00920 } 00921 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00922 } 00923 00924 /* See if it was because they hung up */ 00925 if (done == 3) { 00926 speech_datastore_destroy(chan); 00927 } else { 00928 /* Channel is okay so restore read format */ 00929 ast_set_read_format(chan, oldreadformat); 00930 } 00931 00932 return 0; 00933 }
static int speech_create | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechCreate() Dialplan Application.
Definition at line 532 of file app_speech_utils.c.
References ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_speech_destroy(), ast_speech_new(), ast_datastore::data, ast_channel::nativeformats, and pbx_builtin_setvar_helper().
Referenced by load_module().
00533 { 00534 struct ast_speech *speech = NULL; 00535 struct ast_datastore *datastore = NULL; 00536 00537 /* Request a speech object */ 00538 speech = ast_speech_new(data, chan->nativeformats); 00539 if (speech == NULL) { 00540 /* Not available */ 00541 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00542 return 0; 00543 } 00544 00545 datastore = ast_datastore_alloc(&speech_datastore, NULL); 00546 if (datastore == NULL) { 00547 ast_speech_destroy(speech); 00548 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00549 return 0; 00550 } 00551 pbx_builtin_setvar_helper(chan, "ERROR", NULL); 00552 datastore->data = speech; 00553 ast_channel_lock(chan); 00554 ast_channel_datastore_add(chan, datastore); 00555 ast_channel_unlock(chan); 00556 00557 return 0; 00558 }
static int speech_datastore_destroy | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 312 of file app_speech_utils.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, and ast_datastore_free().
Referenced by speech_background(), and speech_destroy().
00313 { 00314 struct ast_datastore *datastore; 00315 int res; 00316 00317 ast_channel_lock(chan); 00318 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00319 if (datastore) { 00320 ast_channel_datastore_remove(chan, datastore); 00321 } 00322 ast_channel_unlock(chan); 00323 if (datastore) { 00324 ast_datastore_free(datastore); 00325 res = 0; 00326 } else { 00327 res = -1; 00328 } 00329 return res; 00330 }
static int speech_deactivate | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechDeactivateGrammar(Grammar Name) Dialplan Application.
Definition at line 602 of file app_speech_utils.c.
References ast_speech_grammar_deactivate(), and find_speech().
Referenced by load_module().
00603 { 00604 int res = 0; 00605 struct ast_speech *speech = find_speech(chan); 00606 00607 if (speech == NULL) 00608 return -1; 00609 00610 /* Deactivate the grammar on the speech object */ 00611 res = ast_speech_grammar_deactivate(speech, data); 00612 00613 return res; 00614 }
static int speech_destroy | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechDestroy() Dialplan Application.
Definition at line 937 of file app_speech_utils.c.
References speech_datastore_destroy().
Referenced by load_module().
00938 { 00939 if (!chan) { 00940 return -1; 00941 } 00942 return speech_datastore_destroy(chan); 00943 }
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 440 of file app_speech_utils.c.
References ast_speech_change(), and find_speech().
00441 { 00442 struct ast_speech *speech = find_speech(chan); 00443 00444 if (data == NULL || speech == NULL) { 00445 return -1; 00446 } 00447 00448 ast_speech_change(speech, data, value); 00449 00450 return 0; 00451 }
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 414 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech_result::grammar, and ast_speech::results.
00416 { 00417 struct ast_speech_result *result = NULL; 00418 struct ast_speech *speech = find_speech(chan); 00419 00420 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) { 00421 return -1; 00422 } 00423 00424 if (result->grammar != NULL) { 00425 ast_copy_string(buf, result->grammar, len); 00426 } else { 00427 buf[0] = '\0'; 00428 } 00429 00430 return 0; 00431 }
static int speech_load | ( | struct ast_channel * | chan, | |
const char * | vdata | |||
) | [static] |
SpeechLoadGrammar(Grammar Name,Path) Dialplan Application.
Definition at line 561 of file app_speech_utils.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_speech_grammar_load(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_speech::data, and find_speech().
Referenced by load_module().
00562 { 00563 int res = 0; 00564 struct ast_speech *speech = find_speech(chan); 00565 char *data; 00566 AST_DECLARE_APP_ARGS(args, 00567 AST_APP_ARG(grammar); 00568 AST_APP_ARG(path); 00569 ); 00570 00571 data = ast_strdupa(vdata); 00572 AST_STANDARD_APP_ARGS(args, data); 00573 00574 if (speech == NULL) 00575 return -1; 00576 00577 if (args.argc != 2) 00578 return -1; 00579 00580 /* Load the grammar locally on the object */ 00581 res = ast_speech_grammar_load(speech, args.grammar, args.path); 00582 00583 return res; 00584 }
static int speech_processing_sound | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechProcessingSound(Sound File) Dialplan Application.
Definition at line 646 of file app_speech_utils.c.
References ast_free, ast_strdup, find_speech(), and ast_speech::processing_sound.
Referenced by load_module().
00647 { 00648 int res = 0; 00649 struct ast_speech *speech = find_speech(chan); 00650 00651 if (speech == NULL) 00652 return -1; 00653 00654 if (speech->processing_sound != NULL) { 00655 ast_free(speech->processing_sound); 00656 speech->processing_sound = NULL; 00657 } 00658 00659 speech->processing_sound = ast_strdup(data); 00660 00661 return res; 00662 }
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 482 of file app_speech_utils.c.
References ast_copy_string(), AST_LIST_NEXT, AST_SPEECH_SPOKE, ast_test_flag, find_speech(), and ast_speech::results.
00484 { 00485 int results = 0; 00486 struct ast_speech_result *result = NULL; 00487 struct ast_speech *speech = find_speech(chan); 00488 char tmp[128] = ""; 00489 00490 /* Now go for the various options */ 00491 if (!strcasecmp(data, "status")) { 00492 if (speech != NULL) 00493 ast_copy_string(buf, "1", len); 00494 else 00495 ast_copy_string(buf, "0", len); 00496 return 0; 00497 } 00498 00499 /* Make sure we have a speech structure for everything else */ 00500 if (speech == NULL) { 00501 return -1; 00502 } 00503 00504 /* Check to see if they are checking for silence */ 00505 if (!strcasecmp(data, "spoke")) { 00506 if (ast_test_flag(speech, AST_SPEECH_SPOKE)) 00507 ast_copy_string(buf, "1", len); 00508 else 00509 ast_copy_string(buf, "0", len); 00510 } else if (!strcasecmp(data, "results")) { 00511 /* Count number of results */ 00512 for (result = speech->results; result; result = AST_LIST_NEXT(result, list)) 00513 results++; 00514 snprintf(tmp, sizeof(tmp), "%d", results); 00515 ast_copy_string(buf, tmp, len); 00516 } else { 00517 buf[0] = '\0'; 00518 } 00519 00520 return 0; 00521 }
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 460 of file app_speech_utils.c.
References ast_speech_change_results_type(), AST_SPEECH_RESULTS_TYPE_NBEST, AST_SPEECH_RESULTS_TYPE_NORMAL, and find_speech().
00461 { 00462 struct ast_speech *speech = find_speech(chan); 00463 00464 if (data == NULL || speech == NULL) 00465 return -1; 00466 00467 if (!strcasecmp(value, "normal")) 00468 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NORMAL); 00469 else if (!strcasecmp(value, "nbest")) 00470 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NBEST); 00471 00472 return 0; 00473 }
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 363 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech::results, and ast_speech_result::score.
00365 { 00366 struct ast_speech_result *result = NULL; 00367 struct ast_speech *speech = find_speech(chan); 00368 char tmp[128] = ""; 00369 00370 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) { 00371 return -1; 00372 } 00373 00374 snprintf(tmp, sizeof(tmp), "%d", result->score); 00375 00376 ast_copy_string(buf, tmp, len); 00377 00378 return 0; 00379 }
static int speech_start | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechStart() Dialplan Application.
Definition at line 632 of file app_speech_utils.c.
References ast_speech_start(), and find_speech().
Referenced by load_module().
00633 { 00634 int res = 0; 00635 struct ast_speech *speech = find_speech(chan); 00636 00637 if (speech == NULL) 00638 return -1; 00639 00640 ast_speech_start(speech); 00641 00642 return res; 00643 }
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 665 of file app_speech_utils.c.
References ast_applystream(), ast_openstream(), and ast_playstream().
Referenced by speech_background().
00666 { 00667 struct ast_filestream *fs = NULL; 00668 00669 if (!(fs = ast_openstream(chan, filename, preflang))) 00670 return -1; 00671 00672 if (ast_applystream(chan, fs)) 00673 return -1; 00674 00675 ast_playstream(fs); 00676 00677 return 0; 00678 }
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 388 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech::results, and ast_speech_result::text.
00390 { 00391 struct ast_speech_result *result = NULL; 00392 struct ast_speech *speech = find_speech(chan); 00393 00394 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) { 00395 return -1; 00396 } 00397 00398 if (result->text != NULL) { 00399 ast_copy_string(buf, result->text, len); 00400 } else { 00401 buf[0] = '\0'; 00402 } 00403 00404 return 0; 00405 }
static int speech_unload | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
SpeechUnloadGrammar(Grammar Name) Dialplan Application.
Definition at line 587 of file app_speech_utils.c.
References ast_speech_grammar_unload(), and find_speech().
Referenced by load_module().
00588 { 00589 int res = 0; 00590 struct ast_speech *speech = find_speech(chan); 00591 00592 if (speech == NULL) 00593 return -1; 00594 00595 /* Unload the grammar */ 00596 res = ast_speech_grammar_unload(speech, data); 00597 00598 return res; 00599 }
static int unload_module | ( | void | ) | [static] |
Definition at line 945 of file app_speech_utils.c.
References ast_custom_function_unregister(), and ast_unregister_application().
00946 { 00947 int res = 0; 00948 00949 res = ast_unregister_application("SpeechCreate"); 00950 res |= ast_unregister_application("SpeechLoadGrammar"); 00951 res |= ast_unregister_application("SpeechUnloadGrammar"); 00952 res |= ast_unregister_application("SpeechActivateGrammar"); 00953 res |= ast_unregister_application("SpeechDeactivateGrammar"); 00954 res |= ast_unregister_application("SpeechStart"); 00955 res |= ast_unregister_application("SpeechBackground"); 00956 res |= ast_unregister_application("SpeechDestroy"); 00957 res |= ast_unregister_application("SpeechProcessingSound"); 00958 res |= ast_custom_function_unregister(&speech_function); 00959 res |= ast_custom_function_unregister(&speech_score_function); 00960 res |= ast_custom_function_unregister(&speech_text_function); 00961 res |= ast_custom_function_unregister(&speech_grammar_function); 00962 res |= ast_custom_function_unregister(&speech_engine_function); 00963 res |= ast_custom_function_unregister(&speech_results_type_function); 00964 00965 return res; 00966 }
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 453 of file app_speech_utils.c.
struct ast_custom_function speech_function [static] |
{ .name = "SPEECH", .read = speech_read, .write = NULL, }
Definition at line 523 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 433 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 475 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 381 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 407 of file app_speech_utils.c.