Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Enumerations | Functions
speech.h File Reference

Generic Speech Recognition API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_speech
 
struct  ast_speech_engine
 
struct  ast_speech_result
 

Enumerations

enum  ast_speech_flags { AST_SPEECH_QUIET = (1 << 0) , AST_SPEECH_SPOKE = (1 << 1) , AST_SPEECH_HAVE_RESULTS = (1 << 2) }
 
enum  ast_speech_results_type { AST_SPEECH_RESULTS_TYPE_NORMAL = 0 , AST_SPEECH_RESULTS_TYPE_NBEST }
 
enum  ast_speech_states { AST_SPEECH_STATE_NOT_READY = 0 , AST_SPEECH_STATE_READY , AST_SPEECH_STATE_WAIT , AST_SPEECH_STATE_DONE }
 

Functions

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...
 
struct ast_speech_engineast_speech_find_engine (const char *engine_name)
 Retrieve a speech recognition engine. 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 grammar on a speech structure. More...
 
int ast_speech_grammar_deactivate (struct ast_speech *speech, const char *grammar_name)
 Deactivate a grammar on a speech structure. More...
 
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) More...
 
int ast_speech_grammar_unload (struct ast_speech *speech, const char *grammar_name)
 Unload a grammar. More...
 
struct ast_speechast_speech_new (const char *engine_name, const struct ast_format_cap *formats)
 Create a new speech structure. 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 set of results. More...
 
struct ast_speech_resultast_speech_results_get (struct ast_speech *speech)
 Get speech recognition results. More...
 
const char * ast_speech_results_type_to_string (enum ast_speech_results_type type)
 Convert a speech results type to a string. More...
 
void ast_speech_start (struct ast_speech *speech)
 Indicate to the speech engine that audio is now going to start being written. More...
 
int ast_speech_unregister (const char *engine_name)
 Unregister a speech recognition engine. More...
 
struct ast_speech_engineast_speech_unregister2 (const char *engine_name)
 Unregister a speech recognition engine. More...
 
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. More...
 
int ast_speech_write (struct ast_speech *speech, void *data, int len)
 Write audio to the speech engine. More...
 

Detailed Description

Generic Speech Recognition API.

Definition in file speech.h.

Enumeration Type Documentation

◆ ast_speech_flags

Enumerator
AST_SPEECH_QUIET 
AST_SPEECH_SPOKE 
AST_SPEECH_HAVE_RESULTS 

Definition at line 31 of file speech.h.

31 {
32 AST_SPEECH_QUIET = (1 << 0), /* Quiet down output... they are talking */
33 AST_SPEECH_SPOKE = (1 << 1), /* Speaker spoke! */
34 AST_SPEECH_HAVE_RESULTS = (1 << 2), /* Results are present */
35};
@ AST_SPEECH_QUIET
Definition: speech.h:32
@ AST_SPEECH_HAVE_RESULTS
Definition: speech.h:34
@ AST_SPEECH_SPOKE
Definition: speech.h:33

◆ ast_speech_results_type

Enumerator
AST_SPEECH_RESULTS_TYPE_NORMAL 
AST_SPEECH_RESULTS_TYPE_NBEST 

Definition at line 45 of file speech.h.

45 {
48};
@ AST_SPEECH_RESULTS_TYPE_NBEST
Definition: speech.h:47
@ AST_SPEECH_RESULTS_TYPE_NORMAL
Definition: speech.h:46

◆ ast_speech_states

Enumerator
AST_SPEECH_STATE_NOT_READY 
AST_SPEECH_STATE_READY 
AST_SPEECH_STATE_WAIT 
AST_SPEECH_STATE_DONE 

Definition at line 38 of file speech.h.

38 {
39 AST_SPEECH_STATE_NOT_READY = 0, /* Not ready to accept audio */
40 AST_SPEECH_STATE_READY, /* Accepting audio */
41 AST_SPEECH_STATE_WAIT, /* Wait for results to become available */
42 AST_SPEECH_STATE_DONE, /* Processing is all done */
43};
@ AST_SPEECH_STATE_DONE
Definition: speech.h:42
@ AST_SPEECH_STATE_READY
Definition: speech.h:40
@ AST_SPEECH_STATE_NOT_READY
Definition: speech.h:39
@ AST_SPEECH_STATE_WAIT
Definition: speech.h:41

Function Documentation

◆ 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 169 of file res_speech.c.

170{
171 return (speech->engine->change ? speech->engine->change(speech, name, value) : -1);
172}
static const char name[]
Definition: format_mp3.c:68
int(* change)(struct ast_speech *speech, const char *name, const char *value)
Definition: speech.h:98
struct ast_speech_engine * engine
Definition: speech.h:72
int value
Definition: syslog.c:37

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

