// file: $isip/doc/examples/class/search/search_example_01/example.cc
// version: $Id: example.cc 6847 2001-04-28 23:52:25Z jelinek $
//

// isip include files
//
#include <Console.h>
#include <FrontEnd.h>
#include <HierarchicalSearch.h>
#include <Filename.h>

int main(int argc, const char** argv) {

  // configure FrontEnd
  //
  FrontEnd fe;
             
  Sof front_end_sof;
  front_end_sof.open(L"$ISIP_DEVEL/util/speech/isip_recognize/param.sof");
  fe.read(front_end_sof, front_end_sof.first(fe.name()));
  front_end_sof.close();

  // configure HierarchicalSearch
  //
  HierarchicalSearch search_engine;
  long num_levels = 3;
  search_engine.setNumLevels(num_levels);

  // read models
  //
  Sof model_sof;
  model_sof.open(L"$ISIP_DEVEL/doc/examples/data/models/tidigit_preview.sof");

  for (long curr_level = 0; curr_level < num_levels; curr_level++) {
    SearchLevel& level = search_engine.getSearchLevel(curr_level);
    level.load(model_sof);
  }
  model_sof.close();

  // process the sentence
  //
  Filename speech_file(L"$ISIP_DEVEL/doc/examples/data/audio/bg_119oo39a.raw");

  fe.open(speech_file);
  search_engine.decode(fe);
  fe.close();

  // get the best hypothesis
  //
  String best_hypothesis;
  float score = 0;
  long num_frames = 0;
  search_engine.getHypotheses(best_hypothesis, score, num_frames);

  // print the hypotheses
  //
  Console::put(best_hypothesis);

}
