Dear Sir,
i try to change language model at runtime but it seem not to be successful.
my system was initial with large vocabulary dictionary but language model
consist only of number.
after it decode the first time, i try to change language model to a large
vocabulary language model but it seem not to be successful because the result
that i got consist only of number. here is my code:
static void
recognize_from_microphone() {
ad_rec_t ad;
int16 adbuf;
int32 k, ts, rem;
char const hyp;
char const uttid;
cont_ad_t cont;
char word;
if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"),
(int) cmd_ln_float32_r(config, "-samprate"))) == NULL)
E_FATAL("Failed top open audio device\n");
/ Initialize continuous listening module /
if ((cont = cont_ad_init(ad, ad_read)) == NULL)
E_FATAL("Failed to initialize voice activity detection\n");
if (ad_start_rec(ad) < 0)
E_FATAL("Failed to start recording\n");
if (cont_ad_calib(cont) < 0)
E_FATAL("Failed to calibrate voice activity detection\n");
for (;;) {
/ Change language model/
//ngram_model_t lmset, lm;
//lm = ngram_model_read(config,"",NGRAM_AUTO,ps_get_logmath(ps));
/ Indicate listening for next utterance /
printf("READY....\n");
fflush(stdout);
fflush(stderr);
/ Wait data for next utterance /
while ((k = cont_ad_read(cont, adbuf, 4096)) == 0)
sleep_msec(100);
if (k < 0)
E_FATAL("Failed to read audio\n");
/ Non-zero amount of data received; start recognition of new utterance. NULL argument to uttproc_begin_utt => automatic generation of utterance-id. /
if (ps_start_utt(ps, NULL) < 0)
E_FATAL("Failed to start utterance\n");
ps_process_raw(ps, adbuf, k, FALSE, FALSE);
printf("Listening...\n");
fflush(stdout);
/ Note timestamp for this first block of data /
ts = cont->read_ts;
/ Decode utterance until end (marked by a "long" silence, >1sec) /
for (;;) {
/ Read non-silence audio data, if any, from continuous listening module /
if ((k = cont_ad_read(cont, adbuf, 4096)) < 0)
E_FATAL("Failed to read audio\n");
if (k == 0) {
/ No speech data available; check current timestamp with most recent speech to see if more than 1 sec elapsed. If so, end of utterance. /
if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC)
break;
} else {
/ New speech data received; note current timestamp /
ts = cont->read_ts;
}
/ Decode whatever data was read above.
*/
rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE);
/ If no work to be done, sleep a bit /
if ((rem == 0) && (k == 0))
sleep_msec(20);
}
/ Utterance ended; flush any accumulated, unprocessed A/D data and stop listening until current utterance completely decoded /
ad_stop_rec(ad);
while (ad_read(ad, adbuf, 4096) >= 0);
cont_ad_reset(cont);
/ Add by khoand 06/06/2011 03:32:03 PM Checking for change language model flag, if flag is set, read new language model, add to decoder and re-initial decoder /
const char changeLmFlag = "/home/khoand/Desktop/changelm";
ngram_model_t lmset, lm;
lmset = ps_get_lmset(ps);
if (lmset != NULL) {
/ Check if change language is exist /
if (file_exists(changeLmFlag)) {
FILE changeLmf;
char line;
changeLmf = fopen(changeLmFlag, "r+");
while (fgets(line, sizeof (line), changeLmf)) {
if (file_exists((char ) &line)) {
E_INFO("\nChange language model to %s\n", &line);
lm = ngram_model_read(ps_get_config(ps), (char ) &line, NGRAM_AUTO,
ps_get_logmath(ps));
ngram_model_set_add(lmset, lm, "free", 1.0, TRUE);
ps_update_lmset(ps, lmset);
break;
}
}
fclose(changeLmf);
remove(changeLmFlag);
}
}
/ End/
/ Resume A/D recording for next utterance /
if (ad_start_rec(ad) < 0)
E_FATAL("Failed to start recording\n");
}
cont_ad_close(cont);
ad_close(ad);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear Sir,
i try to change language model at runtime but it seem not to be successful.
my system was initial with large vocabulary dictionary but language model
consist only of number.
after it decode the first time, i try to change language model to a large
vocabulary language model but it seem not to be successful because the result
that i got consist only of number. here is my code:
static void
recognize_from_microphone() {
ad_rec_t ad;
int16 adbuf;
int32 k, ts, rem;
char const hyp;
char const uttid;
cont_ad_t cont;
char word;
if ((ad = ad_open_dev(cmd_ln_str_r(config, "-adcdev"),
(int) cmd_ln_float32_r(config, "-samprate"))) == NULL)
E_FATAL("Failed top open audio device\n");
/ Initialize continuous listening module /
if ((cont = cont_ad_init(ad, ad_read)) == NULL)
E_FATAL("Failed to initialize voice activity detection\n");
if (ad_start_rec(ad) < 0)
E_FATAL("Failed to start recording\n");
if (cont_ad_calib(cont) < 0)
E_FATAL("Failed to calibrate voice activity detection\n");
for (;;) {
/ Change language model/
//ngram_model_t lmset, lm;
//lm = ngram_model_read(config,"",NGRAM_AUTO,ps_get_logmath(ps));
/ Indicate listening for next utterance /
printf("READY....\n");
fflush(stdout);
fflush(stderr);
/ Wait data for next utterance /
while ((k = cont_ad_read(cont, adbuf, 4096)) == 0)
sleep_msec(100);
if (k < 0)
E_FATAL("Failed to read audio\n");
/
Non-zero amount of data received; start recognition of new utterance.
NULL argument to uttproc_begin_utt => automatic generation of utterance-id.
/
if (ps_start_utt(ps, NULL) < 0)
E_FATAL("Failed to start utterance\n");
ps_process_raw(ps, adbuf, k, FALSE, FALSE);
printf("Listening...\n");
fflush(stdout);
/ Note timestamp for this first block of data /
ts = cont->read_ts;
/ Decode utterance until end (marked by a "long" silence, >1sec) /
for (;;) {
/ Read non-silence audio data, if any, from continuous listening module /
if ((k = cont_ad_read(cont, adbuf, 4096)) < 0)
E_FATAL("Failed to read audio\n");
if (k == 0) {
/
No speech data available; check current timestamp with most recent
speech to see if more than 1 sec elapsed. If so, end of utterance.
/
if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC)
break;
} else {
/ New speech data received; note current timestamp /
ts = cont->read_ts;
}
/
Decode whatever data was read above.
*/
rem = ps_process_raw(ps, adbuf, k, FALSE, FALSE);
/ If no work to be done, sleep a bit /
if ((rem == 0) && (k == 0))
sleep_msec(20);
}
/
Utterance ended; flush any accumulated, unprocessed A/D data and stop
listening until current utterance completely decoded
/
ad_stop_rec(ad);
while (ad_read(ad, adbuf, 4096) >= 0);
cont_ad_reset(cont);
printf("Stopped listening, please wait...\n");
fflush(stdout);
/ Finish decoding, obtain and print result /
ps_end_utt(ps);
hyp = ps_get_hyp(ps, NULL, &uttid);
printf("%s: %s %d\n", uttid, hyp, ps_get_prob(ps, &uttid));
fflush(stdout);
/ Add by khoand 06/06/2011 03:32:03 PM
Checking for change language model flag, if flag is set, read new
language model, add to decoder and re-initial decoder
/
const char changeLmFlag = "/home/khoand/Desktop/changelm";
ngram_model_t lmset, lm;
lmset = ps_get_lmset(ps);
if (lmset != NULL) {
/ Check if change language is exist /
if (file_exists(changeLmFlag)) {
FILE changeLmf;
char line;
changeLmf = fopen(changeLmFlag, "r+");
while (fgets(line, sizeof (line), changeLmf)) {
if (file_exists((char ) &line)) {
E_INFO("\nChange language model to %s\n", &line);
lm = ngram_model_read(ps_get_config(ps), (char ) &line, NGRAM_AUTO,
ps_get_logmath(ps));
ngram_model_set_add(lmset, lm, "free", 1.0, TRUE);
ps_update_lmset(ps, lmset);
break;
}
}
fclose(changeLmf);
remove(changeLmFlag);
}
}
/ End/
/ Resume A/D recording for next utterance /
if (ad_start_rec(ad) < 0)
E_FATAL("Failed to start recording\n");
}
cont_ad_close(cont);
ad_close(ad);
}
You also need to select a language model, after you added it: