Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void QtCVMainWindow::speech()
- {
- ps_decoder_t *ps;
- cmd_ln_t *config;
- char const *hyp, *uttid;
- 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;
- ps = ps_init(config);
- if (ps == NULL)
- return;
- AUD_DeviceSpecs specs;
- specs.channels = AUD_CHANNELS_MONO;
- specs.rate = AUD_RATE_16000;
- specs.format = AUD_FORMAT_S16;
- AUD_Reference<AUD_IReader> capture = new AUD_ConverterReader(new AUD_OpenALReader(specs.specs), specs);
- AUD_Buffer buffer(specs.rate * 5 * AUD_DEVICE_SAMPLE_SIZE(specs));
- int samples = specs.rate * 5;
- int len;
- int16_t* sbuf = reinterpret_cast<int16_t*>(buffer.getBuffer());
- bool eos;
- while(samples > 0)
- {
- len = capture->getLength();
- if(len > samples)
- len = samples;
- if(len > 0)
- {
- capture->read(len, eos, reinterpret_cast<sample_t*>(sbuf));
- sbuf += len;
- samples -= len;
- }
- }
- rv = ps_start_utt(ps, "goforward");
- if (rv < 0)
- return;
- rv = ps_process_raw(ps, reinterpret_cast<int16*>(buffer.getBuffer()), 5 * specs.rate, false, true);
- if(rv < 0)
- return;
- rv = ps_end_utt(ps);
- if (rv < 0)
- return;
- hyp = ps_get_hyp(ps, &score, &uttid);
- QMessageBox msgBox;
- if(!hyp)
- msgBox.setText("No clue what you are talking about.");
- else
- msgBox.setText(hyp);
- msgBox.exec();
- ps_free(ps);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement