res_aeap & res_speech_aeap: Add Asterisk External Application Protocol

Add framework to connect to, and read and write protocol based
messages from and to an external application using an Asterisk
External Application Protocol (AEAP). This has been divided into
several abstractions:

 1. transport - base communication layer (currently websocket only)
 2. message - AEAP description and data (currently JSON only)
 3. transaction - links/binds requests and responses
 4. aeap - transport, message, and transaction handler/manager

This patch also adds an AEAP implementation for speech to text.
Existing speech API callbacks for speech to text have been completed
making it possible for Asterisk to connect to a configured external
translator service and provide audio for STT. Results can also be
received from the external translator, and made available as speech
results in Asterisk.

Unit tests have also been created that test the AEAP framework, and
also the speech to text implementation.

ASTERISK-29726 #close

Change-Id: Iaa4b259f84aa63501e5fd2a6fb107f900b4d4ed2
This commit is contained in:
Kevin Harwell
2021-06-18 12:54:10 -05:00
committed by Friendly Automation
parent 53a3af6321
commit 272bac70dd
25 changed files with 4831 additions and 57 deletions

View File

@@ -42,7 +42,7 @@ static AST_RWLIST_HEAD_STATIC(engines, ast_speech_engine);
static struct ast_speech_engine *default_engine = NULL;
/*! \brief Find a speech recognition engine of specified name, if NULL then use the default one */
static struct ast_speech_engine *find_engine(const char *engine_name)
struct ast_speech_engine *ast_speech_find_engine(const char *engine_name)
{
struct ast_speech_engine *engine = NULL;
@@ -185,7 +185,7 @@ struct ast_speech *ast_speech_new(const char *engine_name, const struct ast_form
RAII_VAR(struct ast_format *, best, NULL, ao2_cleanup);
/* Try to find the speech recognition engine that was requested */
if (!(engine = find_engine(engine_name)))
if (!(engine = ast_speech_find_engine(engine_name)))
return NULL;
joint = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
@@ -313,7 +313,7 @@ int ast_speech_register(struct ast_speech_engine *engine)
}
/* If an engine is already loaded with this name, error out */
if (find_engine(engine->name)) {
if (ast_speech_find_engine(engine->name)) {
ast_log(LOG_WARNING, "Speech recognition engine '%s' already exists.\n", engine->name);
return -1;
}
@@ -366,6 +366,36 @@ struct ast_speech_engine *ast_speech_unregister2(const char *engine_name)
return engine;
}
void ast_speech_unregister_engines(
int (*should_unregister)(const struct ast_speech_engine *engine, void *data), void *data,
void (*on_unregistered)(void *obj))
{
struct ast_speech_engine *engine = NULL;
if (!should_unregister) {
return;
}
AST_RWLIST_WRLOCK(&engines);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&engines, engine, list) {
if (should_unregister(engine, data)) {
/* We have our engine... removed it */
AST_RWLIST_REMOVE_CURRENT(list);
/* If this was the default engine, we need to pick a new one */
if (engine == default_engine) {
default_engine = AST_RWLIST_FIRST(&engines);
}
ast_verb(2, "Unregistered speech recognition engine '%s'\n", engine->name);
/* All went well */
if (on_unregistered) {
on_unregistered(engine);
}
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&engines);
}
static int unload_module(void)
{
/* We can not be unloaded */