Spaces:
Running
Running
main : fix SRT timestamp to use comma "," instead of dot "."
Browse files
main.cpp
CHANGED
|
@@ -21,7 +21,7 @@ const std::vector<std::string> k_colors = {
|
|
| 21 |
|
| 22 |
// 500 -> 00:05.000
|
| 23 |
// 6000 -> 01:00.000
|
| 24 |
-
std::string to_timestamp(int64_t t) {
|
| 25 |
int64_t msec = t * 10;
|
| 26 |
int64_t hr = msec / (1000 * 60 * 60);
|
| 27 |
msec = msec - hr * (1000 * 60 * 60);
|
|
@@ -31,7 +31,7 @@ std::string to_timestamp(int64_t t) {
|
|
| 31 |
msec = msec - sec * 1000;
|
| 32 |
|
| 33 |
char buf[32];
|
| 34 |
-
snprintf(buf, sizeof(buf), "%02d:%02d:%02d
|
| 35 |
|
| 36 |
return std::string(buf);
|
| 37 |
}
|
|
@@ -262,7 +262,7 @@ bool output_srt(struct whisper_context * ctx, const char * fname, const whisper_
|
|
| 262 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 263 |
|
| 264 |
fout << i + 1 + params.offset_n << "\n";
|
| 265 |
-
fout << to_timestamp(t0) << " --> " << to_timestamp(t1) << "\n";
|
| 266 |
fout << text << "\n\n";
|
| 267 |
}
|
| 268 |
|
|
|
|
| 21 |
|
| 22 |
// 500 -> 00:05.000
|
| 23 |
// 6000 -> 01:00.000
|
| 24 |
+
std::string to_timestamp(int64_t t, bool comma = false) {
|
| 25 |
int64_t msec = t * 10;
|
| 26 |
int64_t hr = msec / (1000 * 60 * 60);
|
| 27 |
msec = msec - hr * (1000 * 60 * 60);
|
|
|
|
| 31 |
msec = msec - sec * 1000;
|
| 32 |
|
| 33 |
char buf[32];
|
| 34 |
+
snprintf(buf, sizeof(buf), "%02d:%02d:%02d%s%03d", (int) hr, (int) min, (int) sec, comma ? "," : ".", (int) msec);
|
| 35 |
|
| 36 |
return std::string(buf);
|
| 37 |
}
|
|
|
|
| 262 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 263 |
|
| 264 |
fout << i + 1 + params.offset_n << "\n";
|
| 265 |
+
fout << to_timestamp(t0, true) << " --> " << to_timestamp(t1, true) << "\n";
|
| 266 |
fout << text << "\n\n";
|
| 267 |
}
|
| 268 |
|