Skip to content

Commit b31a46f

Browse files
committed
time transcription and add result to verbose_json
1 parent ec2594f commit b31a46f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

whisper.cpp/server/server.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <vector>
1515
#include <cstring>
1616
#include <sstream>
17+
#include <chrono>
1718

1819
#if defined(_MSC_VER)
1920
#pragma warning(disable: 4244 4267) // possible loss of data
@@ -749,6 +750,7 @@ int main(int argc, char ** argv) {
749750
}
750751

751752
// run the inference
753+
float t_total;
752754
{
753755
printf("Running whisper.cpp inference on %s\n", filename.c_str());
754756
whisper_full_params wparams = whisper_full_default_params(WHISPER_SAMPLING_GREEDY);
@@ -828,12 +830,15 @@ int main(int argc, char ** argv) {
828830
wparams.abort_callback_user_data = &is_aborted;
829831
}
830832

833+
// time the processing
834+
auto t_start = std::chrono::high_resolution_clock::now();
831835
if (whisper_full_parallel(ctx, wparams, pcmf32.data(), pcmf32.size(), params.n_processors) != 0) {
832836
fprintf(stderr, "%s: failed to process audio\n", argv[0]);
833837
const std::string error_resp = "{\"error\":\"failed to process audio\"}";
834838
res.set_content(error_resp, "application/json");
835839
return;
836840
}
841+
t_total = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - t_start).count();
837842
}
838843

839844
// return results to user
@@ -893,6 +898,7 @@ int main(int argc, char ** argv) {
893898
{"language", whisper_lang_str_full(whisper_full_lang_id(ctx))},
894899
{"duration", float(pcmf32.size())/WHISPER_SAMPLE_RATE},
895900
{"text", results},
901+
{"transcribe_time", t_total},
896902
{"segments", json::array()}
897903
};
898904
const int n_segments = whisper_full_n_segments(ctx);

0 commit comments

Comments
 (0)