43#define SPEECH_AEAP_VERSION "0.1.0"
44#define SPEECH_PROTOCOL "speech_to_text"
46#define CONNECTION_TIMEOUT 2000
48#define log_error(obj, fmt, ...) \
49 ast_log(LOG_ERROR, "AEAP speech (%p): " fmt "\n", obj, ##__VA_ARGS__)
65 for (i = variables; i; i = i->
next) {
66 if (i->
name[0] ==
'@' && i->
name[1]) {
106 if (!tsx_params.
msg) {
190 log_error(aeap,
"Unable to 'get' speech setting for '%s'", setting->
param);
196 log_error(aeap,
"No value for speech setting '%s'", setting->
param);
213 if (!json_results || !speech_results) {
214 log_error(aeap,
"Unable to 'get' speech results");
229 if (*speech_results) {
265 log_error(aeap,
"no 'get' parameters returned");
280 const char *codec_name;
288 log_error(aeap,
"no 'setup' object returned");
294 log_error(aeap,
"no 'setup' codecs available");
316 const char *error_msg =
NULL;
320 error_msg =
"no parameter(s) requested";
325 error_msg =
"no associated speech object";
327 error_msg =
"unable to handle results";
332 error_msg =
"can only set 'results'";
363 ast_log(
LOG_ERROR,
"aeap generated error with no associated speech object");
578static void speech_engine_alloc_and_register2(
const char *
name,
const char *codec_names)
625 ast_log(
LOG_ERROR,
"AEAP speech: unable to allocate default engine format for '%s'\n",
id);
664 if (!strcmp(
"_aeap_test_speech_", engine->
name)) {
751 speech_engine_alloc_and_register2(
"_aeap_test_speech_",
"ulaw");
762 .
requires =
"res_speech,res_aeap",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_calloc(num, len)
A wrapper for calloc()
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg)
Allocate and initialize an object.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void __ao2_cleanup(void *obj)
static struct formats formats
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Configuration File Parser.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Asterisk JSON abstraction layer.
#define ast_json_object_string_get(object, key)
Get a string field from a JSON object.
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
struct ast_json_iter * ast_json_object_iter(struct ast_json *object)
Get an iterator pointing to the first field in a JSON object.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
#define ast_json_object_integer_get(object, key)
Get an integer field from a JSON object.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
const char * ast_json_object_iter_key(struct ast_json_iter *iter)
Get the key from an iterator.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Asterisk module definitions.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_ref(mod)
Hold a reference to the module.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_CHANNEL_DEPEND
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Asterisk External Application Protocol API.
struct ast_aeap * ast_aeap_create_and_connect_by_id(const char *id, const struct ast_aeap_params *params, int timeout)
Create and connect to an Asterisk external application by sorcery id.
int ast_aeap_user_data_register(struct ast_aeap *aeap, const char *id, void *obj, ast_aeap_user_obj_cleanup cleanup)
Register a user data object.
int ast_aeap_client_config_has_protocol(const struct ast_aeap_client_config *cfg, const char *protocol)
Check a given protocol against that in an Asterisk external application configuration.
void * ast_aeap_user_data_object_by_id(struct ast_aeap *aeap, const char *id)
Retrieve a registered user data object by its id.
int ast_aeap_send_msg(struct ast_aeap *aeap, struct ast_aeap_message *msg)
Send a message to an external application.
struct ast_variable * ast_aeap_custom_fields_get(const char *id)
Retrieve a list of custom configuration fields.
struct ast_sorcery * ast_aeap_sorcery(void)
Retrieve the AEAP sorcery object.
int ast_aeap_send_msg_tsx(struct ast_aeap *aeap, struct ast_aeap_tsx_params *params)
Send a transaction based message to an external application using the given parameters.
#define AEAP_CONFIG_CLIENT
int ast_aeap_send_binary(struct ast_aeap *aeap, const void *buf, uintmax_t size)
Send a binary data to an external application.
struct ao2_container * ast_aeap_client_configs_get(const char *protocol)
Retrieve a listing of all client configuration objects by protocol.
const struct ast_format_cap * ast_aeap_client_config_codecs(const struct ast_aeap_client_config *cfg)
Retrieve codec capabilities from the configuration.
Asterisk External Application Protocol Message API.
struct ast_aeap_message * ast_aeap_message_create_error(const struct ast_aeap_message_type *type, const char *name, const char *id, const char *error_msg)
Create an Asterisk external application error response object.
const char * ast_aeap_message_id(const struct ast_aeap_message *message)
Retrieve a message id.
struct ast_aeap_message * ast_aeap_message_create_request(const struct ast_aeap_message_type *type, const char *name, const char *id, const void *params)
Create an Asterisk external application request object.
const char * ast_aeap_message_name(const struct ast_aeap_message *message)
Retrieve a message name.
const struct ast_aeap_message_type * ast_aeap_message_type_json
Asterisk external application JSON message type.
struct ast_aeap_message * ast_aeap_message_create_response(const struct ast_aeap_message_type *type, const char *name, const char *id, const void *params)
Create an Asterisk external application response object.
void * ast_aeap_message_data(struct ast_aeap_message *message)
Retrieve the core message data/body.
struct ao2_container * container
static const struct ast_aeap_message_handler response_handlers[]
static int speech_aeap_engine_destroy(struct ast_speech *speech)
#define CONNECTION_TIMEOUT
static void speech_observer_loaded(const char *object_type)
static int load_engine(void *obj, void *arg, int flags)
static int matches_engine(void *obj, void *arg, int flags)
static int speech_aeap_engine_change(struct ast_speech *speech, const char *name, const char *value)
static struct ast_speech_result * speech_aeap_engine_get(struct ast_speech *speech)
static int handle_results(struct ast_aeap *aeap, struct ast_json_iter *iter, struct ast_speech_result **speech_results)
static int handle_setting(struct ast_aeap *aeap, struct ast_json_iter *iter, struct speech_setting *setting)
static const struct ast_sorcery_observer speech_observer
Observer for AEAP reloads.
static int handle_response_get(struct ast_aeap *aeap, struct ast_aeap_message *message, void *data)
static int should_unregister(const struct ast_speech_engine *engine, void *data)
static struct ast_speech_engine * speech_engine_alloc(const char *name)
static int speech_aeap_engine_get_setting(struct ast_speech *speech, const char *name, char *buf, size_t len)
static int unload_engine(void *obj, void *arg, int flags)
static int speech_aeap_get(struct ast_speech *speech, const char *param, void *data)
static int speech_aeap_engine_write(struct ast_speech *speech, void *data, int len)
static void ast_aeap_speech_on_error(struct ast_aeap *aeap)
static int handle_response_setup(struct ast_aeap *aeap, struct ast_aeap_message *message, void *data)
static const struct ast_aeap_message_handler request_handlers[]
static void speech_engine_destroy(void *obj)
static int speech_aeap_engine_create(struct ast_speech *speech, struct ast_format *format)
#define log_error(obj, fmt,...)
static struct ast_json * custom_fields_to_params(const struct ast_variable *variables)
static struct ast_aeap_params speech_aeap_params
static int handle_response_set(struct ast_aeap *aeap, struct ast_aeap_message *message, void *data)
static int speech_aeap_engine_start(struct ast_speech *speech)
static int speech_aeap_send_request(struct ast_aeap *aeap, const char *name, struct ast_json *json, void *data)
#define SPEECH_AEAP_VERSION
static int load_module(void)
static int speech_aeap_engine_dtmf(struct ast_speech *speech, const char *dtmf)
static int speech_aeap_engine_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
static int unload_module(void)
static void speech_engine_alloc_and_register(const char *name, const struct ast_format_cap *formats)
static int handle_request_set(struct ast_aeap *aeap, struct ast_aeap_message *message, void *data)
static int speech_aeap_set(struct ast_speech *speech, const char *name, const char *value)
Sorcery Data Access Layer API.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Generic Speech Recognition API.
struct ast_speech_engine * ast_speech_find_engine(const char *engine_name)
Retrieve a speech recognition engine.
const char * ast_speech_results_type_to_string(enum ast_speech_results_type type)
Convert a speech results type to a string.
struct ast_speech_engine * ast_speech_unregister2(const char *engine_name)
Unregister a speech recognition engine.
void ast_speech_unregister_engines(int(*should_unregister)(const struct ast_speech_engine *engine, void *data), void *data, void(*on_unregistered)(void *obj))
Unregister all speech recognition engines told to by callback.
int ast_speech_register(struct ast_speech_engine *engine)
Register a speech recognition engine.
int ast_speech_change_state(struct ast_speech *speech, int state)
Change state of a speech structure.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
An Asterisk external application message handler.
Asterisk external application base message.
Callbacks and other parameters used by an Asterisk external application object.
const struct ast_aeap_message_type * msg_type
const struct ast_aeap_message_handler * response_handlers
Parameters to be used when sending a transaction based message.
struct ast_aeap_message * msg
Iterator for JSON object key/values.
Abstract JSON element (object, array, string, int, ...).
Interface for a sorcery object type observer.
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
struct ast_format_cap * formats
int(* start)(struct ast_speech *speech)
int(* change_results_type)(struct ast_speech *speech, enum ast_speech_results_type results_type)
struct ast_speech_result *(* get)(struct ast_speech *speech)
int(* get_setting)(struct ast_speech *speech, const char *name, char *buf, size_t len)
int(* destroy)(struct ast_speech *speech)
int(* dtmf)(struct ast_speech *speech, const char *dtmf)
int(* change)(struct ast_speech *speech, const char *name, const char *value)
int(* create)(struct ast_speech *speech, struct ast_format *format)
int(* write)(struct ast_speech *speech, void *data, int len)
struct ast_speech_engine * engine
struct ast_speech_result * results
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next