Asterisk - The Open Source Telephony Project  18.5.0
speech.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Digium, Inc.
5  *
6  * Joshua Colp <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Generic Speech Recognition API
21  */
22 
23 #ifndef _ASTERISK_SPEECH_H
24 #define _ASTERISK_SPEECH_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 /* Speech structure flags */
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 };
36 
37 /* Speech structure states - in order of expected change */
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 };
44 
48 };
49 
50 /* Speech structure */
51 struct ast_speech {
52  /*! Structure lock */
54  /*! Set flags */
55  unsigned int flags;
56  /*! Processing sound (used when engine is processing audio and getting results) */
58  /*! Current state of structure */
59  int state;
60  /*! Expected write format */
61  struct ast_format *format;
62  /*! Data for speech engine */
63  void *data;
64  /*! Cached results */
66  /*! Type of results we want */
68  /*! Pointer to the engine used by this speech structure */
70 };
71 
72 /* Speech recognition engine structure */
74  /*! Name of speech engine */
75  char *name;
76  /*! Set up the speech structure within the engine */
77  int (*create)(struct ast_speech *speech, struct ast_format *format);
78  /*! Destroy any data set on the speech structure by the engine */
79  int (*destroy)(struct ast_speech *speech);
80  /*! Load a local grammar on the speech structure */
81  int (*load)(struct ast_speech *speech, const char *grammar_name, const char *grammar);
82  /*! Unload a local grammar */
83  int (*unload)(struct ast_speech *speech, const char *grammar_name);
84  /*! Activate a loaded grammar */
85  int (*activate)(struct ast_speech *speech, const char *grammar_name);
86  /*! Deactivate a loaded grammar */
87  int (*deactivate)(struct ast_speech *speech, const char *grammar_name);
88  /*! Write audio to the speech engine */
89  int (*write)(struct ast_speech *speech, void *data, int len);
90  /*! Signal DTMF was received */
91  int (*dtmf)(struct ast_speech *speech, const char *dtmf);
92  /*! Prepare engine to accept audio */
93  int (*start)(struct ast_speech *speech);
94  /*! Change an engine specific setting */
95  int (*change)(struct ast_speech *speech, const char *name, const char *value);
96  /*! Get an engine specific setting */
97  int (*get_setting)(struct ast_speech *speech, const char *name, char *buf, size_t len);
98  /*! Change the type of results we want back */
99  int (*change_results_type)(struct ast_speech *speech, enum ast_speech_results_type results_type);
100  /*! Try to get results */
101  struct ast_speech_result *(*get)(struct ast_speech *speech);
102  /*! Accepted formats by the engine */
105 };
106 
107 /* Result structure */
109  /*! Recognized text */
110  char *text;
111  /*! Result score */
112  int score;
113  /*! NBest Alternative number if in NBest results type */
115  /*! Matched grammar */
116  char *grammar;
117  /*! List information */
119 };
120 
121 /*! \brief Activate a grammar on a speech structure */
122 int ast_speech_grammar_activate(struct ast_speech *speech, const char *grammar_name);
123 /*! \brief Deactivate a grammar on a speech structure */
124 int ast_speech_grammar_deactivate(struct ast_speech *speech, const char *grammar_name);
125 /*! \brief Load a grammar on a speech structure (not globally) */
126 int ast_speech_grammar_load(struct ast_speech *speech, const char *grammar_name, const char *grammar);
127 /*! \brief Unload a grammar */
128 int ast_speech_grammar_unload(struct ast_speech *speech, const char *grammar_name);
129 /*! \brief Get speech recognition results */
130 struct ast_speech_result *ast_speech_results_get(struct ast_speech *speech);
131 /*! \brief Free a set of results */
133 /*! \brief Indicate to the speech engine that audio is now going to start being written */
134 void ast_speech_start(struct ast_speech *speech);
135 /*! \brief Create a new speech structure */
136 struct ast_speech *ast_speech_new(const char *engine_name, const struct ast_format_cap *formats);
137 /*! \brief Destroy a speech structure */
138 int ast_speech_destroy(struct ast_speech *speech);
139 /*! \brief Write audio to the speech engine */
140 int ast_speech_write(struct ast_speech *speech, void *data, int len);
141 /*! \brief Signal to the engine that DTMF was received */
142 int ast_speech_dtmf(struct ast_speech *speech, const char *dtmf);
143 /*! \brief Change an engine specific attribute */
144 int ast_speech_change(struct ast_speech *speech, const char *name, const char *value);
145 /*! \brief Get an engine specific attribute */
146 int ast_speech_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len);
147 /*! \brief Change the type of results we want */
149 /*! \brief Change state of a speech structure */
150 int ast_speech_change_state(struct ast_speech *speech, int state);
151 /*! \brief Register a speech recognition engine */
153 /*! \brief Unregister a speech recognition engine */
154 int ast_speech_unregister(const char *engine_name);
155 
156 #if defined(__cplusplus) || defined(c_plusplus)
157 }
158 #endif
159 
160 #endif /* _ASTERISK_SPEECH_H */
int state
Definition: speech.h:59
int ast_speech_destroy(struct ast_speech *speech)
Destroy a speech structure.
Definition: res_speech.c:240
void ast_speech_start(struct ast_speech *speech)
Indicate to the speech engine that audio is now going to start being written.
Definition: res_speech.c:121
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
enum ast_speech_results_type results_type
Definition: speech.h:67
int ast_speech_register(struct ast_speech_engine *engine)
Register a speech recognition engine.
Definition: res_speech.c:292
struct ast_speech_result * ast_speech_results_get(struct ast_speech *speech)
Get speech recognition results.
Definition: res_speech.c:89
Definition of a media format.
Definition: format.c:43
void * data
Definition: speech.h:63
char * name
Definition: speech.h:75
int value
Definition: syslog.c:37
char * grammar
Definition: speech.h:116
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: res_speech.c:284
ast_speech_results_type
Definition: speech.h:45
int ast_speech_grammar_deactivate(struct ast_speech *speech, const char *grammar_name)
Deactivate a grammar on a speech structure.
Definition: res_speech.c:71
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
Definition: res_speech.c:267
struct ast_format_cap * formats
Definition: speech.h:103
struct ast_speech_engine * engine
Definition: speech.h:69
int ast_speech_grammar_unload(struct ast_speech *speech, const char *grammar_name)
Unload a grammar.
Definition: res_speech.c:83
struct ast_speech_result * results
Definition: speech.h:65
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
int ast_speech_grammar_activate(struct ast_speech *speech, const char *grammar_name)
Activate a grammar on a speech structure.
Definition: res_speech.c:65
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Definition: file.c:69
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
unsigned int flags
Definition: speech.h:55
static const char name[]
Definition: cdr_mysql.c:74
static void destroy(struct ast_trans_pvt *pvt)
Definition: translate.c:291
struct ast_format * format
Definition: speech.h:61
int ast_speech_results_free(struct ast_speech_result *result)
Free a set of results.
Definition: res_speech.c:95
ast_mutex_t lock
Definition: speech.h:53
ast_speech_states
Definition: speech.h:38
int ast_speech_dtmf(struct ast_speech *speech, const char *dtmf)
Signal to the engine that DTMF was received.
Definition: res_speech.c:153
int ast_speech_unregister(const char *engine_name)
Unregister a speech recognition engine.
Definition: res_speech.c:323
struct ast_speech * ast_speech_new(const char *engine_name, const struct ast_format_cap *formats)
Create a new speech structure.
Definition: res_speech.c:180
static PGresult * result
Definition: cel_pgsql.c:88
int(* dtmf)(struct ast_speech *speech, const char *dtmf)
Definition: speech.h:91
char * processing_sound
Definition: speech.h:57
int ast_speech_write(struct ast_speech *speech, void *data, int len)
Write audio to the speech engine.
Definition: res_speech.c:143
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)
Definition: res_speech.c:77
ast_speech_flags
Definition: speech.h:31
int ast_speech_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len)
Get an engine specific attribute.
Definition: res_speech.c:174
int ast_speech_change(struct ast_speech *speech, const char *name, const char *value)
Change an engine specific attribute.
Definition: res_speech.c:168
Structure for mutex and tracking information.
Definition: lock.h:135