Spaces:
Running
Running
ref #68 : add option "-on" to specify segment index offset for SRT
Browse files
main.cpp
CHANGED
|
@@ -30,9 +30,10 @@ std::string to_timestamp(int64_t t) {
|
|
| 30 |
|
| 31 |
// command-line parameters
|
| 32 |
struct whisper_params {
|
| 33 |
-
int32_t seed
|
| 34 |
-
int32_t n_threads
|
| 35 |
-
int32_t
|
|
|
|
| 36 |
|
| 37 |
bool verbose = false;
|
| 38 |
bool translate = false;
|
|
@@ -63,8 +64,10 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
|
|
| 63 |
params.seed = std::stoi(argv[++i]);
|
| 64 |
} else if (arg == "-t" || arg == "--threads") {
|
| 65 |
params.n_threads = std::stoi(argv[++i]);
|
| 66 |
-
} else if (arg == "-
|
| 67 |
-
params.
|
|
|
|
|
|
|
| 68 |
} else if (arg == "-v" || arg == "--verbose") {
|
| 69 |
params.verbose = true;
|
| 70 |
} else if (arg == "--translate") {
|
|
@@ -111,7 +114,8 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
|
|
| 111 |
fprintf(stderr, " -h, --help show this help message and exit\n");
|
| 112 |
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
|
| 113 |
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
| 114 |
-
fprintf(stderr, " -
|
|
|
|
| 115 |
fprintf(stderr, " -v, --verbose verbose output\n");
|
| 116 |
fprintf(stderr, " --translate translate from source language to english\n");
|
| 117 |
fprintf(stderr, " -otxt, --output-txt output result in a text file\n");
|
|
@@ -225,7 +229,7 @@ int main(int argc, char ** argv) {
|
|
| 225 |
wparams.translate = params.translate;
|
| 226 |
wparams.language = params.language.c_str();
|
| 227 |
wparams.n_threads = params.n_threads;
|
| 228 |
-
wparams.offset_ms = params.
|
| 229 |
|
| 230 |
if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
|
| 231 |
fprintf(stderr, "%s: failed to process audio\n", argv[0]);
|
|
@@ -316,7 +320,7 @@ int main(int argc, char ** argv) {
|
|
| 316 |
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
|
| 317 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 318 |
|
| 319 |
-
fout_srt << i + 1 << "\n";
|
| 320 |
fout_srt << to_timestamp(t0) << " --> " << to_timestamp(t1) << "\n";
|
| 321 |
fout_srt << text << "\n\n";
|
| 322 |
}
|
|
|
|
| 30 |
|
| 31 |
// command-line parameters
|
| 32 |
struct whisper_params {
|
| 33 |
+
int32_t seed = -1; // RNG seed, not used currently
|
| 34 |
+
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
| 35 |
+
int32_t offset_t_ms = 0;
|
| 36 |
+
int32_t offset_n = 0;
|
| 37 |
|
| 38 |
bool verbose = false;
|
| 39 |
bool translate = false;
|
|
|
|
| 64 |
params.seed = std::stoi(argv[++i]);
|
| 65 |
} else if (arg == "-t" || arg == "--threads") {
|
| 66 |
params.n_threads = std::stoi(argv[++i]);
|
| 67 |
+
} else if (arg == "-ot" || arg == "--offset-t") {
|
| 68 |
+
params.offset_t_ms = std::stoi(argv[++i]);
|
| 69 |
+
} else if (arg == "-on" || arg == "--offset-n") {
|
| 70 |
+
params.offset_n = std::stoi(argv[++i]);
|
| 71 |
} else if (arg == "-v" || arg == "--verbose") {
|
| 72 |
params.verbose = true;
|
| 73 |
} else if (arg == "--translate") {
|
|
|
|
| 114 |
fprintf(stderr, " -h, --help show this help message and exit\n");
|
| 115 |
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
|
| 116 |
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
| 117 |
+
fprintf(stderr, " -ot N, --offset-t N time offset in milliseconds (default: %d)\n", params.offset_t_ms);
|
| 118 |
+
fprintf(stderr, " -on N, --offset-n N segment index offset (default: %d)\n", params.offset_n);
|
| 119 |
fprintf(stderr, " -v, --verbose verbose output\n");
|
| 120 |
fprintf(stderr, " --translate translate from source language to english\n");
|
| 121 |
fprintf(stderr, " -otxt, --output-txt output result in a text file\n");
|
|
|
|
| 229 |
wparams.translate = params.translate;
|
| 230 |
wparams.language = params.language.c_str();
|
| 231 |
wparams.n_threads = params.n_threads;
|
| 232 |
+
wparams.offset_ms = params.offset_t_ms;
|
| 233 |
|
| 234 |
if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
|
| 235 |
fprintf(stderr, "%s: failed to process audio\n", argv[0]);
|
|
|
|
| 320 |
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
|
| 321 |
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
|
| 322 |
|
| 323 |
+
fout_srt << i + 1 + params.offset_n << "\n";
|
| 324 |
fout_srt << to_timestamp(t0) << " --> " << to_timestamp(t1) << "\n";
|
| 325 |
fout_srt << text << "\n\n";
|
| 326 |
}
|