278 if (speech == NULL) {
304 ast_channel_lock(chan);
306 ast_channel_unlock(chan);
307 if (datastore == NULL) {
310 speech = datastore->
data;
324 static int speech_datastore_destroy(
struct ast_channel *chan)
329 ast_channel_lock(chan);
334 ast_channel_unlock(chan);
349 int nbest_num = 0, wanted_num = 0, i = 0;
355 if ((tmp = strchr(result_num,
'/'))) {
357 nbest_num = atoi(result_num);
358 wanted_num = atoi(tmp);
360 wanted_num = atoi(result_num);
376 char *buf,
size_t len)
382 if (data == NULL || speech == NULL || !(result = find_result(speech->
results, data))) {
386 snprintf(tmp,
sizeof(tmp),
"%d", result->
score);
394 .
name =
"SPEECH_SCORE",
401 char *buf,
size_t len)
406 if (data == NULL || speech == NULL || !(result = find_result(speech->
results, data))) {
410 if (result->
text != NULL) {
420 .
name =
"SPEECH_TEXT",
427 char *buf,
size_t len)
432 if (data == NULL || speech == NULL || !(result = find_result(speech->
results, data))) {
446 .
name =
"SPEECH_GRAMMAR",
456 if (data == NULL || speech == NULL) {
470 if (!data || !speech) {
478 .
name =
"SPEECH_ENGINE",
488 if (data == NULL || speech == NULL)
491 if (!strcasecmp(value,
"normal"))
493 else if (!strcasecmp(value,
"nbest"))
500 .
name =
"SPEECH_RESULTS_TYPE",
507 char *buf,
size_t len)
515 if (!strcasecmp(data,
"status")) {
524 if (speech == NULL) {
529 if (!strcasecmp(data,
"spoke")) {
530 if (ast_test_flag(speech, AST_SPEECH_SPOKE))
534 }
else if (!strcasecmp(data,
"results")) {
538 snprintf(tmp,
sizeof(tmp),
"%d", results);
563 if (speech == NULL) {
569 datastore = ast_datastore_alloc(&speech_datastore, NULL);
570 if (datastore == NULL) {
576 datastore->
data = speech;
577 ast_channel_lock(chan);
579 ast_channel_unlock(chan);
705 SB_OPT_NOANSWER = (1 << 0),
706 SB_OPT_PARTIALRESULTS = (1 << 1),
717 unsigned int timeout = 0;
718 int res = 0, done = 0, started = 0, quieted = 0, max_dtmf_len = 0;
723 struct timeval start = { 0, 0 }, current;
724 char *parse, *filename_tmp = NULL, *filename = NULL, tmp[2] =
"", dtmf_terminator =
'#';
725 const char *tmp2 = NULL;
739 if (!ast_strlen_zero(args.options)) {
751 oldreadformat =
ao2_bump(ast_channel_readformat(chan));
757 if (!ast_strlen_zero(args.soundfile)) {
760 if (!ast_strlen_zero(args.timeout)) {
761 if ((timeout = atof(args.timeout) * 1000.0) == 0)
768 ast_channel_lock(chan);
770 max_dtmf_len = atoi(tmp2);
775 if (ast_strlen_zero(tmp2))
776 dtmf_terminator =
'\0';
778 dtmf_terminator = tmp2[0];
780 ast_channel_unlock(chan);
783 if (speech->
state == AST_SPEECH_STATE_NOT_READY || speech->
state == AST_SPEECH_STATE_DONE) {
795 && ast_channel_streamid(chan) == -1
796 && ast_channel_timingfunc(chan) == NULL
823 if ((!quieted || strlen(dtmf)) && started == 1) {
834 ast_mutex_lock(&speech->
lock);
835 if (ast_test_flag(speech, AST_SPEECH_QUIET)) {
836 if (ast_channel_stream(chan))
838 ast_clear_flag(speech, AST_SPEECH_QUIET);
842 switch (speech->
state) {
843 case AST_SPEECH_STATE_READY:
845 if (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL)
847 if (!quieted && ast_channel_stream(chan) == NULL && timeout && started == 0 && !filename_tmp) {
862 case AST_SPEECH_STATE_WAIT:
865 if (ast_channel_stream(chan) == NULL) {
871 }
else if (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL) {
881 case AST_SPEECH_STATE_DONE:
890 if (ast_channel_stream(chan) != NULL) {
898 ast_mutex_unlock(&speech->
lock);
905 if (dtmf_terminator !=
'\0' && f->
subclass.
integer == dtmf_terminator) {
909 if (ast_channel_stream(chan) != NULL) {
914 timeout = (ast_channel_pbx(chan) && ast_channel_pbx(chan)->
dtimeoutms) ? ast_channel_pbx(chan)->
dtimeoutms : 5000;
919 strncat(dtmf, tmp,
sizeof(dtmf) - strlen(dtmf) - 1);
921 if (max_dtmf_len && strlen(dtmf) == max_dtmf_len)
941 if (ast_strlen_zero(dtmf) && speech->
state == AST_SPEECH_STATE_READY && ast_test_flag(&options, SB_OPT_PARTIALRESULTS)) {
944 }
else if (!ast_strlen_zero(dtmf)) {
958 speech_datastore_destroy(chan);
974 return speech_datastore_destroy(chan);
977 static int unload_module(
void)
1000 static int load_module(
void)
1023 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Dialplan Speech Applications",
1024 .support_level = AST_MODULE_SUPPORT_CORE,
1025 .load = load_module,
1026 .unload = unload_module,
1027 .requires =
"res_speech",
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static int speech_create(struct ast_channel *chan, const char *data)
SpeechCreate() Dialplan Application.
Generic Speech Recognition API.
static int speech_unload(struct ast_channel *chan, const char *data)
SpeechUnloadGrammar(Grammar Name) Dialplan Application.
int ast_speech_destroy(struct ast_speech *speech)
Destroy a speech structure.
void ast_speech_start(struct ast_speech *speech)
Indicate to the speech engine that audio is now going to start being written.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
static int speech_background(struct ast_channel *chan, const char *data)
SpeechBackground(Sound File,Timeout) Dialplan Application.
static int speech_text(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
SPEECH_TEXT() Dialplan Function.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Structure for a data store type.
ast_channel_state
ast_channel states
struct ast_speech_result * ast_speech_results_get(struct ast_speech *speech)
Get speech recognition results.
static int speech_streamfile(struct ast_channel *chan, const char *filename, const char *preflang)
Helper function used by speech_background to playback a soundfile.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
#define ast_strdup(str)
A wrapper for strdup()
Structure for a data store object.
static int speech_engine_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
SPEECH_ENGINE() Dialplan Get Function.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
static int speech_load(struct ast_channel *chan, const char *vdata)
SpeechLoadGrammar(Grammar Name,Path) Dialplan Application.
int ast_unregister_application(const char *app)
Unregister an application.
static int speech_destroy(struct ast_channel *chan, const char *data)
SpeechDestroy() Dialplan Application.
static int speech_results_type_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
SPEECH_RESULTS_TYPE() Dialplan Function.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
int ast_speech_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
Change the type of results we want.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
int ast_speech_grammar_deactivate(struct ast_speech *speech, const char *grammar_name)
Deactivate a grammar on a speech structure.
int ast_playstream(struct ast_filestream *s)
Play a open stream on a channel.
General Asterisk PBX channel definitions.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
#define ast_strdupa(s)
duplicate a string in memory from the stack
static struct ast_speech * find_speech(struct ast_channel *chan)
Helper function used to find the speech structure attached to a channel.
Data structure associated with a custom dialplan function.
#define AST_MAX_EXTENSION
static int speech_deactivate(struct ast_channel *chan, const char *data)
SpeechDeactivateGrammar(Grammar Name) Dialplan Application.
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
int ast_speech_grammar_unload(struct ast_speech *speech, const char *grammar_name)
Unload a grammar.
struct ast_speech_result * results
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Core PBX routines and definitions.
static int speech_activate(struct ast_channel *chan, const char *data)
SpeechActivateGrammar(Grammar Name) Dialplan Application.
static int speech_engine_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
SPEECH_ENGINE() Dialplan Set Function.
static int speech_start(struct ast_channel *chan, const char *data)
SpeechStart() Dialplan Application.
int ast_applystream(struct ast_channel *chan, struct ast_filestream *s)
Applies a open stream to a channel.
static void destroy_callback(void *data)
Helper function used by datastores to destroy the speech structure upon hangup.
int ast_speech_grammar_activate(struct ast_speech *speech, const char *grammar_name)
Activate a grammar on a speech structure.
static int speech_processing_sound(struct ast_channel *chan, const char *data)
SpeechProcessingSound(Sound File) Dialplan Application.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
struct ast_format * format
Structure used to handle boolean flags.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
static const struct ast_datastore_info speech_datastore
Static structure for datastore information.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
int ast_speech_dtmf(struct ast_speech *speech, const char *dtmf)
Signal to the engine that DTMF was received.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct ast_speech * ast_speech_new(const char *engine_name, const struct ast_format_cap *formats)
Create a new speech structure.
int ast_answer(struct ast_channel *chan)
Answer a channel.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Data structure associated with a single frame of data.
static int speech_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
SPEECH() Dialplan Function.
enum ast_frame_type frametype
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_speech_write(struct ast_speech *speech, void *data, int len)
Write audio to the speech engine.
int ast_speech_grammar_load(struct ast_speech *speech, const char *grammar_name, const char *grammar)
Load a grammar on a speech structure (not globally)
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_speech_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len)
Get an engine specific attribute.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
int ast_speech_change(struct ast_speech *speech, const char *name, const char *value)
Change an engine specific attribute.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
#define ast_custom_function_register(acf)
Register a custom function.
static int speech_grammar(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
SPEECH_GRAMMAR() Dialplan Function.
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
static int speech_score(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
SPEECH_SCORE() Dialplan Function.
struct ast_filestream * ast_openstream(struct ast_channel *chan, const char *filename, const char *preflang)
Opens stream for use in seeking, playing.
#define AST_APP_ARG(name)
Define an application argument.