unity_lib.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "ggml/ggml.h"
  2. #include "ggml/ggml-alloc.h"
  3. #include "math.h"
  4. #include "model_loader.h"
  5. #include "fairseq2.h"
  6. #include <thread>
  7. #include <cassert>
  8. #include <cmath>
  9. #include <cstdio>
  10. #include <cstring>
  11. #include <fstream>
  12. #include <map>
  13. #include <string>
  14. #include <vector>
  15. #include <iostream>
  16. #include <cstdlib>
  17. struct Result {
  18. std::vector<std::string> transcription;
  19. std::vector<float> word_confidence_scores;
  20. std::unordered_map<std::string, float> lid_scores;
  21. int err;
  22. };
  23. struct ggml_cgraph * unity_speech_encoder(
  24. fairseq2_model& model,
  25. struct ggml_tensor * speech_input
  26. );
  27. struct ggml_cgraph * unity_text_encoder(
  28. fairseq2_model& model,
  29. struct ggml_tensor * text_input
  30. );
  31. Hypothesis* unity_decode(
  32. fairseq2_model& model,
  33. const SequenceGeneratorOptions& opts,
  34. int tgt_lang_idx,
  35. ggml_tensor* encoder_output,
  36. int n_threads
  37. );
  38. extern "C" fairseq2_model unity_init_model(const char* model_path);
  39. extern "C" Result unity_eval_speech(
  40. fairseq2_model& model,
  41. std::vector<float>& data,
  42. SequenceGeneratorOptions opts,
  43. std::string tgt_lang,
  44. int n_threads
  45. );
  46. extern "C" Result unity_eval_text(
  47. fairseq2_model& model,
  48. const std::string& text,
  49. SequenceGeneratorOptions opts,
  50. std::string tgt_lang,
  51. int n_threads
  52. );