Referenced by AST_TEST_DEFINE(), handle_speechset(), and speech_engine_write().

◆ 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 308 of file res_speech.c.

309{
310 speech->results_type = results_type;
311
312 return (speech->engine->change_results_type ? speech->engine->change_results_type(speech, results_type) : 0);
313}
int(* change_results_type)(struct ast_speech *speech, enum ast_speech_results_type results_type)
Definition: speech.h:102
enum ast_speech_results_type results_type
Definition: speech.h:70

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

Referenced by AST_TEST_DEFINE(), and speech_results_type_write().

◆ ast_speech_change_state()

int ast_speech_change_state ( struct ast_speech speech,
int  state 
)

Change state of a speech structure.

Definition at line 278 of file res_speech.c.

279{
280 int res = 0;
281
282 switch (state) {
284 /* The engine heard audio, so they spoke */
286 default:
287 speech->state = state;
288 break;
289 }
290
291 return res;
292}
enum cc_state state
Definition: ccss.c:393
int state
Definition: speech.h:62
#define ast_set_flag(p, flag)
Definition: utils.h:70

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

Referenced by ast_aeap_speech_on_error(), ast_speech_new(), handle_request_set(), handle_speechrecognize(), speech_aeap_engine_start(), and speech_background().

◆ ast_speech_destroy()

int ast_speech_destroy ( struct ast_speech speech)

Destroy a speech structure.

Definition at line 251 of file res_speech.c.

252{
253 int res = 0;
254
255 /* Call our engine so we are destroyed properly */
256 speech->engine->destroy(speech);
257
258 /* Deinitialize the lock */
259 ast_mutex_destroy(&speech->lock);
260
261 /* If results exist on the speech structure, destroy them */
262 if (speech->results)
264
265 /* If a processing sound is set - free the memory used by it */
266 if (speech->processing_sound)
267 ast_free(speech->processing_sound);
268
269 ao2_ref(speech->format, -1);
270
271 /* Aloha we are done */
272 ast_free(speech);
273
274 return res;
275}
#define ast_free(a)
Definition: astmm.h:180
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_mutex_destroy(a)
Definition: lock.h:188
int ast_speech_results_free(struct ast_speech_result *result)
Free a list of results.
Definition: res_speech.c:96
int(* destroy)(struct ast_speech *speech)
Definition: speech.h:82
char * processing_sound
Definition: speech.h:60
struct ast_format * format
Definition: speech.h:64
ast_mutex_t lock
Definition: speech.h:56
struct ast_speech_result * results
Definition: speech.h:68

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 AST_TEST_DEFINE(), destroy_callback(), handle_speechdestroy(), launch_asyncagi(), run_agi(), and speech_create().

◆ 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 154 of file res_speech.c.

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

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

Referenced by AST_TEST_DEFINE(), and speech_background().

◆ ast_speech_find_engine()

struct ast_speech_engine * ast_speech_find_engine ( const char *  engine_name)

Retrieve a speech recognition engine.

Retrieve a speech recognition engine.

Definition at line 46 of file res_speech.c.

47{
48 struct ast_speech_engine *engine = NULL;
49
50 /* If no name is specified -- use the default engine */
51 if (ast_strlen_zero(engine_name))
52 return default_engine;
53
55 AST_RWLIST_TRAVERSE(&engines, engine, list) {
56 if (!strcasecmp(engine->name, engine_name)) {
57 break;
58 }
59 }
61
62 return engine;
63}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
static struct ast_speech_engine * default_engine
Definition: res_speech.c:43
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
char * name
Definition: speech.h:78

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(), ast_speech_register(), and load_engine().

◆ 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 175 of file res_speech.c.

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

References buf, ast_speech::engine, ast_speech_engine::get_setting, len(), and name.

Referenced by AST_TEST_DEFINE(), and speech_engine_read().

◆ ast_speech_grammar_activate()

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

Activate a grammar on a speech structure.

Activate a grammar on a speech structure.

Definition at line 66 of file res_speech.c.

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

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

Referenced by handle_speechactivategrammar(), and speech_activate().

◆ ast_speech_grammar_deactivate()

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

Deactivate a grammar on a speech structure.

Deactivate a grammar on a speech structure.

Definition at line 72 of file res_speech.c.

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

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

Referenced by handle_speechdeactivategrammar(), and speech_deactivate().

◆ ast_speech_grammar_load()

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)

Load a grammar on a speech structure (not globally)

Definition at line 78 of file res_speech.c.

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

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

Referenced by handle_speechloadgrammar(), and speech_load().

◆ ast_speech_grammar_unload()

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

Unload a grammar.

Unload a grammar.

Definition at line 84 of file res_speech.c.

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

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

Referenced by handle_speechunloadgrammar(), and speech_unload().

