/** Create a new client. */
srs_client_t *client_create(srs_context_t *srs, srs_client_type_t type,
- const char *name, const char *appclass,
- char **commands, int ncommand,
- const char *id, srs_client_ops_t *ops);
+ const char *name, const char *appclass,
+ char **commands, int ncommand,
+ const char *id, srs_client_ops_t *ops);
/** Destroy a client. */
void client_destroy(srs_client_t *c);
"The possible options are:\n"
" -c, --config-file=PATH main configuration file to use\n"
" The default configuration file is '%s'.\n"
+ " -B, --dbus=BUS D-BUS type or address to use\n"
+ " The default D-BUS is 'session'.\n"
" -P, --plugin-dir=PATH use DIR to search for plugins\n"
" The default plugin directory is '%s'.\n"
" -L, --load-plugin=NAME load the given plugin\n"
} srs_srec_t;
static srs_srec_t *find_srec(srs_context_t *srs, const char *name);
-static void srec_notify_cb(srs_srec_token_t *tokens, int ntoken,
- void *notify_data);
+static int srec_notify_cb(srs_srec_utterance_t *utt, void *notify_data);
int srs_register_srec(srs_context_t *srs, const char *name,
srs_srec_api_t *api, void *api_data,
}
-int srs_check_model(srs_context_t *srs, const char *name, const char *model)
+int srs_check_decoder(srs_context_t *srs, const char *name,
+ const char *decoder)
{
srs_srec_t *srec = find_srec(srs, name);
if (srec != NULL)
- return srec->api.check_model(model, srec->api_data);
+ return srec->api.check_decoder(decoder, srec->api_data);
else
return FALSE;
}
-int srs_check_dictionary(srs_context_t *srs, const char *name,
- const char *dictionary)
+int srs_set_decoder(srs_context_t *srs, const char *name, const char *decoder)
{
srs_srec_t *srec = find_srec(srs, name);
if (srec != NULL)
- return srec->api.check_dictionary(dictionary, srec->api_data);
- else
- return FALSE;
-}
-
-
-int srs_set_model(srs_context_t *srs, const char *name, const char *model)
-{
- srs_srec_t *srec = find_srec(srs, name);
-
- if (srec != NULL)
- return srec->api.set_model(model, srec->api_data);
- else
- return FALSE;
-}
-
-
-int srs_set_dictionary(srs_context_t *srs, const char *name,
- const char *dictionary)
-{
- srs_srec_t *srec = find_srec(srs, name);
-
- if (srec != NULL)
- return srec->api.set_dictionary(dictionary, srec->api_data);
+ return srec->api.select_decoder(decoder, srec->api_data);
else
return FALSE;
}
}
-static void srec_notify_cb(srs_srec_token_t *tokens, int ntoken,
- void *notify_data)
+static int srec_notify_cb(srs_srec_utterance_t *utt, void *notify_data)
{
- srs_srec_t *srec = (srs_srec_t *)notify_data;
- int i;
-
- mrp_log_info("Got %d tokens from %s backend:", ntoken, srec->name);
+ srs_srec_t *srec = (srs_srec_t *)notify_data;
+ srs_srec_candidate_t *c;
+ srs_srec_token_t *t;
+ int i, j;
+
+ mrp_log_info("Got %zd recognition candidates in from %s backend:",
+ utt->ncand, srec->name);
+
+ for (i = 0, c = utt->cands; i < (int)utt->ncand; i++, c++) {
+ mrp_log_info("Candidate #%d:", i);
+ for (j = 0, t = c->tokens; j < (int)c->ntoken; j++, t++) {
+ mrp_log_info(" token #%d: '%s'", j, t->token);
+ }
+ }
- for (i = 0; i < ntoken; i++)
- mrp_log_info(" #%d: '%s'", i, tokens[i].token);
+ return -1;
}
#define __SRS_DAEMON_RECOGNIZER_H__
/** Type for tokens recognized by a speech recognition backend. */
-typedef struct srs_srec_token_s srs_srec_token_t;
+typedef struct srs_srec_utterance_s srs_srec_utterance_t;
/** Type for a backend recognition notification callback. */
-typedef void (*srs_srec_notify_t)(srs_srec_token_t *tokens, int ntoken,
- void *notify_data);
+typedef int (*srs_srec_notify_t)(srs_srec_utterance_t *utt, void *notify_data);
/*
* API to a speech recognition backend.
/** Get a copy of the audio samples in the buffer. */
void *(*sampledup)(uint32_t start, uint32_t end, void *user_data);
/** Check if the given language model exists/is usable. */
- int (*check_model)(const char *model, void *user_data);
- /** Check if the given dictionary exists/is usable. */
- int (*check_dictionary)(const char *dictionary, void *user_data);
+ int (*check_decoder)(const char *decoder, void *user_data);
/** Set language model to be used. */
- int (*set_model)(const char *model, void *user_data);
- /** Set dictionary to be used. */
- int (*set_dictionary)(const char *dictionary, void *user_data);
+ int (*select_decoder)(const char *decoder, void *user_data);
} srs_srec_api_t;
/*
* a single speech token
*/
-struct srs_srec_token_s {
+typedef struct {
char *token; /* recognized tokens */
double score; /* correctness probability */
uint32_t start; /* start in audio buffer */
uint32_t end; /* end in audio buffer */
- int flush : 1; /* flush from audio buffer */
-};
+} srs_srec_token_t;
+
+
+/*
+ * a single candidate
+ */
+typedef struct {
+ double score;
+ size_t ntoken;
+ srs_srec_token_t *tokens;
+} srs_srec_candidate_t;
+/*
+ * an utterance with a set of candidates
+ */
+struct srs_srec_utterance_s {
+ const char *id;
+ double score;
+ uint32_t length;
+ size_t ncand;
+ srs_srec_candidate_t *cands;
+};
+
/** Register a speech recognition backend. */
int srs_register_srec(srs_context_t *srs, const char *name,
srs_srec_api_t *api, void *api_data,
/** Deactivate the specified speech recognition backend. */
void srs_deactivate_srec(srs_context_t *srs, const char *name);
-/** Check if a given model exists for a recognition backend. */
-int srs_check_model(srs_context_t *srs, const char *name, const char *model);
-
-/** Check if a given dictionary exists for a recognition backend. */
-int srs_check_dictionary(srs_context_t *srs, const char *name,
- const char *dictionary);
-
-/** Check if a given model exists for a recognition backend. */
-int srs_set_model(srs_context_t *srs, const char *name, const char *model);
+/** Check if a decoder (model/dictionary combination) exists for a backend. */
+int srs_check_decoder(srs_context_t *srs, const char *name,
+ const char *decoder);
-/** Check if a given dictionary exists for a recognition backend. */
-int srs_set_dictionary(srs_context_t *srs, const char *name,
- const char *dictionary);
+/** Select a decoder for a backend. */
+int srs_set_decoder(srs_context_t *srs, const char *name, const char *decoder);
#endif /* __SRS_DAEMON_RECOGNIZER_H__ */
static void push_token_cb(mrp_timer_t *t, void *user_data)
{
- fake_t *fake = (fake_t *)user_data;
- fake_token_t *token = fake->tokens + fake->tokidx++;
- srs_srec_token_t tok;
+ fake_t *fake = (fake_t *)user_data;
+ fake_token_t *token = fake->tokens + fake->tokidx++;
+ srs_srec_token_t tok;
+ srs_srec_candidate_t cand;
+ srs_srec_utterance_t utt;
mrp_del_timer(t);
fake->toktmr = NULL;
tok.score = 1;
tok.start = token - fake->tokens;
tok.end = tok.start + 1;
- tok.flush = FALSE;
- fake->notify(&tok, 1, fake->notify_data);
+ cand.score = 1;
+ cand.ntoken = 1;
+ cand.tokens = &tok;
+
+ utt.id = "fake backend utterance";
+ utt.score = 1;
+ utt.length = 1;
+ utt.length = tok.end - tok.start;
+ utt.ncand = 1;
+ utt.cands = &cand;
+
+ fake->notify(&utt, fake->notify_data);
}
}
-static int fake_check_model(const char *model, void *user_data)
-{
- fake_t *fake = (fake_t *)user_data;
-
- MRP_UNUSED(fake);
-
- mrp_debug("checking model '%s' for fake backend", model);
-
- return TRUE;
-}
-
-
-static int fake_check_dictionary(const char *dictionary, void *user_data)
-{
- fake_t *fake = (fake_t *)user_data;
-
- MRP_UNUSED(fake);
-
- mrp_debug("checking dictionary '%s' for fake backend", dictionary);
-
- return TRUE;
-}
-
-
-static int fake_set_model(const char *model, void *user_data)
+static int fake_check_decoder(const char *decoder, void *user_data)
{
fake_t *fake = (fake_t *)user_data;
MRP_UNUSED(fake);
- mrp_debug("setting model '%s' for fake backend", model);
+ mrp_debug("checking availibilty of decoder '%s' for fake backend", decoder);
return TRUE;
}
-static int fake_set_dictionary(const char *dictionary, void *user_data)
+static int fake_select_decoder(const char *decoder, void *user_data)
{
fake_t *fake = (fake_t *)user_data;
MRP_UNUSED(fake);
- mrp_debug("setting dictionary '%s' for fake backend", dictionary);
+ mrp_debug("selecting decoder '%s' for fake backend", decoder);
return TRUE;
}
flush: fake_flush,
rescan: fake_rescan,
sampledup: fake_sampledup,
- check_model: fake_check_model,
- check_dictionary: fake_check_dictionary,
- set_model: fake_set_model,
- set_dictionary: fake_set_dictionary,
+ check_decoder: fake_check_decoder,
+ select_decoder: fake_select_decoder,
};
srs_context_t *srs = plugin->srs;
}
-static int nuance_check_model(const char *model, void *user_data)
+static int nuance_check_decoder(const char *decoder, void *user_data)
{
nuance_t *nua = (nuance_t *)user_data;
MRP_UNUSED(nua);
- mrp_debug("checking model '%s' for Nuance backend", model);
+ mrp_debug("checking availability of decoder '%s' for Nuance backend",
+ decoder);
return TRUE;
}
-static int nuance_check_dictionary(const char *dictionary, void *user_data)
+static int nuance_select_decoder(const char *decoder, void *user_data)
{
nuance_t *nua = (nuance_t *)user_data;
MRP_UNUSED(nua);
- mrp_debug("checking dictionary '%s' for Nuance backend", dictionary);
-
- return TRUE;
-}
-
-
-static int nuance_set_model(const char *model, void *user_data)
-{
- nuance_t *nua = (nuance_t *)user_data;
-
- MRP_UNUSED(nua);
-
- mrp_debug("setting model '%s' for Nuance backend", model);
-
- return TRUE;
-}
-
-
-static int nuance_set_dictionary(const char *dictionary, void *user_data)
-{
- nuance_t *nua = (nuance_t *)user_data;
-
- MRP_UNUSED(nua);
-
- mrp_debug("setting dictionary '%s' for Nuance backend", dictionary);
+ mrp_debug("setting decoder '%s' for Nuance backend", decoder);
return TRUE;
}
flush: nuance_flush,
rescan: nuance_rescan,
sampledup: nuance_sampledup,
- check_model: nuance_check_model,
- check_dictionary: nuance_check_dictionary,
- set_model: nuance_set_model,
- set_dictionary: nuance_set_dictionary,
+ check_decoder: nuance_check_decoder,
+ select_decoder: nuance_select_decoder,
};
srs_context_t *srs = plugin->srs;