Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
res_speech.c File Reference

Generic Speech Recognition API. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/cli.h"
#include "asterisk/term.h"
#include "asterisk/speech.h"
#include "asterisk/format_cache.h"
Include dependency graph for res_speech.c:

Go to the source code of this file.

Data Structures

struct  engines
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
int ast_speech_change (struct ast_speech *speech, const char *name, const char *value)
 Change an engine specific attribute. More...
 
int ast_speech_change_results_type (struct ast_speech *speech, enum ast_speech_results_type results_type)
 Change the type of results we want. More...
 
int ast_speech_change_state (struct ast_speech *speech, int state)
 Change state of a speech structure. More...
 
int ast_speech_destroy (struct ast_speech *speech)
 Destroy a speech structure. More...
 
int ast_speech_dtmf (struct ast_speech *speech, const char *dtmf)
 Signal to the engine that DTMF was received. More...
 
int ast_speech_get_setting (struct ast_speech *speech, const char *name, char *buf, size_t len)
 Get an engine specific attribute. More...
 
int ast_speech_grammar_activate (struct ast_speech *speech, const char *grammar_name)
 Activate a loaded (either local or global) grammar. More...
 
int ast_speech_grammar_deactivate (struct ast_speech *speech, const char *grammar_name)
 Deactivate a loaded grammar on a speech structure. More...
 
int ast_speech_grammar_load (struct ast_speech *speech, const char *grammar_name, const char *grammar)
 Load a local grammar on a speech structure. More...
 
int ast_speech_grammar_unload (struct ast_speech *speech, const char *grammar_name)
 Unload a local grammar from a speech structure. More...
 
struct ast_speechast_speech_new (const char *engine_name, const struct ast_format_cap *cap)
 Create a new speech structure using the engine specified. More...
 
int ast_speech_register (struct ast_speech_engine *engine)
 Register a speech recognition engine. More...
 
int ast_speech_results_free (struct ast_speech_result *result)
 Free a list of results. More...
 
struct ast_speech_resultast_speech_results_get (struct ast_speech *speech)
 Return the results of a recognition from the speech structure. More...
 
void ast_speech_start (struct ast_speech *speech)
 Start speech recognition on a speech structure. More...
 
int ast_speech_unregister (const char *engine_name)
 Unregister a speech recognition engine. More...
 
int ast_speech_write (struct ast_speech *speech, void *data, int len)
 Write in signed linear audio to be recognized. More...
 
static struct ast_speech_enginefind_engine (const char *engine_name)
 Find a speech recognition engine of specified name, if NULL then use the default one. More...
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Generic Speech Recognition API" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND - 1, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_speech_enginedefault_engine = NULL
 
static struct engines engines = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

Detailed Description

Generic Speech Recognition API.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file res_speech.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 368 of file res_speech.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 368 of file res_speech.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 368 of file res_speech.c.

◆ ast_speech_change()

int ast_speech_change ( struct ast_speech speech,
const char *  name,
const char *  value 
)

Change an engine specific attribute.

Definition at line 168 of file res_speech.c.

References ast_speech_engine::change, and ast_speech::engine.

Referenced by handle_speechset(), and speech_engine_write().

169 {
170  return (speech->engine->change ? speech->engine->change(speech, name, value) : -1);
171 }
int(* change)(struct ast_speech *speech, const char *name, const char *value)
Definition: speech.h:95
int value
Definition: syslog.c:37
struct ast_speech_engine * engine
Definition: speech.h:69
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_speech_change_results_type()

int ast_speech_change_results_type ( struct ast_speech speech,
enum ast_speech_results_type  results_type 
)

Change the type of results we want.

Definition at line 284 of file res_speech.c.

References ast_speech_engine::change_results_type, ast_speech::engine, and ast_speech::results_type.

Referenced by speech_results_type_write().

285 {
286  speech->results_type = results_type;
287 
288  return (speech->engine->change_results_type ? speech->engine->change_results_type(speech, results_type) : 0);
289 }
enum ast_speech_results_type results_type
Definition: speech.h:67
int(* change_results_type)(struct ast_speech *speech, enum ast_speech_results_type results_type)
Definition: speech.h:99
struct ast_speech_engine * engine
Definition: speech.h:69

◆ ast_speech_change_state()

int ast_speech_change_state ( struct ast_speech speech,
int  state 
)

Change state of a speech structure.

Definition at line 267 of file res_speech.c.

References ast_set_flag, AST_SPEECH_SPOKE, AST_SPEECH_STATE_WAIT, ast_speech::state, and state.

Referenced by ast_speech_new(), handle_speechrecognize(), and speech_background().

