diff --git a/sherpa-onnx/csrc/offline-stream.cc b/sherpa-onnx/csrc/offline-stream.cc index 9beb8669..5284abf4 100644 --- a/sherpa-onnx/csrc/offline-stream.cc +++ b/sherpa-onnx/csrc/offline-stream.cc @@ -8,8 +8,9 @@ #include #include -#include "nlohmann/json.hpp" + #include "kaldi-native-fbank/csrc/online-feature.h" +#include "nlohmann/json.hpp" #include "sherpa-onnx/csrc/macros.h" #include "sherpa-onnx/csrc/offline-recognizer.h" #include "sherpa-onnx/csrc/resample.h" @@ -218,7 +219,19 @@ std::string OfflineRecognitionResult::AsJsonString() const { nlohmann::json j; j["text"] = text; j["tokens"] = tokens; - j["timestamps"] = timestamps; + + std::ostringstream os; + os << "["; + std::string sep = ""; + for (auto t : timestamps) { + os << sep << std::fixed << std::setprecision(2) << t; + sep = ","; + } + os << "]"; + + // NOTE: We don't use j["timestamps"] = timestamps; + // because we need to control the number of decimal points to keep + j["timestamps"] = os.str(); return j.dump(); }