From e4811a8248c88e14bd4b3421bdf692d228707fdb Mon Sep 17 00:00:00 2001 From: Joshua Colp Date: Mon, 10 Apr 2006 23:29:50 +0000 Subject: Presenting a revised data stores and oh my, a generic speech recognition API! I wonder what we can do with this now... git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@18979 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/speech.h | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 include/asterisk/speech.h (limited to 'include/asterisk/speech.h') diff --git a/include/asterisk/speech.h b/include/asterisk/speech.h new file mode 100644 index 000000000..f6aa2b0dc --- /dev/null +++ b/include/asterisk/speech.h @@ -0,0 +1,125 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2006, Digium, Inc. + * + * Joshua Colp + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * \brief Generic Speech Recognition API + */ + +#ifndef _ASTERISK_SPEECH_H +#define _ASTERISK_SPEECH_H + +#if defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +/* Speech structure flags */ +#define AST_SPEECH_QUIET (1 << 0) /* Quiet down output... they are talking */ + +/* Speech structure states - in order of expected change */ +#define AST_SPEECH_STATE_NOT_READY 0 /* Not ready to accept audio */ +#define AST_SPEECH_STATE_READY 1 /* Accepting audio */ +#define AST_SPEECH_STATE_WAIT 2 /* Wait for results to become available */ +#define AST_SPEECH_STATE_DONE 3 /* Processing is done */ + +/* Speech structure */ +struct ast_speech { + /*! Structure lock */ + ast_mutex_t lock; + /*! Set flags */ + unsigned int flags; + /*! Processing sound (used when engine is processing audio and getting results) */ + char *processing_sound; + /*! Current state of structure */ + int state; + /*! Expected write format */ + int format; + /*! Data for speech engine */ + void *data; + /*! Pointer to the engine used by this speech structure */ + struct ast_speech_engine *engine; +}; + +/* Speech recognition engine structure */ +struct ast_speech_engine { + /*! Name of speech engine */ + char *name; + /*! Set up the speech structure within the engine */ + int (*new)(struct ast_speech *speech); + /*! Destroy any data set on the speech structure by the engine */ + int (*destroy)(struct ast_speech *speech); + /*! Load a local grammar on the speech structure */ + int (*load)(struct ast_speech *speech, char *grammar_name, char *grammar); + /*! Unload a local grammar */ + int (*unload)(struct ast_speech *speech, char *grammar_name); + /*! Activate a loaded grammar */ + int (*activate)(struct ast_speech *speech, char *grammar_name); + /*! Deactivate a loaded grammar */ + int (*deactivate)(struct ast_speech *speech, char *grammar_name); + /*! Write audio to the speech engine */ + int (*write)(struct ast_speech *speech, void *data, int len); + /*! Prepare engine to accept audio */ + int (*start)(struct ast_speech *speech); + /*! Try to get results */ + struct ast_speech_result *(*get)(struct ast_speech *speech); + /*! Accepted formats by the engine */ + int formats; + AST_LIST_ENTRY(ast_speech_engine) list; +}; + +/* Result structure */ +struct ast_speech_result { + /*! Recognized text */ + char *text; + /*! Result score */ + int score; + /*! Next result (may not always be present) */ + struct ast_speech_result *next; +}; + +/*! \brief Activate a grammar on a speech structure */ +int ast_speech_grammar_activate(struct ast_speech *speech, char *grammar_name); +/*! \brief Deactivate a grammar on a speech structure */ +int ast_speech_grammar_deactivate(struct ast_speech *speech, char *grammar_name); +/*! \brief Load a grammar on a speech structure (not globally) */ +int ast_speech_grammar_load(struct ast_speech *speech, char *grammar_name, char *grammar); +/*! \brief Unload a grammar */ +int ast_speech_grammar_unload(struct ast_speech *speech, char *grammar_name); +/*! \brief Get speech recognition results */ +struct ast_speech_result *ast_speech_results_get(struct ast_speech *speech); +/*! \brief Free a set of results */ +int ast_speech_results_free(struct ast_speech_result *result); +/*! \brief Indicate to the speech engine that audio is now going to start being written */ +void ast_speech_start(struct ast_speech *speech); +/*! \brief Create a new speech structure */ +struct ast_speech *ast_speech_new(char *engine_name, int format); +/*! \brief Destroy a speech structure */ +int ast_speech_destroy(struct ast_speech *speech); +/*! \brief Write audio to the speech engine */ +int ast_speech_write(struct ast_speech *speech, void *data, int len); +/*! \brief Change state of a speech structure */ +int ast_speech_change_state(struct ast_speech *speech, int state); +/*! \brief Register a speech recognition engine */ +int ast_speech_register(struct ast_speech_engine *engine); +/*! \brief Unregister a speech recognition engine */ +int ast_speech_unregister(char *engine_name); + +#if defined(__cplusplus) || defined(c_plusplus) +} +#endif + +#endif /* _ASTERISK_SPEECH_H */ -- cgit v1.2.3