[Asterisk-code-review] res_speech: Add a type conversion, and new engine unregister methods (asterisk[18])

Kevin Harwell asteriskteam at digium.com
Thu Oct 21 13:02:41 CDT 2021


Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16644 )


Change subject: res_speech: Add a type conversion, and new engine unregister methods
......................................................................

res_speech: Add a type conversion, and new engine unregister methods

Add a new function that converts a speech results type to a string.
Also add another function to unregister an engine, but returns a
pointer to the unregistered engine object instead of a success/fail
integer.

Change-Id: I0f7de17cb411021c09fb03988bc2b904e1380192
---
M include/asterisk/speech.h
M res/res_speech.c
2 files changed, 28 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/44/16644/1

diff --git a/include/asterisk/speech.h b/include/asterisk/speech.h
index 7af7e99..681c536 100644
--- a/include/asterisk/speech.h
+++ b/include/asterisk/speech.h
@@ -47,6 +47,9 @@
 	AST_SPEECH_RESULTS_TYPE_NBEST,
 };
 
+/*! \brief Convert a speech results type to a string */
+const char *ast_speech_results_type_to_string(enum ast_speech_results_type type);
+
 /* Speech structure */
 struct ast_speech {
 	/*! Structure lock */
@@ -152,6 +155,9 @@
 int ast_speech_register(struct ast_speech_engine *engine);
 /*! \brief Unregister a speech recognition engine */
 int ast_speech_unregister(const char *engine_name);
+/*! \brief Unregister a speech recognition engine */
+struct ast_speech_engine *ast_speech_unregister2(const char *engine_name);
+
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }
diff --git a/res/res_speech.c b/res/res_speech.c
index 57f6fa6..382c9ab 100644
--- a/res/res_speech.c
+++ b/res/res_speech.c
@@ -280,6 +280,18 @@
 	return res;
 }
 
+const char *ast_speech_results_type_to_string(enum ast_speech_results_type type)
+{
+	switch (type) {
+	case AST_SPEECH_RESULTS_TYPE_NORMAL:
+		return "normal";
+	case AST_SPEECH_RESULTS_TYPE_NBEST:
+		return "nbest";
+	default:
+		return "unknown";
+	}
+}
+
 /*! \brief Change the type of results we want */
 int ast_speech_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
 {
@@ -322,11 +334,16 @@
 /*! \brief Unregister a speech recognition engine */
 int ast_speech_unregister(const char *engine_name)
 {
-	struct ast_speech_engine *engine = NULL;
-	int res = -1;
+	return ast_speech_unregister2(engine_name) == NULL ? -1 : 0;
+}
 
-	if (ast_strlen_zero(engine_name))
-		return -1;
+struct ast_speech_engine *ast_speech_unregister2(const char *engine_name)
+{
+	struct ast_speech_engine *engine = NULL;
+
+	if (ast_strlen_zero(engine_name)) {
+		return NULL;
+	}
 
 	AST_RWLIST_WRLOCK(&engines);
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&engines, engine, list) {
@@ -339,14 +356,13 @@
 			}
 			ast_verb(2, "Unregistered speech recognition engine '%s'\n", engine_name);
 			/* All went well */
-			res = 0;
 			break;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 	AST_RWLIST_UNLOCK(&engines);
 
-	return res;
+	return engine;
 }
 
 static int unload_module(void)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16644
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I0f7de17cb411021c09fb03988bc2b904e1380192
Gerrit-Change-Number: 16644
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211021/32a49cc3/attachment-0001.html>


More information about the asterisk-code-review mailing list