39 #define ADDR "127.0.0.1:8088"
41 static int speech_test_server_setup(
struct ast_json *req,
struct ast_json *resp)
57 #define TEST_SPEECH_RESULTS_TEXT "foo"
58 #define TEST_SPEECH_RESULTS_SCORE 7
59 #define TEST_SPEECH_RESULTS_GRAMMAR "bar"
60 #define TEST_SPEECH_RESULTS_BEST 1
62 static int speech_test_server_get(
struct ast_json *req,
struct ast_json *resp)
72 if (!strcmp(param,
"results")) {
75 "text", TEST_SPEECH_RESULTS_TEXT,
76 "score", TEST_SPEECH_RESULTS_SCORE,
77 "grammar", TEST_SPEECH_RESULTS_GRAMMAR,
78 "best", TEST_SPEECH_RESULTS_BEST);
91 static int speech_test_server_set(
struct ast_json *req,
struct ast_json *resp)
100 static int speech_test_server_handle_request(
struct ast_websocket *ws,
const void *buf, uint64_t size)
110 ast_log(LOG_ERROR,
"speech test handle request: unable to load json\n");
116 ast_log(LOG_ERROR,
"speech test handle request: no name\n");
124 ast_log(LOG_ERROR,
"speech test handle request: unable to create response '%s'\n", name);
129 if (!strcmp(name,
"setup")) {
130 res = speech_test_server_setup(req, resp);
131 }
else if (!strcmp(name,
"get")) {
132 res = speech_test_server_get(req, resp);
133 }
else if (!strcmp(name,
"set")) {
134 res = speech_test_server_set(req, resp);
136 ast_log(LOG_ERROR,
"speech test handle request: unsupported request '%s'\n", name);
141 ast_log(LOG_ERROR,
"speech test handle request: unable to build response '%s'\n", name);
151 ast_log(LOG_ERROR,
"speech test handle request: unable to dump response '%s'\n", name);
156 res = ast_websocket_write_string(ws, resp_buf);
158 ast_log(LOG_ERROR,
"speech test handle request: unable to write response '%s'\n", name);
173 ast_websocket_unref(ws);
177 while ((res = ast_websocket_wait_for_input(ws, -1)) > 0) {
179 uint64_t payload_len;
183 if (ast_websocket_read(ws, &payload, &payload_len, &opcode, &fragmented)) {
184 ast_log(LOG_ERROR,
"speech test: Read failure in server loop\n");
190 ast_websocket_unref(ws);
196 ast_debug(3,
"payload=%.*s\n", (
int)payload_len, payload);
197 if (speech_test_server_handle_request(ws, payload, payload_len)) {
198 ast_websocket_unref(ws);
206 ast_websocket_unref(ws);
214 enum ast_test_result_state res = AST_TEST_PASS;
219 info->name = __func__;
220 info->explicit_only = 0;
221 info->category =
"/res/aeap/speech/";
222 info->summary =
"test the speech AEAP interface";
223 info->description = info->summary;
224 return AST_TEST_NOT_RUN;
229 ast_test_validate(
test, !ast_websocket_add_protocol(
"_aeap_test_speech_", speech_test_server_cb));
239 speech, AST_SPEECH_RESULTS_TYPE_NBEST), res,
cleanup);
242 speech,
"foo", buf,
sizeof(buf)), res,
cleanup);
243 ast_test_validate_cleanup(
test, !strcmp(buf,
"bar"), res,
cleanup);
255 ast_websocket_remove_protocol(
"_aeap_test_speech_", speech_test_server_cb);
262 static int load_module(
void)
264 if (!(http_server = ast_http_test_server_get(
"aeap transport http server", NULL))) {
268 AST_TEST_REGISTER(res_speech_aeap_test);
273 static int unload_module(
void)
275 AST_TEST_UNREGISTER(res_speech_aeap_test);
277 ast_http_test_server_discard(http_server);
282 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Asterisk External Application Protocol Speech test(s)",
283 .support_level = AST_MODULE_SUPPORT_CORE,
285 .unload = unload_module,
286 .requires =
"res_speech_aeap",
Asterisk External Application Protocol API.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Generic Speech Recognition API.
int ast_speech_destroy(struct ast_speech *speech)
Destroy a speech structure.
struct ast_json * ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
Parse buffer with known length into a JSON object or array.
void ast_speech_start(struct ast_speech *speech)
Indicate to the speech engine that audio is now going to start being written.
Asterisk External Application Protocol Message API.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Structure for variables, used for configurations and for channel variables.
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
struct ast_speech_result * ast_speech_results_get(struct ast_speech *speech)
Get speech recognition results.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
int ast_speech_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
Change the type of results we want.
Support for Private Asterisk HTTP Servers.
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
static void cleanup(void)
Clean up any old apps that we don't need any more.
Asterisk JSON abstraction layer.
#define ast_json_object_string_get(object, key)
Get a string field from a JSON object.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_speech_result * results
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
int AST_OPTIONAL_API_NAME() ast_websocket_write(struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size)
Write function for websocket traffic.
Structure definition for session.
Module has failed to load, may be in an inconsistent state.
int ast_speech_results_free(struct ast_speech_result *result)
Free a set of results.
int ast_speech_dtmf(struct ast_speech *speech, const char *dtmf)
Signal to the engine that DTMF was received.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
struct ast_speech * ast_speech_new(const char *engine_name, const struct ast_format_cap *formats)
Create a new speech structure.
#define AST_TEST_DEFINE(hdr)
Abstract JSON element (object, array, string, int, ...).
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_speech_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len)
Get an engine specific attribute.
Asterisk module definitions.
ast_websocket_opcode
WebSocket operation codes.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_speech_change(struct ast_speech *speech, const char *name, const char *value)
Change an engine specific attribute.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.