You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

  1. // Copyright (c) 2022 Binbin Zhang (binbzha@qq.com)
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "api/wenet_api.h"
  15. #include "frontend/wav.h"
  16. #include "utils/flags.h"
  17. DEFINE_string(model_dir, "", "model dir path");
  18. DEFINE_string(wav_path, "", "single wave path");
  19. DEFINE_bool(enable_timestamp, false, "enable timestamps");
  20. int main(int argc, char* argv[]) {
  21. gflags::ParseCommandLineFlags(&argc, &argv, false);
  22. google::InitGoogleLogging(argv[0]);
  23. wenet_set_log_level(2);
  24. void* decoder = wenet_init(FLAGS_model_dir.c_str());
  25. wenet_set_timestamp(decoder, FLAGS_enable_timestamp == true ? 1 : 0);
  26. wenet::WavReader wav_reader(FLAGS_wav_path);
  27. std::vector<int16_t> data(wav_reader.num_samples());
  28. for (int i = 0; i < wav_reader.num_samples(); i++) {
  29. data[i] = static_cast<int16_t>(*(wav_reader.data() + i));
  30. }
  31. for (int i = 0; i < 10; i++) {
  32. // Return the final result when last is 1
  33. const char* result =
  34. wenet_decode(decoder, reinterpret_cast<const char*>(data.data()),
  35. data.size() * 2, 1);
  36. LOG(INFO) << i << " " << result;
  37. wenet_reset(decoder);
  38. }
  39. wenet_free(decoder);
  40. return 0;
  41. }