Skip to content

Commit 7787b87

Browse files
committed
ref #16, #22 : add "offset" argument
Allows to start processing the input audio at some offset from the beginning. Useful for splitting a long job into multiple tasks.
1 parent e29a5da commit 7787b87

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ std::string to_timestamp(int64_t t) {
2828
struct whisper_params {
2929
int32_t seed = -1; // RNG seed, not used currently
3030
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
31+
int32_t offset_ms = 0;
3132

3233
bool verbose = false;
3334
bool translate = false;
@@ -55,6 +56,8 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
5556
params.seed = std::stoi(argv[++i]);
5657
} else if (arg == "-t" || arg == "--threads") {
5758
params.n_threads = std::stoi(argv[++i]);
59+
} else if (arg == "-o" || arg == "--offset") {
60+
params.offset_ms = std::stoi(argv[++i]);
5861
} else if (arg == "-v" || arg == "--verbose") {
5962
params.verbose = true;
6063
} else if (arg == "--translate") {
@@ -95,6 +98,7 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
9598
fprintf(stderr, " -h, --help show this help message and exit\n");
9699
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
97100
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
101+
fprintf(stderr, " -o N, --offset N offset in milliseconds (default: %d)\n", params.offset_ms);
98102
fprintf(stderr, " -v, --verbose verbose output\n");
99103
fprintf(stderr, " --translate translate from source language to english\n");
100104
fprintf(stderr, " -ps, --print_special print special tokens\n");
@@ -203,6 +207,7 @@ int main(int argc, char ** argv) {
203207
wparams.translate = params.translate;
204208
wparams.language = params.language.c_str();
205209
wparams.n_threads = params.n_threads;
210+
wparams.offset_ms = params.offset_ms;
206211

207212
if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) {
208213
fprintf(stderr, "%s: failed to process audio\n", argv[0]);

whisper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
22562256
result = (struct whisper_full_params) {
22572257
.strategy = WHISPER_DECODE_GREEDY,
22582258
.n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2259+
.offset_ms = 0,
22592260

22602261
.translate = false,
22612262
.print_special_tokens = false,
@@ -2275,6 +2276,7 @@ struct whisper_full_params whisper_full_default_params(enum whisper_decode_strat
22752276
result = (struct whisper_full_params) {
22762277
.strategy = WHISPER_DECODE_GREEDY,
22772278
.n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency()),
2279+
.offset_ms = 0,
22782280

22792281
.translate = false,
22802282
.print_special_tokens = false,
@@ -2329,7 +2331,7 @@ int whisper_full(
23292331
int progress_step = 5;
23302332

23312333
// main loop
2332-
int seek = 0;
2334+
int seek = params.offset_ms/10;
23332335
while (true) {
23342336
int progress_cur = (100*seek)/whisper_n_len(ctx);
23352337
while (progress_cur >= progress_prev + progress_step) {

whisper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ extern "C" {
102102
enum whisper_decode_strategy strategy;
103103

104104
int n_threads;
105+
int offset_ms;
105106

106107
bool translate;
107108
bool print_special_tokens;

0 commit comments

Comments
 (0)