◆ ast_speech_new()

struct ast_speech * ast_speech_new ( const char *  engine_name,
const struct ast_format_cap cap 
)

Create a new speech structure.

Create a new speech structure.

Definition at line 181 of file res_speech.c.

182{
183 struct ast_speech_engine *engine = NULL;
184 struct ast_speech *new_speech = NULL;
185 struct ast_format_cap *joint;
186 RAII_VAR(struct ast_format *, best, NULL, ao2_cleanup);
187 RAII_VAR(struct ast_format *, best_translated, NULL, ao2_cleanup);
188
189 /* Try to find the speech recognition engine that was requested */
190 if (!(engine = ast_speech_find_engine(engine_name)))
191 return NULL;
192
194 if (!joint) {
195 return NULL;
196 }
197
198 ast_format_cap_get_compatible(engine->formats, cap, joint);
199 best = ast_format_cap_get_format(joint, 0);
200 ao2_ref(joint, -1);
201
202 if (!best) {
205 } else {
206 /*
207 * If there is no overlap and the engine does not support slin, find the best
208 * format to translate to and set that as the 'best' input format for the engine.
209 * API consumer is responsible for translating to this format.
210 * Safe to cast cap as ast_translator_best_choice does not modify the caps
211 */
212 if (ast_translator_best_choice(engine->formats, (struct ast_format_cap *)cap, &best, &best_translated)) {
213 /* No overlapping formats and no translatable formats */
214 return NULL;
215 }
216 }
217 }
218
219 /* Allocate our own speech structure, and try to allocate a structure from the engine too */
220 if (!(new_speech = ast_calloc(1, sizeof(*new_speech)))) {
221 return NULL;
222 }
223
224 /* Initialize the lock */
225 ast_mutex_init(&new_speech->lock);
226
227 /* Make sure no results are present */
228 new_speech->results = NULL;
229
230 /* Copy over our engine pointer */
231 new_speech->engine = engine;
232
233 /* Can't forget the format audio is going to be in */
234 new_speech->format = ao2_bump(best);
235
236 /* We are not ready to accept audio yet */
238
239 /* Pass ourselves to the engine so they can set us up some more and if they error out then do not create a structure */
240 if (engine->create(new_speech, new_speech->format)) {
241 ast_mutex_destroy(&new_speech->lock);
242 ao2_ref(new_speech->format, -1);
243 ast_free(new_speech);
244 return NULL;
245 }
246
247 return new_speech;
248}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
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
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:628
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:581
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
#define ast_mutex_init(pmutex)
Definition: lock.h:186
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.
Definition: res_speech.c:46
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
Definition: res_speech.c:278
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Definition of a media format.
Definition: format.c:43
struct ast_format_cap * formats
Definition: speech.h:106
int(* create)(struct ast_speech *speech, struct ast_format *format)
Definition: speech.h:80
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.
Definition: translate.c:1402
#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:941

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_find_engine(), AST_SPEECH_STATE_NOT_READY, ast_translator_best_choice(), ast_speech_engine::create, ast_speech::engine, ast_speech::format, ast_speech_engine::formats, ast_speech::lock, NULL, RAII_VAR, and ast_speech::results.

Referenced by AST_TEST_DEFINE(), handle_speechcreate(), and speech_create().

◆ ast_speech_register()

int ast_speech_register ( struct ast_speech_engine engine)

Register a speech recognition engine.

Definition at line 316 of file res_speech.c.

317{
318 int res = 0;
319
320 /* Confirm the engine meets the minimum API requirements */
321 if (!engine->create || !engine->write || !engine->destroy) {
322 ast_log(LOG_WARNING, "Speech recognition engine '%s' did not meet minimum API requirements.\n", engine->name);
323 return -1;
324 }
325
326 /* If an engine is already loaded with this name, error out */
327 if (ast_speech_find_engine(engine->name)) {
328 ast_log(LOG_WARNING, "Speech recognition engine '%s' already exists.\n", engine->name);
329 return -1;
330 }
331
332 ast_verb(5, "Registered speech recognition engine '%s'\n", engine->name);
333
334 /* Add to the engine linked list and make default if needed */
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);
340 }
342
343 return res;
344}
#define ast_log
Definition: astobj2.c:42
#define ast_verb(level,...)
#define LOG_WARNING
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
int(* write)(struct ast_speech *speech, void *data, int len)
Definition: speech.h:92

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

Referenced by speech_engine_alloc_and_register().

◆ ast_speech_results_free()

int ast_speech_results_free ( struct ast_speech_result result)

Free a set of results.

Free a set of results.

Definition at line 96 of file res_speech.c.

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

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

Referenced by ast_speech_destroy(), ast_speech_start(), and AST_TEST_DEFINE().

◆ ast_speech_results_get()

