|
14 | 14 | #include <vector> |
15 | 15 | #include <cstring> |
16 | 16 | #include <sstream> |
| 17 | +#include <chrono> |
17 | 18 |
|
18 | 19 | #if defined(_MSC_VER) |
19 | 20 | #pragma warning(disable: 4244 4267) // possible loss of data |
@@ -749,6 +750,7 @@ int main(int argc, char ** argv) { |
749 | 750 | } |
750 | 751 |
|
751 | 752 | // run the inference |
| 753 | + float t_total; |
752 | 754 | { |
753 | 755 | printf("Running whisper.cpp inference on %s\n", filename.c_str()); |
754 | 756 | whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY); |
@@ -828,12 +830,15 @@ int main(int argc, char ** argv) { |
828 | 830 | wparams.abort_callback_user_data = &is_aborted; |
829 | 831 | } |
830 | 832 |
|
| 833 | + // time the processing |
| 834 | + auto t_start = std::chrono::high_resolution_clock::now(); |
831 | 835 | if (whisper_full_parallel(ctx, wparams, pcmf32.data(), pcmf32.size(), params.n_processors) != 0) { |
832 | 836 | fprintf(stderr, "%s: failed to process audio\n", argv[0]); |
833 | 837 | const std::string error_resp = "{\"error\":\"failed to process audio\"}"; |
834 | 838 | res.set_content(error_resp, "application/json"); |
835 | 839 | return; |
836 | 840 | } |
| 841 | + t_total = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t_start).count(); |
837 | 842 | } |
838 | 843 |
|
839 | 844 | // return results to user |
@@ -893,6 +898,7 @@ int main(int argc, char ** argv) { |
893 | 898 | {"language", whisper_lang_str_full(whisper_full_lang_id(ctx))}, |
894 | 899 | {"duration", float(pcmf32.size())/WHISPER_SAMPLE_RATE}, |
895 | 900 | {"text", results}, |
| 901 | + {"transcribe_time", t_total}, |
896 | 902 | {"segments", json::array()} |
897 | 903 | }; |
898 | 904 | const int n_segments = whisper_full_n_segments(ctx); |
|
0 commit comments