268 {
269  int res = 0;
270 
271  switch (state) {
273  /* The engine heard audio, so they spoke */
275  default:
276  speech->state = state;
277  break;
278  }
279 
280  return res;
281 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
int state
Definition: speech.h:59
#define ast_set_flag(p, flag)
Definition: utils.h:70

◆ ast_speech_destroy()

int ast_speech_destroy ( struct ast_speech speech)

Destroy a speech structure.

Definition at line 240 of file res_speech.c.

References ao2_ref, ast_free, ast_mutex_destroy, ast_speech_results_free(), ast_speech_engine::destroy, ast_speech::engine, ast_speech::format, ast_speech::lock, ast_speech::processing_sound, and ast_speech::results.

Referenced by destroy_callback(), handle_speechdestroy(), launch_asyncagi(), run_agi(), and speech_create().

241 {
242  int res = 0;
243 
244  /* Call our engine so we are destroyed properly */
245  speech->engine->destroy(speech);
246 
247  /* Deinitialize the lock */
248  ast_mutex_destroy(&speech->lock);
249 
250  /* If results exist on the speech structure, destroy them */
251  if (speech->results)
253 
254  /* If a processing sound is set - free the memory used by it */
255  if (speech->processing_sound)
256  ast_free(speech->processing_sound);
257 
258  ao2_ref(speech->format, -1);
259 
260  /* Aloha we are done */
261  ast_free(speech);
262 
263  return res;
264 }
int(* destroy)(struct ast_speech *speech)
Definition: speech.h:79
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_speech_engine * engine
Definition: speech.h:69
struct ast_speech_result * results
Definition: speech.h:65
int ast_speech_results_free(struct ast_speech_result *result)
Free a list of results.
Definition: res_speech.c:95
#define ast_free(a)
Definition: astmm.h:182
struct ast_format * format
Definition: speech.h:61
ast_mutex_t lock
Definition: speech.h:53
char * processing_sound
Definition: speech.h:57
#define ast_mutex_destroy(a)
Definition: lock.h:186

◆ ast_speech_dtmf()

int ast_speech_dtmf ( struct ast_speech speech,
const char *  dtmf 
)

Signal to the engine that DTMF was received.

Definition at line 153 of file res_speech.c.

References AST_SPEECH_STATE_READY, ast_speech_engine::dtmf, ast_speech::engine, NULL, and ast_speech::state.

Referenced by speech_background().

154 {
155  int res = 0;
156 
157  if (speech->state != AST_SPEECH_STATE_READY)
158  return -1;
159 
160  if (speech->engine->dtmf != NULL) {
161  res = speech->engine->dtmf(speech, dtmf);
162  }
163 
164  return res;
165 }
int state
Definition: speech.h:59
#define NULL
Definition: resample.c:96
struct ast_speech_engine * engine
Definition: speech.h:69
int(* dtmf)(struct ast_speech *speech, const char *dtmf)
Definition: speech.h:91

◆ ast_speech_get_setting()

int ast_speech_get_setting ( struct ast_speech speech,
const char *  name,
char *  buf,
size_t  len 
)

Get an engine specific attribute.

Definition at line 174 of file res_speech.c.

References ast_speech::engine, and ast_speech_engine::get_setting.

Referenced by speech_engine_read().

175 {
176  return (speech->engine->get_setting ? speech->engine->get_setting(speech, name, buf, len) : -1);
177 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
struct ast_speech_engine * engine
Definition: speech.h:69
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static const char name[]
Definition: cdr_mysql.c:74
int(* get_setting)(struct ast_speech *speech, const char *name, char *buf, size_t len)
Definition: speech.h:97

◆ ast_speech_grammar_activate()

int ast_speech_grammar_activate ( struct ast_speech speech,
const char *  grammar_name 
)

Activate a loaded (either local or global) grammar.

Activate a grammar on a speech structure.

Definition at line 65 of file res_speech.c.

References ast_speech_engine::activate, and ast_speech::engine.

Referenced by handle_speechactivategrammar(), and speech_activate().

66 {
67  return (speech->engine->activate ? speech->engine->activate(speech, grammar_name) : -1);
68 }
struct ast_speech_engine * engine
Definition: speech.h:69
int(* activate)(struct ast_speech *speech, const char *grammar_name)
Definition: speech.h:85

◆ ast_speech_grammar_deactivate()

int ast_speech_grammar_deactivate ( struct ast_speech speech,
const char *  grammar_name 
)

Deactivate a loaded grammar on a speech structure.

Deactivate a grammar on a speech structure.

Definition at line 71 of file res_speech.c.

References ast_speech_engine::deactivate, and ast_speech::engine.

Referenced by handle_speechdeactivategrammar(), and speech_deactivate().

72 {
73  return (speech->engine->deactivate ? speech->engine->deactivate(speech, grammar_name) : -1);
74 }
struct ast_speech_engine * engine
Definition: speech.h:69
int(* deactivate)(struct ast_speech *speech, const char *grammar_name)
Definition: speech.h:87

◆ ast_speech_grammar_load()

int ast_speech_grammar_load ( struct ast_speech speech,
const char *  grammar_name,
const char *  grammar 
)

Load a local grammar on a speech structure.

Load a grammar on a speech structure (not globally)

Definition at line 77 of file res_speech.c.

References ast_speech::engine, and ast_speech_engine::load.

Referenced by handle_speechloadgrammar(), and speech_load().

78 {
79  return (speech->engine->load ? speech->engine->load(speech, grammar_name, grammar) : -1);
80 }
struct ast_speech_engine * engine
Definition: speech.h:69
int(* load)(struct ast_speech *speech, const char *grammar_name, const char *grammar)
Definition: speech.h:81

◆ ast_speech_grammar_unload()

int ast_speech_grammar_unload ( struct ast_speech speech,
const char *  grammar_name 
)

Unload a local grammar from a speech structure.

Unload a grammar.

Definition at line 83 of file res_speech.c.

References ast_speech::engine, and ast_speech_engine::unload.

Referenced by handle_speechunloadgrammar(), and speech_unload().

84 {
85  return (speech->engine->unload ? speech->engine->unload(speech, grammar_name) : -1);
86 }
int(* unload)(struct ast_speech *speech, const char *grammar_name)
Definition: speech.h:83
struct ast_speech_engine * engine
Definition: speech.h:69

◆ ast_speech_new()

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.

Create a new speech structure.

Definition at line 180 of file res_speech.c.

References ao2_bump, ao2_cleanup, ao2_ref, ast_calloc, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_compatible(), ast_format_cap_get_format(), ast_format_cap_iscompatible_format(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_slin, ast_free, ast_mutex_destroy, ast_mutex_init, ast_speech_change_state(), AST_SPEECH_STATE_NOT_READY, ast_speech_engine::create, ast_speech::engine, find_engine(), ast_speech::format, ast_speech_engine::formats, ast_speech::lock, NULL, RAII_VAR, and ast_speech::results.

Referenced by handle_speechcreate(), and speech_create().

181 {
182  struct ast_speech_engine *engine = NULL;
183  struct ast_speech *new_speech = NULL;
184  struct ast_format_cap *joint;
185  RAII_VAR(struct ast_format *, best, NULL, ao2_cleanup);
186 
187  /* Try to find the speech recognition engine that was requested */
188  if (!(engine = find_engine(engine_name)))
189  return NULL;
190 
192  if (!joint) {
193  return NULL;
194  }
195 
196  ast_format_cap_get_compatible(engine->formats, cap, joint);
197  best = ast_format_cap_get_format(joint, 0);
198  ao2_ref(joint, -1);
199 
200  if (!best) {
202  best = ao2_bump(ast_format_slin);
203  } else {
204  return NULL;
205  }
206  }
207 
208  /* Allocate our own speech structure, and try to allocate a structure from the engine too */
209  if (!(new_speech = ast_calloc(1, sizeof(*new_speech)))) {
210  return NULL;
211  }
212 
213  /* Initialize the lock */
214  ast_mutex_init(&new_speech->lock);
215 
216  /* Make sure no results are present */
217  new_speech->results = NULL;
218 
219  /* Copy over our engine pointer */
220  new_speech->engine = engine;
221 
222  /* Can't forget the format audio is going to be in */
223  new_speech->format = ao2_bump(best);
224 
225  /* We are not ready to accept audio yet */
227 
228  /* Pass ourselves to the engine so they can set us up some more and if they error out then do not create a structure */
229  if (engine->create(new_speech, new_speech->format)) {
230  ast_mutex_destroy(&new_speech->lock);
231  ao2_ref(new_speech->format, -1);
232  ast_free(new_speech);
233  return NULL;
234  }
235 
236  return new_speech;
237 }
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
Definition: res_speech.c:267
int(* create)(struct ast_speech *speech, struct ast_format *format)
Definition: speech.h:77
Definition of a media format.
Definition: format.c:43
#define NULL
Definition: resample.c:96
enum ast_format_cmp_res ast_format_cap_iscompatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
Find if ast_format is within the capabilities of the ast_format_cap object.
Definition: format_cap.c:583
#define ao2_bump(obj)
Definition: astobj2.h:491
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_format_cap * formats
Definition: speech.h:103
struct ast_speech_engine * engine
Definition: speech.h:69
struct ast_speech_result * results
Definition: speech.h:65
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct ast_format * format
Definition: speech.h:61
static struct ast_speech_engine * find_engine(const char *engine_name)
Find a speech recognition engine of specified name, if NULL then use the default one.
Definition: res_speech.c:45
ast_mutex_t lock
Definition: speech.h:53
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_mutex_init(pmutex)
Definition: lock.h:184
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
#define ast_mutex_destroy(a)
Definition: lock.h:186
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
int ast_format_cap_get_compatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
Find the compatible formats between two capabilities structures.
Definition: format_cap.c:630

◆ ast_speech_register()

int ast_speech_register ( struct ast_speech_engine engine)

Register a speech recognition engine.

Definition at line 292 of file res_speech.c.

References ast_log, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_speech_engine::create, ast_speech_engine::destroy, find_engine(), LOG_WARNING, ast_speech_engine::name, and ast_speech_engine::write.

293 {
294  int res = 0;
295 
296  /* Confirm the engine meets the minimum API requirements */
297  if (!engine->create || !engine->write || !engine->destroy) {
298  ast_log(LOG_WARNING, "Speech recognition engine '%s' did not meet minimum API requirements.\n", engine->name);
299  return -1;
300  }
301 
302  /* If an engine is already loaded with this name, error out */
303  if (find_engine(engine->name)) {
304  ast_log(LOG_WARNING, "Speech recognition engine '%s' already exists.\n", engine->name);
305  return -1;
306  }
307 
308  ast_verb(2, "Registered speech recognition engine '%s'\n", engine->name);
309 
310  /* Add to the engine linked list and make default if needed */
312  AST_RWLIST_INSERT_HEAD(&engines, engine, list);
313  if (!default_engine) {
314  default_engine = engine;
315  ast_verb(2, "Made '%s' the default speech recognition engine\n", engine->name);
316  }
318 
319  return res;
320 }
int(* destroy)(struct ast_speech *speech)
Definition: speech.h:79
int(* create)(struct ast_speech *speech, struct ast_format *format)
Definition: speech.h:77
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static struct ast_speech_engine * default_engine
Definition: res_speech.c:42
char * name
Definition: speech.h:75
#define ast_verb(level,...)
Definition: logger.h:463
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
#define ast_log
Definition: astobj2.c:42
int(* write)(struct ast_speech *speech, void *data, int len)
Definition: speech.h:89
static struct ast_speech_engine * find_engine(const char *engine_name)
Find a speech recognition engine of specified name, if NULL then use the default one.
Definition: res_speech.c:45

◆ ast_speech_results_free()

int ast_speech_results_free ( struct ast_speech_result result)

Free a list of results.

Free a set of results.

Definition at line 95 of file res_speech.c.

References ast_free, AST_LIST_NEXT, ast_speech_result::grammar, NULL, result, and ast_speech_result::text.

Referenced by ast_speech_destroy(), and ast_speech_start().

96 {
97  struct ast_speech_result *current_result = result, *prev_result = NULL;
98  int res = 0;
99 
100  while (current_result != NULL) {
101  prev_result = current_result;
102  /* Deallocate what we can */
103  if (current_result->text != NULL) {
104  ast_free(current_result->text);
105  current_result->text = NULL;
106  }
107  if (current_result->grammar != NULL) {
108  ast_free(current_result->grammar);
109  current_result->grammar = NULL;
110  }
111  /* Move on and then free ourselves */
112  current_result = AST_LIST_NEXT(current_result, list);
113  ast_free(prev_result);
114  prev_result = NULL;
115  }
116 
117  return res;
118 }
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
#define NULL
Definition: resample.c:96
char * grammar
Definition: speech.h:116
#define ast_free(a)
Definition: astmm.h:182
static PGresult * result
Definition: cel_pgsql.c:88

◆ ast_speech_results_get()

struct ast_speech_result* ast_speech_results_get ( struct ast_speech speech)

Return the results of a recognition from the speech structure.

Get speech recognition results.

Definition at line 89 of file res_speech.c.

References ast_speech::engine, ast_speech_engine::get, and NULL.

Referenced by handle_speechrecognize(), and speech_background().

90 {
91  return (speech->engine->get ? speech->engine->get(speech) : NULL);
92 }
#define NULL
Definition: resample.c:96
struct ast_speech_engine * engine
Definition: speech.h:69
struct ast_speech_result *(* get)(struct ast_speech *speech)
Definition: speech.h:101

◆ ast_speech_start()

void ast_speech_start ( struct ast_speech speech)

Start speech recognition on a speech structure.

Indicate to the speech engine that audio is now going to start being written.

Definition at line 121 of file res_speech.c.

References ast_clear_flag, AST_SPEECH_HAVE_RESULTS, AST_SPEECH_QUIET, ast_speech_results_free(), AST_SPEECH_SPOKE, ast_speech::engine, NULL, ast_speech::results, and ast_speech_engine::start.

Referenced by handle_speechrecognize(), speech_background(), and speech_start().

122 {
123 
124  /* Clear any flags that may affect things */
128 
129  /* If results are on the structure, free them since we are starting again */
130  if (speech->results) {
132  speech->results = NULL;
133  }
134 
135  /* If the engine needs to start stuff up, do it */
136  if (speech->engine->start)
137  speech->engine->start(speech);
138 
139  return;
140 }
#define NULL
Definition: resample.c:96
int(* start)(struct ast_speech *speech)
Definition: speech.h:93
struct ast_speech_engine * engine
Definition: speech.h:69
struct ast_speech_result * results
Definition: speech.h:65
int ast_speech_results_free(struct ast_speech_result *result)
Free a list of results.
Definition: res_speech.c:95
#define ast_clear_flag(p, flag)
Definition: utils.h:77

◆ ast_speech_unregister()

int ast_speech_unregister ( const char *  engine_name)

Unregister a speech recognition engine.

Definition at line 323 of file res_speech.c.

References AST_RWLIST_FIRST, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero, ast_verb, ast_speech_engine::name, and NULL.

324 {
325  struct ast_speech_engine *engine = NULL;
326  int res = -1;
327 
328  if (ast_strlen_zero(engine_name))
329  return -1;
330 
332  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&engines, engine, list) {
333  if (!strcasecmp(engine->name, engine_name)) {
334  /* We have our engine... removed it */
336  /* If this was the default engine, we need to pick a new one */
337  if (engine == default_engine) {
339  }
340  ast_verb(2, "Unregistered speech recognition engine '%s'\n", engine_name);
341  /* All went well */
342  res = 0;
343  break;
344  }
345  }
348 
349  return res;
350 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static struct ast_speech_engine * default_engine
Definition: res_speech.c:42
char * name
Definition: speech.h:75
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
#define AST_RWLIST_FIRST
Definition: linkedlists.h:422
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ ast_speech_write()

int ast_speech_write ( struct ast_speech speech,
void *  data,
int  len 
)

Write in signed linear audio to be recognized.

Write audio to the speech engine.

Definition at line 143 of file res_speech.c.

References AST_SPEECH_STATE_READY, ast_speech::engine, ast_speech::state, and ast_speech_engine::write.

Referenced by handle_speechrecognize(), and speech_background().

144 {
145  /* Make sure the speech engine is ready to accept audio */
146  if (speech->state != AST_SPEECH_STATE_READY)
147  return -1;
148 
149  return speech->engine->write(speech, data, len);
150 }
int state
Definition: speech.h:59
struct ast_speech_engine * engine
Definition: speech.h:69
int(* write)(struct ast_speech *speech, void *data, int len)
Definition: speech.h:89
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ find_engine()

static struct ast_speech_engine* find_engine ( const char *  engine_name)
static

Find a speech recognition engine of specified name, if NULL then use the default one.

Definition at line 45 of file res_speech.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero, default_engine, ast_speech_engine::name, and NULL.

Referenced by ast_speech_new(), and ast_speech_register().

46 {
47  struct ast_speech_engine *engine = NULL;
48 
49  /* If no name is specified -- use the default engine */
50  if (ast_strlen_zero(engine_name))
51  return default_engine;
52 
54  AST_RWLIST_TRAVERSE(&engines, engine, list) {
55  if (!strcasecmp(engine->name, engine_name)) {
56  break;
57  }
58  }
60 
61  return engine;
62 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
static struct ast_speech_engine * default_engine
Definition: res_speech.c:42
char * name
Definition: speech.h:75
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493

◆ load_module()

static int load_module ( void  )
static

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 352 of file res_speech.c.

Referenced by load_module().

353 {
354  /* We can not be unloaded */
355  return -1;
356 }

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Generic Speech Recognition API" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND - 1, }
static

Definition at line 368 of file res_speech.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 368 of file res_speech.c.

◆ default_engine

struct ast_speech_engine* default_engine = NULL
static

Definition at line 42 of file res_speech.c.

Referenced by find_engine().

◆ engines

struct engines engines = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static