本文整理汇总了C++中ps_start_utt函数的典型用法代码示例。如果您正苦于以下问题:C++ ps_start_utt函数的具体用法?C++ ps_start_utt怎么用?C++ ps_start_utt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ps_start_utt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.bin",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
if (config == NULL) {
fprintf(stderr, "Failed to create config object, see log for details\n");
return -1;
}
// Initialize pocketsphinx
ps = ps_init(config);
if (ps == NULL) {
fprintf(stderr, "Failed to create recognizer, see log for details\n");
return -1;
}
// Open the wav file passed from argument
printf("file: %s\n", argv[1]);
fh = fopen(argv[1], "rb");
if (fh == NULL) {
fprintf(stderr, "Unable to open input file %s\n", argv[1]);
return -1;
}
// Start utterance
rv = ps_start_utt(ps);
// Process buffer, 512 samples at a time
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
// Recieve the recognized string
rv = ps_end_utt(ps);
hyp = ps_get_hyp(ps, &score);
printf("Recognized: |%s|\n", hyp);
// free memory
fclose(fh);
ps_free(ps);
cmd_ln_free_r(config);
return 0;
}
示例2: test_no_search
static void
test_no_search()
{
cmd_ln_t *config = default_config();
ps_decoder_t *ps = ps_init(config);
TEST_ASSERT(ps_start_utt(ps) < 0);
ps_free(ps);
cmd_ln_free_r(config);
}
示例3: config_input
static int config_input(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
ASRContext *s = ctx->priv;
ps_start_utt(s->ps);
return 0;
}
示例4: start
ReturnType Recognizer::start() {
if ((decoder == NULL) || (is_recording)) return BAD_STATE;
if (ps_start_utt(decoder, NULL) < 0) {
return RUNTIME_ERROR;
}
current_hyp = "";
is_recording = true;
return SUCCESS;
}
示例5: main
int
main(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
"-lm", MODELDIR "/lm/en/turtle.DMP",
"-dict", MODELDIR "/lm/en/turtle.dic",
NULL);
if (config == NULL)
return 1;
ps = ps_init(config);
if (ps == NULL)
return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL) {
perror("Failed to open goforward.raw");
return 1;
}
rv = ps_decode_raw(ps, fh, "goforward", -1);
if (rv < 0)
return 1;
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL)
return 1;
printf("Recognized: %s\n", hyp);
fseek(fh, 0, SEEK_SET);
rv = ps_start_utt(ps, "goforward");
if (rv < 0)
return 1;
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
rv = ps_end_utt(ps);
if (rv < 0)
return 1;
hyp = ps_get_hyp(ps, &score, &uttid);
if (hyp == NULL)
return 1;
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
return 0;
}
示例6: spDecode
/**
* You must sucessfully call spInitListener
* once before using this function.
*
* Reads the next block of audio from the microphone
* up to SPLBUFSIZE number of samples
* (defined in splistener.h).
* If an utterance was completed in that block,
* the transcription is stored in the string words.
*
* When calling this function in a realtime loop, delay
* by some amount of time between calls keeping in mind
* your recording's sample rate and maximum samples read
* per call (ex. sleep the thread for 100 milliseconds)
* so that some audio can be recorded for the next call.
*
* @return true if a speech session was completed and
* transcribed this block, otherwise false.
*/
static bool spDecode() {
static bool uttered = false;
// lock pocketsphinx resources to make sure they
// don't get freed by main thread while in use
std::lock_guard<std::mutex> ps_lock(ps_mtx);
if(!mic || !ps)
return false;
int samples_read = ad_read(mic, buf, SPLBUFSIZE);
if (samples_read <= 0) {
spError("failed to read audio :(");
return false;
}
ps_process_raw(ps, buf, samples_read, FALSE, FALSE);
bool talking = ps_get_in_speech(ps);
// Just started talking
if (talking && !uttered) {
uttered = true;
return false;
}
// Stopped talking, so transcribe what was said
// and begin the next utterance
if (!talking && uttered) {
ps_end_utt(ps);
const char *trans = ps_get_hyp(ps, NULL);
if (ps_start_utt(ps) < 0) {
spError("failed to start utterance :(");
}
uttered = false;
int l = strlen(trans);
if (trans && l > 0) {
std::lock_guard<std::mutex> lock(words_mtx);
if (words && l + 1 > words_buf_size) {
delete words;
words = NULL;
}
if (!words) {
words = new char[l + 1];
words_buf_size = l + 1;
}
std::copy(trans, trans + l, words);
words[l] = '\0';
return true;
}
}
return false;
}
示例7: ClientMessage
uint32 FSpeechRecognitionWorker::Run() {
char const *hyp;
// attempt to open the default recording device
if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"),
(int)cmd_ln_float32_r(config,
"-samprate"))) == NULL) {
ClientMessage(FString(TEXT("Failed to open audio device")));
return 1;
}
if (ad_start_rec(ad) < 0) {
ClientMessage(FString(TEXT("Failed to start recording")));
return 2;
}
if (ps_start_utt(ps) < 0) {
ClientMessage(FString(TEXT("Failed to start utterance")));
return 3;
}
while (StopTaskCounter.GetValue() == 0) {
if ((k = ad_read(ad, adbuf, 1024)) < 0)
ClientMessage(FString(TEXT("Failed to read audio")));
ps_process_raw(ps, adbuf, k, 0, 0);
in_speech = ps_get_in_speech(ps);
if (in_speech && !utt_started) {
utt_started = 1;
}
if (!in_speech && utt_started) {
/* speech -> silence transition, time to start new utterance */
ps_end_utt(ps);
hyp = ps_get_hyp(ps, NULL);
if (hyp != NULL)
Manager->WordSpoken_method(FString(hyp));
if (ps_start_utt(ps) < 0)
ClientMessage(FString(TEXT("Failed to start")));
utt_started = 0;
}
}
ad_close(ad);
return 0;
}
示例8: decode
int decode()
{
int ret;
int16 buf[BUFFER_SIZE];
printf("Listening for input...\n");
if (ad_start_rec(ad) < 0) {
printf("Error starting recording.\n");
return 0;
}
//check if not silent
while ((ret = cont_ad_read(c_ad, buf, BUFFER_SIZE)) == 0)
usleep(1000);
if (ps_start_utt(ps, NULL) < 0) {
printf("Failed to start utterance.\n");
return 0;
}
ret = ps_process_raw(ps, buf, BUFFER_SIZE, 0, 0);
if (ret < 0) {
printf("Error decoding.\n");
return 0;
}
do
{
ret = cont_ad_read(c_ad, buf, BUFFER_SIZE);
if (ret < 0) {
printf("Failed to record audio.\n");
return 0;
} else if(ret > 0) {
// Valid speech data read.
ret = ps_process_raw(ps, buf, 4096, 0, 0);
if (ret < 0) {
printf("Error decoding.\n");
return 0;
}
} else {
//no data
usleep(1000);
}
} while(getRun());
ad_stop_rec(ad);
while (ad_read(ad, buf, BUFFER_SIZE) >= 0);
cont_ad_reset(c_ad);
ps_end_utt(ps);
return 1;
}
示例9: main
int
main(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-keyphrase", "marieta",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
"-kws_threshold", "1e-30",
NULL);
if (config == NULL) {
fprintf(stderr, "Failed to create config object, see log for details\n");
return -1;
}
ps = ps_init(config);
if (ps == NULL) {
fprintf(stderr, "Failed to create recognizer, see log for details\n");
return -1;
}
fh = fopen("data/marieta.raw", "rb");
if (fh == NULL) {
fprintf(stderr, "Unable to open input file goforward.raw\n");
return -1;
}
rv = ps_start_utt(ps);
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
rv = ps_end_utt(ps);
hyp = ps_get_hyp(ps, &score);
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
cmd_ln_free_r(config);
return 0;
}
示例10: gst_sphinx_sink_process_chunk
static void gst_sphinx_sink_process_chunk (GstSphinxSink *sphinxsink)
{
int32 k;
int16 adbuf[REQUIRED_FRAME_SAMPLES];
k = cont_ad_read (sphinxsink->cont, adbuf, REQUIRED_FRAME_SAMPLES);
if (k == 0 && sphinxsink->last_ts == 0) {
return;
} else if (k == 0 && sphinxsink->cont->read_ts - sphinxsink->last_ts >
DEFAULT_SAMPLES_PER_SEC) {
int32 score;
const char *hyp;
char *stripped_hyp;
int i, j;
ps_end_utt (sphinxsink->decoder);
if ((hyp = ps_get_hyp (sphinxsink->decoder, &score, NULL)) == NULL) {
gst_sphinx_sink_send_message (sphinxsink, "message", "");
g_message("Not Recognized");
} else {
stripped_hyp =
g_malloc (strlen (hyp) + 1);
for (i=0, j=0; hyp[i] != 0; i++) {
if (hyp[i] != '(' && hyp[i] != ')' && (hyp[i] < '0' || hyp[i] > '9')) {
stripped_hyp[j++] = hyp[i];
}
}
stripped_hyp [j] = 0;
gst_sphinx_sink_send_message (sphinxsink, "message", stripped_hyp);
g_message("Recognized: %s", stripped_hyp);
}
sphinxsink->last_ts = 0;
sphinxsink->ad.listening = 0;
} else if (k != 0) {
if (sphinxsink->ad.listening == 0) {
ps_start_utt (sphinxsink->decoder, NULL);
sphinxsink->ad.listening = 1;
gst_sphinx_sink_send_message (sphinxsink, "listening", NULL);
}
ps_process_raw (sphinxsink->decoder, adbuf, k, 0, 0);
sphinxsink->last_ts = sphinxsink->cont->read_ts;
}
}
示例11: utterance_start
void utterance_start(context_t *ctx)
{
decoder_set_t *decset;
decoder_t *dec;
char utid[256];
if (ctx && (decset = ctx->decset) && (dec = decset->curdec)) {
if (!dec->utter) {
snprintf(utid, sizeof(utid), "%07u-%s", dec->utid++, dec->name);
ps_start_utt(dec->ps, mrp_strdup(utid));
dec->utter = true;
}
}
}
示例12: pocketsphinx_asr_get_results
/*! function to read results from the ASR */
static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
{
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>>pocketsphinx_asr_get_results<<<<<<<<<\n");
if (switch_test_flag(ps, PSFLAG_BARGE)) {
switch_clear_flag_locked(ps, PSFLAG_BARGE);
status = SWITCH_STATUS_BREAK;
}
if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) {
switch_mutex_lock(ps->flag_mutex);
switch_clear_flag(ps, PSFLAG_HAS_TEXT);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d, Confidence-Threshold: %d\n", ps->hyp, ps->confidence, ps->confidence_threshold);
switch_mutex_unlock(ps->flag_mutex);
*xmlstr = switch_mprintf("%s", ps->hyp);
if (!switch_test_flag(ps, PSFLAG_INPUT_TIMERS) && switch_test_flag(ah, SWITCH_ASR_FLAG_AUTO_RESUME)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming\n");
switch_set_flag(ps, PSFLAG_READY);
ps_start_utt(ps->ps, NULL);
}
status = SWITCH_STATUS_SUCCESS;
} else if (switch_test_flag(ps, PSFLAG_NOINPUT)) {
switch_clear_flag_locked(ps, PSFLAG_NOINPUT);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO INPUT\n");
*xmlstr = switch_mprintf("");
status = SWITCH_STATUS_SUCCESS;
} else if (switch_test_flag(ps, PSFLAG_NOMATCH)) {
switch_clear_flag_locked(ps, PSFLAG_NOMATCH);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO MATCH\n");
*xmlstr = switch_mprintf("");
status = SWITCH_STATUS_SUCCESS;
}
return status;
}
示例13: pocketsphinx_asr_feed
/*! function to feed audio to the ASR */
static switch_status_t pocketsphinx_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
int rv = 0;
if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED))
return SWITCH_STATUS_BREAK;
if (!switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) {
if (stop_detect(ps, (int16_t *) data, len / 2)) {
char const *hyp;
switch_mutex_lock(ps->flag_mutex);
if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
if (!zstr(hyp)) {
ps_end_utt(ps->ps);
switch_clear_flag(ps, PSFLAG_READY);
if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
if (zstr(hyp)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind....\n");
ps_start_utt(ps->ps, NULL);
switch_set_flag(ps, PSFLAG_READY);
} else {
ps->hyp = switch_core_strdup(ah->memory_pool, hyp);
switch_set_flag(ps, PSFLAG_HAS_TEXT);
}
}
}
}
switch_mutex_unlock(ps->flag_mutex);
}
/* only feed ps_process_raw when we are listening */
if (ps->listening) {
switch_mutex_lock(ps->flag_mutex);
rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE);
switch_mutex_unlock(ps->flag_mutex);
}
if (rv < 0) {
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
示例14: main
int
main(int argc, char *argv[])
{
ps_decoder_t *ps;
cmd_ln_t *config;
FILE *fh;
char const *hyp, *uttid;
int16 buf[512];
int rv;
int32 score;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.dmp",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
if (config == NULL)
return 1;
ps = ps_init(config);
if (ps == NULL)
return 1;
fh = fopen("goforward.raw", "rb");
if (fh == NULL)
return -1;
rv = ps_start_utt(ps);
if (rv < 0)
return 1;
while (!feof(fh)) {
size_t nsamp;
nsamp = fread(buf, 2, 512, fh);
rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
}
rv = ps_end_utt(ps);
if (rv < 0)
return 1;
hyp = ps_get_hyp(ps, &score);
if (hyp == NULL)
return 1;
printf("Recognized: %s\n", hyp);
fclose(fh);
ps_free(ps);
cmd_ln_free_r(config);
return 0;
}
示例15: pocketsphinx_asr_get_results
/*! function to read results from the ASR*/
static switch_status_t pocketsphinx_asr_get_results(switch_asr_handle_t *ah, char **xmlstr, switch_asr_flag_t *flags)
{
pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
int32_t conf;
if (switch_test_flag(ps, PSFLAG_BARGE)) {
switch_clear_flag_locked(ps, PSFLAG_BARGE);
status = SWITCH_STATUS_BREAK;
}
if (switch_test_flag(ps, PSFLAG_HAS_TEXT)) {
switch_mutex_lock(ps->flag_mutex);
switch_clear_flag(ps, PSFLAG_HAS_TEXT);
conf = ps_get_prob(ps->ps, &ps->uttid);
ps->confidence = (conf + 20000) / 200;
if (ps->confidence < 0) {
ps->confidence = 0;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Recognized: %s, Confidence: %d\n", ps->hyp, ps->confidence);
switch_mutex_unlock(ps->flag_mutex);
*xmlstr = switch_mprintf("<?xml version=\"1.0\"?>\n"
"<result grammar=\"%s\">\n"
" <interpretation grammar=\"%s\" confidence=\"%d\">\n"
" <input mode=\"speech\">%s</input>\n"
" </interpretation>\n" "</result>\n", ps->grammar, ps->grammar, ps->confidence, ps->hyp);
if (switch_test_flag(ps, SWITCH_ASR_FLAG_AUTO_RESUME)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Auto Resuming\n");
switch_set_flag(ps, PSFLAG_READY);
ps_start_utt(ps->ps, NULL);
}
status = SWITCH_STATUS_SUCCESS;
}
return status;
}