Committed by
GitHub
Use fixed decimal point for offline timestamp (#158)
正在显示
1 个修改的文件
包含
15 行增加
和
2 行删除
| @@ -8,8 +8,9 @@ | @@ -8,8 +8,9 @@ | ||
| 8 | 8 | ||
| 9 | #include <algorithm> | 9 | #include <algorithm> |
| 10 | #include <cmath> | 10 | #include <cmath> |
| 11 | -#include "nlohmann/json.hpp" | 11 | + |
| 12 | #include "kaldi-native-fbank/csrc/online-feature.h" | 12 | #include "kaldi-native-fbank/csrc/online-feature.h" |
| 13 | +#include "nlohmann/json.hpp" | ||
| 13 | #include "sherpa-onnx/csrc/macros.h" | 14 | #include "sherpa-onnx/csrc/macros.h" |
| 14 | #include "sherpa-onnx/csrc/offline-recognizer.h" | 15 | #include "sherpa-onnx/csrc/offline-recognizer.h" |
| 15 | #include "sherpa-onnx/csrc/resample.h" | 16 | #include "sherpa-onnx/csrc/resample.h" |
| @@ -218,7 +219,19 @@ std::string OfflineRecognitionResult::AsJsonString() const { | @@ -218,7 +219,19 @@ std::string OfflineRecognitionResult::AsJsonString() const { | ||
| 218 | nlohmann::json j; | 219 | nlohmann::json j; |
| 219 | j["text"] = text; | 220 | j["text"] = text; |
| 220 | j["tokens"] = tokens; | 221 | j["tokens"] = tokens; |
| 221 | - j["timestamps"] = timestamps; | 222 | + |
| 223 | + std::ostringstream os; | ||
| 224 | + os << "["; | ||
| 225 | + std::string sep = ""; | ||
| 226 | + for (auto t : timestamps) { | ||
| 227 | + os << sep << std::fixed << std::setprecision(2) << t; | ||
| 228 | + sep = ","; | ||
| 229 | + } | ||
| 230 | + os << "]"; | ||
| 231 | + | ||
| 232 | + // NOTE: We don't use j["timestamps"] = timestamps; | ||
| 233 | + // because we need to control the number of decimal points to keep | ||
| 234 | + j["timestamps"] = os.str(); | ||
| 222 | 235 | ||
| 223 | return j.dump(); | 236 | return j.dump(); |
| 224 | } | 237 | } |
-
请 注册 或 登录 后发表评论