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.

48 lines
1.7 KiB

  1. // Copyright (c) 2023 Ximalaya Speech Team (Xiang Lyu)
  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 "frontend/wav.h"
  15. #include "http/http_client.h"
  16. #include "utils/flags.h"
  17. #include "utils/timer.h"
  18. DEFINE_string(hostname, "127.0.0.1", "hostname of http server");
  19. DEFINE_int32(port, 10086, "port of http server");
  20. DEFINE_int32(nbest, 1, "n-best of decode result");
  21. DEFINE_string(wav_path, "", "test wav file path");
  22. int main(int argc, char* argv[]) {
  23. gflags::ParseCommandLineFlags(&argc, &argv, false);
  24. google::InitGoogleLogging(argv[0]);
  25. wenet::WavReader wav_reader(FLAGS_wav_path);
  26. const int sample_rate = 16000;
  27. // Only support 16K
  28. CHECK_EQ(wav_reader.sample_rate(), sample_rate);
  29. const int num_samples = wav_reader.num_samples();
  30. // Convert to short
  31. std::vector<int16_t> data;
  32. data.reserve(num_samples);
  33. for (int j = 0; j < num_samples; j++) {
  34. data.push_back(static_cast<int16_t>(wav_reader.data()[j]));
  35. }
  36. // Send data
  37. wenet::HttpClient client(FLAGS_hostname, FLAGS_port);
  38. client.set_nbest(FLAGS_nbest);
  39. wenet::Timer timer;
  40. VLOG(2) << "Send " << data.size() << " samples";
  41. client.SendBinaryData(data.data(), data.size() * sizeof(int16_t));
  42. VLOG(2) << "Total latency: " << timer.Elapsed() << "ms.";
  43. return 0;
  44. }