51 if (ast_strlen_zero(engine_name))
52 return default_engine;
55 AST_RWLIST_TRAVERSE(&
engines, engine, list) {
56 if (!strcasecmp(engine->
name, engine_name)) {
101 while (current_result != NULL) {
102 prev_result = current_result;
104 if (current_result->
text != NULL) {
105 ast_free(current_result->
text);
106 current_result->
text = NULL;
108 if (current_result->
grammar != NULL) {
109 ast_free(current_result->
grammar);
110 current_result->
grammar = NULL;
114 ast_free(prev_result);
126 ast_clear_flag(speech, AST_SPEECH_SPOKE);
127 ast_clear_flag(speech, AST_SPEECH_QUIET);
128 ast_clear_flag(speech, AST_SPEECH_HAVE_RESULTS);
147 if (speech->
state != AST_SPEECH_STATE_READY)
158 if (speech->
state != AST_SPEECH_STATE_READY)
220 if (!(new_speech =
ast_calloc(1,
sizeof(*new_speech)))) {
225 ast_mutex_init(&new_speech->
lock);
231 new_speech->
engine = engine;
241 ast_mutex_destroy(&new_speech->
lock);
243 ast_free(new_speech);
259 ast_mutex_destroy(&speech->
lock);
283 case AST_SPEECH_STATE_WAIT:
285 ast_set_flag(speech, AST_SPEECH_SPOKE);
287 speech->
state = state;
297 case AST_SPEECH_RESULTS_TYPE_NORMAL:
299 case AST_SPEECH_RESULTS_TYPE_NBEST:
322 ast_log(LOG_WARNING,
"Speech recognition engine '%s' did not meet minimum API requirements.\n", engine->
name);
328 ast_log(LOG_WARNING,
"Speech recognition engine '%s' already exists.\n", engine->
name);
332 ast_verb(5,
"Registered speech recognition engine '%s'\n", engine->
name);
336 AST_RWLIST_INSERT_HEAD(&
engines, engine, list);
337 if (!default_engine) {
338 default_engine = engine;
339 ast_verb(5,
"Made '%s' the default speech recognition engine\n", engine->
name);
356 if (ast_strlen_zero(engine_name)) {
361 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
engines, engine, list) {
362 if (!strcasecmp(engine->
name, engine_name)) {
364 AST_RWLIST_REMOVE_CURRENT(list);
366 if (engine == default_engine) {
367 default_engine = AST_RWLIST_FIRST(&
engines);
369 ast_verb(5,
"Unregistered speech recognition engine '%s'\n", engine_name);
374 AST_RWLIST_TRAVERSE_SAFE_END;
381 int (*should_unregister)(
const struct ast_speech_engine *engine,
void *data),
void *data,
382 void (*on_unregistered)(
void *obj))
386 if (!should_unregister) {
391 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
engines, engine, list) {
392 if (should_unregister(engine, data)) {
394 AST_RWLIST_REMOVE_CURRENT(list);
396 if (engine == default_engine) {
397 default_engine = AST_RWLIST_FIRST(&
engines);
399 ast_verb(5,
"Unregistered speech recognition engine '%s'\n", engine->
name);
401 if (on_unregistered) {
402 on_unregistered(engine);
406 AST_RWLIST_TRAVERSE_SAFE_END;
410 static int unload_module(
void)
416 static int load_module(
void)
421 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
"Generic Speech Recognition API",
422 .support_level = AST_MODULE_SUPPORT_CORE,
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
struct ast_speech_result * ast_speech_results_get(struct ast_speech *speech)
Return the results of a recognition from the speech structure.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_speech_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len)
Get an engine specific attribute.
int ast_speech_write(struct ast_speech *speech, void *data, int len)
Write in signed linear audio to be recognized.
struct ast_speech_engine * ast_speech_unregister2(const char *engine_name)
Unregister a speech recognition engine.
int(* destroy)(struct ast_speech *speech)
Generic Speech Recognition API.
int(* create)(struct ast_speech *speech, struct ast_format *format)
const char * ast_speech_results_type_to_string(enum ast_speech_results_type type)
Convert a speech results type to a string.
int(* change)(struct ast_speech *speech, const char *name, const char *value)
Support for translation of data formats. translate.c.
struct ast_speech_engine * ast_speech_find_engine(const char *engine_name)
Find a speech recognition engine of specified name, if NULL then use the default one.
int ast_speech_grammar_activate(struct ast_speech *speech, const char *grammar_name)
Activate a loaded (either local or global) grammar.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
int ast_speech_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
Change the type of results we want.
void ast_speech_unregister_engines(int(*should_unregister)(const struct ast_speech_engine *engine, void *data), void *data, void(*on_unregistered)(void *obj))
Unregister all speech recognition engines told to by callback.
int ast_speech_register(struct ast_speech_engine *engine)
Register a speech recognition engine.
enum ast_speech_results_type results_type
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
void ast_speech_start(struct ast_speech *speech)
Start speech recognition on a speech structure.
int ast_speech_unregister(const char *engine_name)
Unregister a speech recognition engine.
int(* start)(struct ast_speech *speech)
int ast_translator_best_choice(struct ast_format_cap *dst_cap, struct ast_format_cap *src_cap, struct ast_format **dst_fmt_out, struct ast_format **src_fmt_out)
Chooses the best translation path.
int ast_speech_grammar_unload(struct ast_speech *speech, const char *grammar_name)
Unload a local grammar from a speech structure.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
int(* unload)(struct ast_speech *speech, const char *grammar_name)
General Asterisk PBX channel definitions.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
int ast_speech_grammar_load(struct ast_speech *speech, const char *grammar_name, const char *grammar)
Load a local grammar on a speech structure.
int ast_speech_change(struct ast_speech *speech, const char *name, const char *value)
Change an engine specific attribute.
struct ast_format_cap * formats
A set of macros to manage forward-linked lists.
int(* change_results_type)(struct ast_speech *speech, enum ast_speech_results_type results_type)
struct ast_speech_engine * engine
struct ast_speech_result * results
struct ast_speech_result *(* get)(struct ast_speech *speech)
int(* activate)(struct ast_speech *speech, const char *grammar_name)
int(* write)(struct ast_speech *speech, void *data, int len)
int ast_speech_results_free(struct ast_speech_result *result)
Free a list of results.
#define ast_calloc(num, len)
A wrapper for calloc()
struct ast_format * format
Standard Command Line Interface.
int(* deactivate)(struct ast_speech *speech, const char *grammar_name)
int ast_speech_dtmf(struct ast_speech *speech, const char *dtmf)
Signal to the engine that DTMF was received.
int(* load)(struct ast_speech *speech, const char *grammar_name, const char *grammar)
int(* dtmf)(struct ast_speech *speech, const char *dtmf)
struct ast_speech * ast_speech_new(const char *engine_name, const struct ast_format_cap *cap)
Create a new speech structure using the engine specified.
Handy terminal functions for vt* terms.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
int ast_speech_destroy(struct ast_speech *speech)
Destroy a speech structure.
#define ASTERISK_GPL_KEY
The text the key() function should return.
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_speech_grammar_deactivate(struct ast_speech *speech, const char *grammar_name)
Deactivate a loaded grammar on a speech structure.
int(* get_setting)(struct ast_speech *speech, const char *name, char *buf, size_t len)