@@ -22,14 +22,16 @@ namespace sherpa_onnx {
22
22
template <typename T>
23
23
std::string VecToString (const std::vector<T> &vec, int32_t precision = 6 ) {
24
24
std::ostringstream oss;
25
- oss << std::fixed << std::setprecision (precision);
26
- oss << " [ " ;
25
+ if (precision != 0 ) {
26
+ oss << std::fixed << std::setprecision (precision);
27
+ }
28
+ oss << " [" ;
27
29
std::string sep = " " ;
28
30
for (const auto &item : vec) {
29
31
oss << sep << item;
30
32
sep = " , " ;
31
33
}
32
- oss << " ]" ;
34
+ oss << " ]" ;
33
35
return oss.str ();
34
36
}
35
37
@@ -38,26 +40,29 @@ template <> // explicit specialization for T = std::string
38
40
std::string VecToString<std::string>(const std::vector<std::string> &vec,
39
41
int32_t ) { // ignore 2nd arg
40
42
std::ostringstream oss;
41
- oss << " [ " ;
43
+ oss << " [" ;
42
44
std::string sep = " " ;
43
45
for (const auto &item : vec) {
44
46
oss << sep << " \" " << item << " \" " ;
45
47
sep = " , " ;
46
48
}
47
- oss << " ]" ;
49
+ oss << " ]" ;
48
50
return oss.str ();
49
51
}
50
52
51
53
std::string OnlineRecognizerResult::AsJsonString () const {
52
54
std::ostringstream os;
53
55
os << " { " ;
54
- os << " \" text\" : " << " \" " << text << " \" " << " , " ;
56
+ os << " \" text\" : "
57
+ << " \" " << text << " \" "
58
+ << " , " ;
55
59
os << " \" tokens\" : " << VecToString (tokens) << " , " ;
56
60
os << " \" timestamps\" : " << VecToString (timestamps, 2 ) << " , " ;
57
61
os << " \" ys_probs\" : " << VecToString (ys_probs, 6 ) << " , " ;
58
62
os << " \" lm_probs\" : " << VecToString (lm_probs, 6 ) << " , " ;
59
63
os << " \" context_scores\" : " << VecToString (context_scores, 6 ) << " , " ;
60
64
os << " \" segment\" : " << segment << " , " ;
65
+ os << " \" words\" : " << VecToString (words, 0 ) << " , " ;
61
66
os << " \" start_time\" : " << std::fixed << std::setprecision (2 ) << start_time
62
67
<< " , " ;
63
68
os << " \" is_final\" : " << (is_final ? " true" : " false" );
0 commit comments