struct ast_speech_result * ast_speech_results_get ( struct ast_speech speech)

Get speech recognition results.

Get speech recognition results.

Definition at line 90 of file res_speech.c.

91{
92 return (speech->engine->get ? speech->engine->get(speech) : NULL);
93}
struct ast_speech_result *(* get)(struct ast_speech *speech)
Definition: speech.h:104

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

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

◆ ast_speech_results_type_to_string()

const char * ast_speech_results_type_to_string ( enum ast_speech_results_type  type)

Convert a speech results type to a string.

Definition at line 294 of file res_speech.c.

295{
296 switch (type) {
298 return "normal";
300 return "nbest";
301 default:
302 ast_assert(0);
303 return "unknown";
304 }
305}
static const char type[]
Definition: chan_ooh323.c:109
#define ast_assert(a)
Definition: utils.h:739

References ast_assert, AST_SPEECH_RESULTS_TYPE_NBEST, AST_SPEECH_RESULTS_TYPE_NORMAL, and type.

Referenced by speech_aeap_engine_change_results_type().

◆ ast_speech_start()

void ast_speech_start ( struct ast_speech speech)

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

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

Definition at line 122 of file res_speech.c.

123{
124
125 /* Clear any flags that may affect things */
129
130 /* If results are on the structure, free them since we are starting again */
131 if (speech->results) {
133 speech->results = NULL;
134 }
135
136 /* If the engine needs to start stuff up, do it */
137 if (speech->engine->start)
138 speech->engine->start(speech);
139
140 return;
141}
int(* start)(struct ast_speech *speech)
Definition: speech.h:96
#define ast_clear_flag(p, flag)
Definition: utils.h:77

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 AST_TEST_DEFINE(), handle_speechrecognize(), speech_background(), and speech_start().

◆ ast_speech_unregister()

int ast_speech_unregister ( const char *  engine_name)

Unregister a speech recognition engine.

Definition at line 347 of file res_speech.c.

348{
349 return ast_speech_unregister2(engine_name) == NULL ? -1 : 0;
350}
struct ast_speech_engine * ast_speech_unregister2(const char *engine_name)
Unregister a speech recognition engine.
Definition: res_speech.c:352

References ast_speech_unregister2(), and NULL.

◆ ast_speech_unregister2()

struct ast_speech_engine * ast_speech_unregister2 ( const char *  engine_name)

Unregister a speech recognition engine.

Definition at line 352 of file res_speech.c.

353{
354 struct ast_speech_engine *engine = NULL;
355
356 if (ast_strlen_zero(engine_name)) {
357 return NULL;
358 }
359
362 if (!strcasecmp(engine->name, engine_name)) {
363 /* We have our engine... removed it */
365 /* If this was the default engine, we need to pick a new one */
366 if (engine == default_engine) {
368 }
369 ast_verb(5, "Unregistered speech recognition engine '%s'\n", engine_name);
370 /* All went well */
371 break;
372 }
373 }
376
377 return engine;
378}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_FIRST
Definition: linkedlists.h:423
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

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, default_engine, ast_speech_engine::name, and NULL.

Referenced by ast_speech_unregister(), load_engine(), unload_engine(), and unload_module().

◆ ast_speech_unregister_engines()

void ast_speech_unregister_engines ( int(*)(const struct ast_speech_engine *engine, void *data)  should_unregister,
void *  data,
void(*)(void *obj)  on_unregistered 
)

Unregister all speech recognition engines told to by callback.

Definition at line 380 of file res_speech.c.

383{
384 struct ast_speech_engine *engine = NULL;
385
386 if (!should_unregister) {
387 return;
388 }
389
392 if (should_unregister(engine, data)) {
393 /* We have our engine... removed it */
395 /* If this was the default engine, we need to pick a new one */
396 if (engine == default_engine) {
398 }
399 ast_verb(5, "Unregistered speech recognition engine '%s'\n", engine->name);
400 /* All went well */
401 if (on_unregistered) {
402 on_unregistered(engine);
403 }
404 }
405 }
408}
static int should_unregister(const struct ast_speech_engine *engine, void *data)

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_verb, default_engine, ast_speech_engine::name, NULL, and should_unregister().

Referenced by speech_observer_loaded().

◆ ast_speech_write()

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

Write audio to the speech engine.

Write audio to the speech engine.

Definition at line 144 of file res_speech.c.

145{
146 /* Make sure the speech engine is ready to accept audio */
147 if (speech->state != AST_SPEECH_STATE_READY)
148 return -1;
149
150 return speech->engine->write(speech, data, len);
151}

References AST_SPEECH_STATE_READY, ast_speech::engine, len(), ast_speech::state, and ast_speech_engine::write.

Referenced by handle_speechrecognize(), and speech_background().