#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.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.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
ASTERISK_FILE_VERSION (__FILE__,"$Revision: 264334 $") | |
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, char *cmd, char *data, const char *value) |
SPEECH_ENGINE() Dialplan Function. | |
static int | speech_grammar (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
SPEECH_GRAMMAR() Dialplan Function. | |
static int | speech_load (struct ast_channel *chan, void *data) |
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, char *cmd, char *data, char *buf, size_t len) |
SPEECH() Dialplan Function. | |
static int | speech_results_type_write (struct ast_channel *chan, char *cmd, char *data, const char *value) |
SPEECH_RESULTS_TYPE() Dialplan Function. | |
static int | speech_score (struct ast_channel *chan, 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, 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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
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.
static void __reg_module | ( | void | ) | [static] |
Definition at line 878 of file app_speech_utils.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 878 of file app_speech_utils.c.
ASTERISK_FILE_VERSION | ( | __FILE__ | , | |
"$Revision: 264334 $" | ||||
) |
static void destroy_callback | ( | void * | data | ) | [static] |
Helper function used by datastores to destroy the speech structure upon hangup.
Definition at line 94 of file app_speech_utils.c.
References ast_speech_destroy().
00095 { 00096 struct ast_speech *speech = (struct ast_speech*)data; 00097 00098 if (speech == NULL) { 00099 return; 00100 } 00101 00102 /* Deallocate now */ 00103 ast_speech_destroy(speech); 00104 00105 return; 00106 }
static struct ast_speech_result* find_result | ( | struct ast_speech_result * | results, | |
char * | result_num | |||
) | [static] |
Definition at line 130 of file app_speech_utils.c.
References ast_speech_result::nbest_num, and ast_speech_result::next.
Referenced by speech_grammar(), speech_score(), and speech_text().
00131 { 00132 struct ast_speech_result *result = results; 00133 char *tmp = NULL; 00134 int nbest_num = 0, wanted_num = 0, i = 0; 00135 00136 if (!result) 00137 return NULL; 00138 00139 if ((tmp = strchr(result_num, '/'))) { 00140 *tmp++ = '\0'; 00141 nbest_num = atoi(result_num); 00142 wanted_num = atoi(tmp); 00143 } else { 00144 wanted_num = atoi(result_num); 00145 } 00146 00147 do { 00148 if (result->nbest_num != nbest_num) 00149 continue; 00150 if (i == wanted_num) 00151 break; 00152 i++; 00153 } while ((result = result->next)); 00154 00155 return result; 00156 }
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 115 of file app_speech_utils.c.
References ast_channel_datastore_find(), 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().
00116 { 00117 struct ast_speech *speech = NULL; 00118 struct ast_datastore *datastore = NULL; 00119 00120 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00121 if (datastore == NULL) { 00122 return NULL; 00123 } 00124 speech = datastore->data; 00125 00126 return speech; 00127 }
static int load_module | ( | void | ) | [static] |
Definition at line 855 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.
00856 { 00857 int res = 0; 00858 00859 res = ast_register_application("SpeechCreate", speech_create, "Create a Speech Structure", speechcreate_descrip); 00860 res |= ast_register_application("SpeechLoadGrammar", speech_load, "Load a Grammar", speechload_descrip); 00861 res |= ast_register_application("SpeechUnloadGrammar", speech_unload, "Unload a Grammar", speechunload_descrip); 00862 res |= ast_register_application("SpeechActivateGrammar", speech_activate, "Activate a Grammar", speechactivategrammar_descrip); 00863 res |= ast_register_application("SpeechDeactivateGrammar", speech_deactivate, "Deactivate a Grammar", speechdeactivategrammar_descrip); 00864 res |= ast_register_application("SpeechStart", speech_start, "Start recognizing voice in the audio stream", speechstart_descrip); 00865 res |= ast_register_application("SpeechBackground", speech_background, "Play a sound file and wait for speech to be recognized", speechbackground_descrip); 00866 res |= ast_register_application("SpeechDestroy", speech_destroy, "End speech recognition", speechdestroy_descrip); 00867 res |= ast_register_application("SpeechProcessingSound", speech_processing_sound, "Change background processing sound", speechprocessingsound_descrip); 00868 res |= ast_custom_function_register(&speech_function); 00869 res |= ast_custom_function_register(&speech_score_function); 00870 res |= ast_custom_function_register(&speech_text_function); 00871 res |= ast_custom_function_register(&speech_grammar_function); 00872 res |= ast_custom_function_register(&speech_engine_function); 00873 res |= ast_custom_function_register(&speech_results_type_function); 00874 00875 return res; 00876 }
static int speech_activate | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechActivateGrammar(Grammar Name) Dialplan Application.
Definition at line 467 of file app_speech_utils.c.
References ast_module_user_add, ast_module_user_remove, ast_speech_grammar_activate(), and find_speech().
Referenced by load_module().
00468 { 00469 int res = 0; 00470 struct ast_module_user *u = NULL; 00471 struct ast_speech *speech = find_speech(chan); 00472 00473 u = ast_module_user_add(chan); 00474 00475 if (speech == NULL) { 00476 ast_module_user_remove(u); 00477 return -1; 00478 } 00479 00480 /* Activate the grammar on the speech object */ 00481 res = ast_speech_grammar_activate(speech, data); 00482 00483 ast_module_user_remove(u); 00484 00485 return res; 00486 }
static int speech_background | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechBackground(Sound File|Timeout) Dialplan Application.
Definition at line 552 of file app_speech_utils.c.
References ast_channel::_state, ast_answer(), ast_app_separate_args(), ast_calloc, ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_clear_flag, AST_CONTROL_HANGUP, AST_FORMAT_SLINEAR, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_frfree, AST_MAX_EXTENSION, ast_module_user_add, ast_module_user_remove, 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_STATE_UP, ast_stopstream(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_waitfor(), ast_pbx::dtimeout, f, find_speech(), ast_channel::language, ast_speech::lock, ast_channel::pbx, pbx_builtin_getvar_helper(), ast_speech::processing_sound, ast_channel::readformat, ast_speech::results, ast_channel::sched, speech_datastore, speech_streamfile(), ast_speech::state, strdup, ast_channel::stream, ast_channel::streamid, and ast_channel::timingfunc.
Referenced by load_module().
00553 { 00554 unsigned int timeout = 0; 00555 int res = 0, done = 0, argc = 0, started = 0, quieted = 0, max_dtmf_len = 0; 00556 struct ast_module_user *u = NULL; 00557 struct ast_speech *speech = find_speech(chan); 00558 struct ast_frame *f = NULL; 00559 int oldreadformat = AST_FORMAT_SLINEAR; 00560 char dtmf[AST_MAX_EXTENSION] = ""; 00561 time_t start, current; 00562 struct ast_datastore *datastore = NULL; 00563 char *argv[2], *args = NULL, *filename_tmp = NULL, *filename = NULL, tmp[2] = "", dtmf_terminator = '#'; 00564 const char *tmp2 = NULL; 00565 00566 args = ast_strdupa(data); 00567 00568 u = ast_module_user_add(chan); 00569 00570 if (speech == NULL) { 00571 ast_module_user_remove(u); 00572 return -1; 00573 } 00574 00575 /* If channel is not already answered, then answer it */ 00576 if (chan->_state != AST_STATE_UP && ast_answer(chan)) { 00577 ast_module_user_remove(u); 00578 return -1; 00579 } 00580 00581 /* Record old read format */ 00582 oldreadformat = chan->readformat; 00583 00584 /* Change read format to be signed linear */ 00585 if (ast_set_read_format(chan, AST_FORMAT_SLINEAR)) { 00586 ast_module_user_remove(u); 00587 return -1; 00588 } 00589 00590 /* Parse out options */ 00591 argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])); 00592 if (argc > 0) { 00593 /* Yay sound file */ 00594 filename_tmp = ast_strdupa(argv[0]); 00595 if (!ast_strlen_zero(argv[1])) { 00596 if ((timeout = atoi(argv[1])) == 0) 00597 timeout = -1; 00598 } else 00599 timeout = 0; 00600 } 00601 00602 /* See if the maximum DTMF length variable is set... we use a variable in case they want to carry it through their entire dialplan */ 00603 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_MAXLEN")) && !ast_strlen_zero(tmp2)) 00604 max_dtmf_len = atoi(tmp2); 00605 00606 /* See if a terminator is specified */ 00607 if ((tmp2 = pbx_builtin_getvar_helper(chan, "SPEECH_DTMF_TERMINATOR"))) { 00608 if (ast_strlen_zero(tmp2)) 00609 dtmf_terminator = '\0'; 00610 else 00611 dtmf_terminator = tmp2[0]; 00612 } 00613 00614 /* Before we go into waiting for stuff... make sure the structure is ready, if not - start it again */ 00615 if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) { 00616 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00617 ast_speech_start(speech); 00618 } 00619 00620 /* Ensure no streams are currently running */ 00621 ast_stopstream(chan); 00622 00623 /* Okay it's streaming so go into a loop grabbing frames! */ 00624 while (done == 0) { 00625 /* If the filename is null and stream is not running, start up a new sound file */ 00626 if (!quieted && (chan->streamid == -1 && chan->timingfunc == NULL) && (filename = strsep(&filename_tmp, "&"))) { 00627 /* Discard old stream information */ 00628 ast_stopstream(chan); 00629 /* Start new stream */ 00630 speech_streamfile(chan, filename, chan->language); 00631 } 00632 00633 /* Run scheduled stuff */ 00634 ast_sched_runq(chan->sched); 00635 00636 /* Yay scheduling */ 00637 res = ast_sched_wait(chan->sched); 00638 if (res < 0) { 00639 res = 1000; 00640 } 00641 00642 /* If there is a frame waiting, get it - if not - oh well */ 00643 if (ast_waitfor(chan, res) > 0) { 00644 f = ast_read(chan); 00645 if (f == NULL) { 00646 /* The channel has hung up most likely */ 00647 done = 3; 00648 break; 00649 } 00650 } 00651 00652 /* Do timeout check (shared between audio/dtmf) */ 00653 if ((!quieted || strlen(dtmf)) && started == 1) { 00654 time(¤t); 00655 if ((current-start) >= timeout) { 00656 done = 1; 00657 if (f) 00658 ast_frfree(f); 00659 break; 00660 } 00661 } 00662 00663 /* Do checks on speech structure to see if it's changed */ 00664 ast_mutex_lock(&speech->lock); 00665 if (ast_test_flag(speech, AST_SPEECH_QUIET)) { 00666 if (chan->stream) 00667 ast_stopstream(chan); 00668 ast_clear_flag(speech, AST_SPEECH_QUIET); 00669 quieted = 1; 00670 } 00671 /* Check state so we can see what to do */ 00672 switch (speech->state) { 00673 case AST_SPEECH_STATE_READY: 00674 /* If audio playback has stopped do a check for timeout purposes */ 00675 if (chan->streamid == -1 && chan->timingfunc == NULL) 00676 ast_stopstream(chan); 00677 if (!quieted && chan->stream == NULL && timeout && started == 0 && !filename_tmp) { 00678 if (timeout == -1) { 00679 done = 1; 00680 if (f) 00681 ast_frfree(f); 00682 break; 00683 } 00684 time(&start); 00685 started = 1; 00686 } 00687 /* Write audio frame out to speech engine if no DTMF has been received */ 00688 if (!strlen(dtmf) && f != NULL && f->frametype == AST_FRAME_VOICE) { 00689 ast_speech_write(speech, f->data, f->datalen); 00690 } 00691 break; 00692 case AST_SPEECH_STATE_WAIT: 00693 /* Cue up waiting sound if not already playing */ 00694 if (!strlen(dtmf)) { 00695 if (chan->stream == NULL) { 00696 if (speech->processing_sound != NULL) { 00697 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound,"none")) { 00698 speech_streamfile(chan, speech->processing_sound, chan->language); 00699 } 00700 } 00701 } else if (chan->streamid == -1 && chan->timingfunc == NULL) { 00702 ast_stopstream(chan); 00703 if (speech->processing_sound != NULL) { 00704 if (strlen(speech->processing_sound) > 0 && strcasecmp(speech->processing_sound,"none")) { 00705 speech_streamfile(chan, speech->processing_sound, chan->language); 00706 } 00707 } 00708 } 00709 } 00710 break; 00711 case AST_SPEECH_STATE_DONE: 00712 /* Now that we are done... let's switch back to not ready state */ 00713 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00714 if (!strlen(dtmf)) { 00715 /* Copy to speech structure the results, if available */ 00716 speech->results = ast_speech_results_get(speech); 00717 /* Break out of our background too */ 00718 done = 1; 00719 /* Stop audio playback */ 00720 if (chan->stream != NULL) { 00721 ast_stopstream(chan); 00722 } 00723 } 00724 break; 00725 default: 00726 break; 00727 } 00728 ast_mutex_unlock(&speech->lock); 00729 00730 /* Deal with other frame types */ 00731 if (f != NULL) { 00732 /* Free the frame we received */ 00733 switch (f->frametype) { 00734 case AST_FRAME_DTMF: 00735 if (dtmf_terminator != '\0' && f->subclass == dtmf_terminator) { 00736 done = 1; 00737 } else { 00738 quieted = 1; 00739 if (chan->stream != NULL) { 00740 ast_stopstream(chan); 00741 } 00742 if (!started) { 00743 /* Change timeout to be 5 seconds for DTMF input */ 00744 timeout = (chan->pbx && chan->pbx->dtimeout) ? chan->pbx->dtimeout : 5; 00745 started = 1; 00746 } 00747 time(&start); 00748 snprintf(tmp, sizeof(tmp), "%c", f->subclass); 00749 strncat(dtmf, tmp, sizeof(dtmf) - strlen(dtmf) - 1); 00750 /* If the maximum length of the DTMF has been reached, stop now */ 00751 if (max_dtmf_len && strlen(dtmf) == max_dtmf_len) 00752 done = 1; 00753 } 00754 break; 00755 case AST_FRAME_CONTROL: 00756 switch (f->subclass) { 00757 case AST_CONTROL_HANGUP: 00758 /* Since they hung up we should destroy the speech structure */ 00759 done = 3; 00760 default: 00761 break; 00762 } 00763 default: 00764 break; 00765 } 00766 ast_frfree(f); 00767 f = NULL; 00768 } 00769 } 00770 00771 if (strlen(dtmf)) { 00772 /* We sort of make a results entry */ 00773 speech->results = ast_calloc(1, sizeof(*speech->results)); 00774 if (speech->results != NULL) { 00775 ast_speech_dtmf(speech, dtmf); 00776 speech->results->score = 1000; 00777 speech->results->text = strdup(dtmf); 00778 speech->results->grammar = strdup("dtmf"); 00779 } 00780 ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY); 00781 } 00782 00783 /* See if it was because they hung up */ 00784 if (done == 3) { 00785 /* Destroy speech structure */ 00786 ast_speech_destroy(speech); 00787 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00788 if (datastore != NULL) { 00789 ast_channel_datastore_remove(chan, datastore); 00790 } 00791 } else { 00792 /* Channel is okay so restore read format */ 00793 ast_set_read_format(chan, oldreadformat); 00794 } 00795 00796 ast_module_user_remove(u); 00797 00798 return 0; 00799 }
static int speech_create | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechCreate() Dialplan Application.
Definition at line 354 of file app_speech_utils.c.
References ast_channel_datastore_add(), ast_channel_datastore_alloc(), AST_FORMAT_SLINEAR, ast_module_user_add, ast_module_user_remove, ast_speech_destroy(), ast_speech_new(), ast_datastore::data, pbx_builtin_setvar_helper(), and speech_datastore.
Referenced by load_module().
00355 { 00356 struct ast_module_user *u = NULL; 00357 struct ast_speech *speech = NULL; 00358 struct ast_datastore *datastore = NULL; 00359 00360 u = ast_module_user_add(chan); 00361 00362 /* Request a speech object */ 00363 speech = ast_speech_new(data, AST_FORMAT_SLINEAR); 00364 if (speech == NULL) { 00365 /* Not available */ 00366 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00367 ast_module_user_remove(u); 00368 return 0; 00369 } 00370 00371 datastore = ast_channel_datastore_alloc(&speech_datastore, NULL); 00372 if (datastore == NULL) { 00373 ast_speech_destroy(speech); 00374 pbx_builtin_setvar_helper(chan, "ERROR", "1"); 00375 ast_module_user_remove(u); 00376 return 0; 00377 } 00378 datastore->data = speech; 00379 ast_channel_datastore_add(chan, datastore); 00380 00381 pbx_builtin_setvar_helper(chan, "ERROR", NULL); 00382 00383 ast_module_user_remove(u); 00384 00385 return 0; 00386 }
static int speech_deactivate | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechDeactivateGrammar(Grammar Name) Dialplan Application.
Definition at line 445 of file app_speech_utils.c.
References ast_module_user_add, ast_module_user_remove, ast_speech_grammar_deactivate(), and find_speech().
Referenced by load_module().
00446 { 00447 int res = 0; 00448 struct ast_module_user *u = NULL; 00449 struct ast_speech *speech = find_speech(chan); 00450 00451 u = ast_module_user_add(chan); 00452 00453 if (speech == NULL) { 00454 ast_module_user_remove(u); 00455 return -1; 00456 } 00457 00458 /* Deactivate the grammar on the speech object */ 00459 res = ast_speech_grammar_deactivate(speech, data); 00460 00461 ast_module_user_remove(u); 00462 00463 return res; 00464 }
static int speech_destroy | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechDestroy() Dialplan Application.
Definition at line 803 of file app_speech_utils.c.
References ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_module_user_add, ast_module_user_remove, ast_speech_destroy(), find_speech(), and speech_datastore.
Referenced by load_module().
00804 { 00805 int res = 0; 00806 struct ast_module_user *u = NULL; 00807 struct ast_speech *speech = find_speech(chan); 00808 struct ast_datastore *datastore = NULL; 00809 00810 u = ast_module_user_add(chan); 00811 00812 if (speech == NULL) { 00813 ast_module_user_remove(u); 00814 return -1; 00815 } 00816 00817 /* Destroy speech structure */ 00818 ast_speech_destroy(speech); 00819 00820 datastore = ast_channel_datastore_find(chan, &speech_datastore, NULL); 00821 if (datastore != NULL) { 00822 ast_channel_datastore_remove(chan, datastore); 00823 } 00824 00825 ast_module_user_remove(u); 00826 00827 return res; 00828 }
static int speech_engine_write | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
SPEECH_ENGINE() Dialplan Function.
Definition at line 245 of file app_speech_utils.c.
References ast_speech_change(), and find_speech().
00246 { 00247 struct ast_speech *speech = find_speech(chan); 00248 00249 if (data == NULL || speech == NULL) 00250 return -1; 00251 00252 ast_speech_change(speech, data, value); 00253 00254 return 0; 00255 }
static int speech_grammar | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
SPEECH_GRAMMAR() Dialplan Function.
Definition at line 216 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech_result::grammar, and ast_speech::results.
00218 { 00219 struct ast_speech_result *result = NULL; 00220 struct ast_speech *speech = find_speech(chan); 00221 00222 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00223 return -1; 00224 00225 if (result->grammar != NULL) { 00226 ast_copy_string(buf, result->grammar, len); 00227 } else { 00228 buf[0] = '\0'; 00229 } 00230 00231 return 0; 00232 }
static int speech_load | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechLoadGrammar(Grammar Name|Path) Dialplan Application.
Definition at line 389 of file app_speech_utils.c.
References ast_app_separate_args(), ast_module_user_add, ast_module_user_remove, ast_speech_grammar_load(), ast_strdupa, find_speech(), and name.
Referenced by load_module().
00390 { 00391 int res = 0, argc = 0; 00392 struct ast_module_user *u = NULL; 00393 struct ast_speech *speech = find_speech(chan); 00394 char *argv[2], *args = NULL, *name = NULL, *path = NULL; 00395 00396 args = ast_strdupa(data); 00397 00398 u = ast_module_user_add(chan); 00399 00400 if (speech == NULL) { 00401 ast_module_user_remove(u); 00402 return -1; 00403 } 00404 00405 /* Parse out arguments */ 00406 argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])); 00407 if (argc != 2) { 00408 ast_module_user_remove(u); 00409 return -1; 00410 } 00411 name = argv[0]; 00412 path = argv[1]; 00413 00414 /* Load the grammar locally on the object */ 00415 res = ast_speech_grammar_load(speech, name, path); 00416 00417 ast_module_user_remove(u); 00418 00419 return res; 00420 }
static int speech_processing_sound | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechProcessingSound(Sound File) Dialplan Application.
Definition at line 510 of file app_speech_utils.c.
References ast_module_user_add, ast_module_user_remove, find_speech(), free, ast_speech::processing_sound, and strdup.
Referenced by load_module().
00511 { 00512 int res = 0; 00513 struct ast_module_user *u = NULL; 00514 struct ast_speech *speech = find_speech(chan); 00515 00516 u = ast_module_user_add(chan); 00517 00518 if (speech == NULL) { 00519 ast_module_user_remove(u); 00520 return -1; 00521 } 00522 00523 if (speech->processing_sound != NULL) { 00524 free(speech->processing_sound); 00525 speech->processing_sound = NULL; 00526 } 00527 00528 speech->processing_sound = strdup(data); 00529 00530 ast_module_user_remove(u); 00531 00532 return res; 00533 }
static int speech_read | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
SPEECH() Dialplan Function.
Definition at line 294 of file app_speech_utils.c.
References ast_copy_string(), AST_SPEECH_SPOKE, ast_test_flag, find_speech(), ast_speech_result::next, and ast_speech::results.
00296 { 00297 int results = 0; 00298 struct ast_speech_result *result = NULL; 00299 struct ast_speech *speech = find_speech(chan); 00300 char tmp[128] = ""; 00301 00302 /* Now go for the various options */ 00303 if (!strcasecmp(data, "status")) { 00304 if (speech != NULL) 00305 ast_copy_string(buf, "1", len); 00306 else 00307 ast_copy_string(buf, "0", len); 00308 return 0; 00309 } 00310 00311 /* Make sure we have a speech structure for everything else */ 00312 if (speech == NULL) { 00313 return -1; 00314 } 00315 00316 /* Check to see if they are checking for silence */ 00317 if (!strcasecmp(data, "spoke")) { 00318 if (ast_test_flag(speech, AST_SPEECH_SPOKE)) 00319 ast_copy_string(buf, "1", len); 00320 else 00321 ast_copy_string(buf, "0", len); 00322 } else if (!strcasecmp(data, "results")) { 00323 /* Count number of results */ 00324 result = speech->results; 00325 while (result) { 00326 results++; 00327 result = result->next; 00328 } 00329 snprintf(tmp, sizeof(tmp), "%d", results); 00330 ast_copy_string(buf, tmp, len); 00331 } else { 00332 buf[0] = '\0'; 00333 } 00334 00335 return 0; 00336 }
static int speech_results_type_write | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
const char * | value | |||
) | [static] |
SPEECH_RESULTS_TYPE() Dialplan Function.
Definition at line 268 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().
00269 { 00270 struct ast_speech *speech = find_speech(chan); 00271 00272 if (data == NULL || speech == NULL) 00273 return -1; 00274 00275 if (!strcasecmp(value, "normal")) 00276 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NORMAL); 00277 else if (!strcasecmp(value, "nbest")) 00278 ast_speech_change_results_type(speech, AST_SPEECH_RESULTS_TYPE_NBEST); 00279 00280 return 0; 00281 }
static int speech_score | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
SPEECH_SCORE() Dialplan Function.
Definition at line 159 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech::results, and ast_speech_result::score.
00161 { 00162 struct ast_speech_result *result = NULL; 00163 struct ast_speech *speech = find_speech(chan); 00164 char tmp[128] = ""; 00165 00166 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00167 return -1; 00168 00169 snprintf(tmp, sizeof(tmp), "%d", result->score); 00170 00171 ast_copy_string(buf, tmp, len); 00172 00173 return 0; 00174 }
static int speech_start | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechStart() Dialplan Application.
Definition at line 489 of file app_speech_utils.c.
References ast_module_user_add, ast_module_user_remove, ast_speech_start(), and find_speech().
Referenced by load_module().
00490 { 00491 int res = 0; 00492 struct ast_module_user *u = NULL; 00493 struct ast_speech *speech = find_speech(chan); 00494 00495 u = ast_module_user_add(chan); 00496 00497 if (speech == NULL) { 00498 ast_module_user_remove(u); 00499 return -1; 00500 } 00501 00502 ast_speech_start(speech); 00503 00504 ast_module_user_remove(u); 00505 00506 return res; 00507 }
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 536 of file app_speech_utils.c.
References ast_applystream(), ast_openstream(), and ast_playstream().
Referenced by speech_background().
00537 { 00538 struct ast_filestream *fs = NULL; 00539 00540 if (!(fs = ast_openstream(chan, filename, preflang))) 00541 return -1; 00542 00543 if (ast_applystream(chan, fs)) 00544 return -1; 00545 00546 ast_playstream(fs); 00547 00548 return 0; 00549 }
static int speech_text | ( | struct ast_channel * | chan, | |
char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
SPEECH_TEXT() Dialplan Function.
Definition at line 187 of file app_speech_utils.c.
References ast_copy_string(), find_result(), find_speech(), ast_speech::results, and ast_speech_result::text.
00189 { 00190 struct ast_speech_result *result = NULL; 00191 struct ast_speech *speech = find_speech(chan); 00192 00193 if (data == NULL || speech == NULL || !(result = find_result(speech->results, data))) 00194 return -1; 00195 00196 if (result->text != NULL) { 00197 ast_copy_string(buf, result->text, len); 00198 } else { 00199 buf[0] = '\0'; 00200 } 00201 00202 return 0; 00203 }
static int speech_unload | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
SpeechUnloadGrammar(Grammar Name) Dialplan Application.
Definition at line 423 of file app_speech_utils.c.
References ast_module_user_add, ast_module_user_remove, ast_speech_grammar_unload(), and find_speech().
Referenced by load_module().
00424 { 00425 int res = 0; 00426 struct ast_module_user *u = NULL; 00427 struct ast_speech *speech = find_speech(chan); 00428 00429 u = ast_module_user_add(chan); 00430 00431 if (speech == NULL) { 00432 ast_module_user_remove(u); 00433 return -1; 00434 } 00435 00436 /* Unload the grammar */ 00437 res = ast_speech_grammar_unload(speech, data); 00438 00439 ast_module_user_remove(u); 00440 00441 return res; 00442 }
static int unload_module | ( | void | ) | [static] |
Definition at line 830 of file app_speech_utils.c.
References ast_custom_function_unregister(), ast_module_user_hangup_all, ast_unregister_application(), speech_engine_function, speech_function, speech_grammar_function, speech_results_type_function, speech_score_function, and speech_text_function.
00831 { 00832 int res = 0; 00833 00834 res = ast_unregister_application("SpeechCreate"); 00835 res |= ast_unregister_application("SpeechLoadGrammar"); 00836 res |= ast_unregister_application("SpeechUnloadGrammar"); 00837 res |= ast_unregister_application("SpeechActivateGrammar"); 00838 res |= ast_unregister_application("SpeechDeactivateGrammar"); 00839 res |= ast_unregister_application("SpeechStart"); 00840 res |= ast_unregister_application("SpeechBackground"); 00841 res |= ast_unregister_application("SpeechDestroy"); 00842 res |= ast_unregister_application("SpeechProcessingSound"); 00843 res |= ast_custom_function_unregister(&speech_function); 00844 res |= ast_custom_function_unregister(&speech_score_function); 00845 res |= ast_custom_function_unregister(&speech_text_function); 00846 res |= ast_custom_function_unregister(&speech_grammar_function); 00847 res |= ast_custom_function_unregister(&speech_engine_function); 00848 res |= ast_custom_function_unregister(&speech_results_type_function); 00849 00850 ast_module_user_hangup_all(); 00851 00852 return res; 00853 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 878 of file app_speech_utils.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 878 of file app_speech_utils.c.
struct ast_datastore_info speech_datastore [static] |
Initial value:
{ .type = "speech", .destroy = destroy_callback }
Definition at line 109 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 257 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_function [static] |
Definition at line 338 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_grammar_function [static] |
Definition at line 234 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 283 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_score_function [static] |
Definition at line 176 of file app_speech_utils.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function speech_text_function [static] |
Definition at line 205 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. A grammar tells the speech recognition engine what to recognize, \n" "and how to portray it back to you in the dialplan. The grammar name is the only argument to this application.\n"
Definition at line 52 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. 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 47 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. The only argument is the grammar name to deactivate.\n"
Definition at line 69 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 78 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 84 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 processing and working to get results.\n" "It takes the sound file as the only argument.\n"
Definition at line 73 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 fed to it. This has no arguments.\n"
Definition at line 57 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 89 of file app_speech_utils.c.
Referenced by load_module().