WEB开发网
开发学院软件开发VC 在vc++6.0/2003/2005/2008中调用HTK 阅读

在vc++6.0/2003/2005/2008中调用HTK

 2009-04-27 20:06:39 来源:WEB开发网   
核心提示: }else{status = unconfirmed;}value = curtag+"("+curwords+")";ok = TRUE;}}else if (as==aTimeout) {printf("Timeoutn");

  }else{
  status = unconfirmed;
  }
  value = curtag+"("+curwords+")";
  ok = TRUE;
  }
  }else if (as==aTimeout) {
  printf("Timeoutn");
  aio->SendMessage("tell("Sorry, I didnt hear that!")");
  }else if (as==aTerminated) {
  terminated = TRUE;
  }
  } while (!ok && !terminated);
  }
  // confirm current slot value
  void QA::Check()
  {
  Boolean ok = FALSE;
  ASRStatus as; SynStatus ss;
  string prompt;
  do {
  prompt = "Are sure you want "+GetValue()+" ?";
  as = Listen(prompt,chk->gname,ss);
  if (as==aDone){
  if (curtag == "command") {
  if (curwords == "HELP") {
  aio->SendMessage("tell("I am trying to confirm your last input.")");
  aio->SendMessage("tell("Please say Yes or No. If No, you can also give the correct value.")");
  }else if (curwords == "CANCEL"){
  ok = TRUE; status = cancelled;
  }
  }
  if (curtag == "yes"){
  ok = TRUE; status = grounded;
  }else if (curtag == name){
  if (curconf > minconf){
  status = grounded;
  }else{
  status = unconfirmed;
  }
  value = curtag+"("+curwords+")";
  ok = TRUE;
  }else {
  ok = TRUE; status = unknown; // user must have said No without correction
  }
  }else if (as==aTimeout) {
  aio->SendMessage("Sorry, I didnt hear that!");
  }else if (as==aTerminated) {
  terminated = TRUE;
  }
  } while (!ok && !terminated);
  }
  void QA::GetSlot()
  {
  do {
  Ask();
  while (status == unconfirmed) Check();
  }while (status != grounded && status != cancelled && !terminated);
  }
  string QA::GetValue()
  {
  int n = value.find("(");
  if (n==string::npos) return "";
  ++n;
  int m = value.length() - n -1;
  string val = value.substr(n,m);
  for (int i = 0; i<M; rman- AGram(?GGram?,?global.net?); ggrm="new" ADict(?ADict?); dict="new" AHmms(?HmmSet?); hset="new" resources fixed global create arman; rman="new" manager resource a ABuffer(?inChan?); inChan="new" AIO from channel return the { BuildRecogniser() void } getchar(); Continuenn?); to Return Press printf(?='==========================================nn");' microphone.nn?); by up picked not printf(?is outputn?); speech that ensure headphones printf(?Use microphone.n?); open an uses demo this - printf(?nWARNING Systemn?); Dialog Spoken Asynchronous ATK printf(?nASDS: HTK_Error(9999); throw HTKn?); initialise cannot HRError(9999,?ASDS: (InitHTK(argc,argv,asds_version)<SUCCESS){ if *argv[]) char argc, Initialise(int --------------------------- Code Initialisation ---------------------- val; val[i]="tolower(ch);" ch="val[i];" int i++){>StoreHMMs(hset);
  rman->StoreDict(dict);
  rman->StoreGram(ggrm);
  ResourceGroup *main = rman->NewGroup("main");
  main->AddHMMs(hset); main->AddDict(dict); main->AddGram(ggrm);
  // create the qa objects, these will create the resource groups
  top = new QA("topping",
  "What topping would you like?",
  "topping.net",
  "I have a variety of toppingsn - try your favourite combination");
  qty = new QA("quantity",
  "How many pizzas would you like?",
  "howmany.net",
  "I need to know how many pizzas to deliver");
  // now we have resources, create aio
  aio = new AIO("aio",inChan,rman);
  aio->DefineFiller("ER");
  aio->DefineFiller("SIL");
  aio->DefineFiller("OH");
  // finally create Monitor and attach it to AIO
  amon = new AMonitor;
  aio->AttachMonitor(amon);
  }
  void StartRecogniser()
  {
  // Start up each component thread
  amon->Start();
  aio->Start();
  }
  void ShutDown()
  {
  printf("Shutting downn");
  // wait till components shutdown
  aio->SendMessage("closedown()");
  // then kill monitor
  amon->Terminate();
  HJoinMonitor();
  }
  // ------------------------- Application Code ---------------------------
  void RunApplication()
  {
  // Start recogniser running
  StartRecogniser();
  do{
  top->GetSlot();
  if (!terminated && top->status == grounded) qty->GetSlot();
  if (top->status == grounded && qty->status == grounded) {
  string order = "Your order is "+qty->GetValue()+" "+top->GetValue();
  if (qty->GetValue() == "one")
  order += " pizza.";

  else
  order += " pizzas.";
  printf("Order: %sn",order.c_str());
  aio->SendMessage("tell(""+order+"")");
  }
  top->Reset(); qty->Reset();
  printf("nn=====================================nn");
  }while(!terminated);
  ShutDown();
  }
  // --------------------------- Main Program ----------------------------
  int main(int argc, char *argv[])
  {
  try {
  Initialise(argc,argv);
  BuildRecogniser();
  RunApplication();
  }
  catch (ATK_Error e){
  int n = HRErrorCount();
  printf("ATK Error %dn",e.i);
  for (int i=1; i<=n; i++)
  printf(" %d. %sn",i,HRErrorGetMess(i));
  }
  catch (HTK_Error e){
  int n = HRErrorCount();
  printf("HTK Error %dn",e.i);
  for (int i=1; i<=n; i++)
  printf(" %d. %sn",i,HRErrorGetMess(i));
  }
  return 0;
  }

上一页  1 2 3 4 5 

Tags:vc 调用 HTK

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接