Răsfoiți Sursa

Output real-time factor (RTF) (#76)

Fangjun Kuang 2 ani în urmă
părinte
comite
41b2116453

+ 1 - 1
sherpa-ncnn/csrc/alsa.cc

@@ -116,7 +116,7 @@ and if you want to select card 3 and the device 0 on that card, please use:
 
 
   if (actual_sample_rate_ != expected_sample_rate_) {
   if (actual_sample_rate_ != expected_sample_rate_) {
     fprintf(stderr, "Failed to set sample rate to %d\n", expected_sample_rate_);
     fprintf(stderr, "Failed to set sample rate to %d\n", expected_sample_rate_);
-    fprintf(stderr, "Current sample rate to %d\n", actual_sample_rate_);
+    fprintf(stderr, "Current sample rate is %d\n", actual_sample_rate_);
     fprintf(stderr,
     fprintf(stderr,
             "Creating a resampler:\n"
             "Creating a resampler:\n"
             "   in_sample_rate: %d\n"
             "   in_sample_rate: %d\n"

+ 2 - 1
sherpa-ncnn/csrc/sherpa-ncnn-alsa.cc

@@ -129,6 +129,7 @@ as the device_name.
 
 
   sherpa_ncnn::Recognizer recognizer(decoder_conf, model_conf, fbank_opts);
   sherpa_ncnn::Recognizer recognizer(decoder_conf, model_conf, fbank_opts);
   sherpa_ncnn::Alsa alsa(device_name);
   sherpa_ncnn::Alsa alsa(device_name);
+  fprintf(stderr, "Use recording device: %s\n", device_name);
 
 
   if (alsa.GetExpectedSampleRate() != expected_sampling_rate) {
   if (alsa.GetExpectedSampleRate() != expected_sampling_rate) {
     fprintf(stderr, "sample rate: %d != %d\n", alsa.GetExpectedSampleRate(),
     fprintf(stderr, "sample rate: %d != %d\n", alsa.GetExpectedSampleRate(),
@@ -153,7 +154,7 @@ as the device_name.
       last_text = text;
       last_text = text;
 
 
       // If you want to display in lower case, please uncomment
       // If you want to display in lower case, please uncomment
-      // the followint two lines
+      // the following two lines
       // std::transform(text.begin(), text.end(), text.begin(),
       // std::transform(text.begin(), text.end(), text.begin(),
       //                [](auto c) { return std::tolower(c); });
       //                [](auto c) { return std::tolower(c); });
 
 

+ 19 - 0
sherpa-ncnn/csrc/sherpa-ncnn.cc

@@ -17,7 +17,10 @@
  * limitations under the License.
  * limitations under the License.
  */
  */
 
 
+#include <stdio.h>
+
 #include <algorithm>
 #include <algorithm>
+#include <chrono>
 #include <iostream>
 #include <iostream>
 
 
 #include "net.h"  // NOLINT
 #include "net.h"  // NOLINT
@@ -94,6 +97,9 @@ for a list of pre-trained models to download.
   std::cout << "wav filename: " << wav_filename << "\n";
   std::cout << "wav filename: " << wav_filename << "\n";
   std::cout << "wav duration (s): " << duration << "\n";
   std::cout << "wav duration (s): " << duration << "\n";
 
 
+  auto begin = std::chrono::steady_clock::now();
+  std::cout << "Started!\n";
+
   recognizer.AcceptWaveform(expected_sampling_rate, samples.data(),
   recognizer.AcceptWaveform(expected_sampling_rate, samples.data(),
                             samples.size());
                             samples.size());
   std::vector<float> tail_paddings(
   std::vector<float> tail_paddings(
@@ -103,8 +109,21 @@ for a list of pre-trained models to download.
 
 
   recognizer.Decode();
   recognizer.Decode();
   auto result = recognizer.GetResult();
   auto result = recognizer.GetResult();
+  std::cout << "Done!\n";
+
   std::cout << "Recognition result for " << wav_filename << "\n"
   std::cout << "Recognition result for " << wav_filename << "\n"
             << result.text << "\n";
             << result.text << "\n";
 
 
+  auto end = std::chrono::steady_clock::now();
+  float elapsed_seconds =
+      std::chrono::duration_cast<std::chrono::milliseconds>(end - begin)
+          .count() /
+      1000.;
+
+  printf("Elapsed seconds: %.3f s\n", elapsed_seconds);
+  float rtf = elapsed_seconds / duration;
+  printf("Real time factor (RTF): %.3f / %.3f = %.3f\n", duration,
+         elapsed_seconds, rtf);
+
   return 0;
   return 0;
 }
 }