|
|
@ -48,7 +48,6 @@ void replace_all(std::string & s, const std::string & search, const std::string
|
|
|
|
|
|
|
|
|
|
|
|
// command-line parameters
|
|
|
|
// command-line parameters
|
|
|
|
struct whisper_params {
|
|
|
|
struct whisper_params {
|
|
|
|
int32_t seed = -1; // RNG seed, not used currently
|
|
|
|
|
|
|
|
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
|
|
|
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
|
|
|
|
int32_t n_processors = 1;
|
|
|
|
int32_t n_processors = 1;
|
|
|
|
int32_t offset_t_ms = 0;
|
|
|
|
int32_t offset_t_ms = 0;
|
|
|
@ -65,7 +64,7 @@ struct whisper_params {
|
|
|
|
bool output_vtt = false;
|
|
|
|
bool output_vtt = false;
|
|
|
|
bool output_srt = false;
|
|
|
|
bool output_srt = false;
|
|
|
|
bool output_wts = false;
|
|
|
|
bool output_wts = false;
|
|
|
|
bool print_special_tokens = false;
|
|
|
|
bool print_special = false;
|
|
|
|
bool print_colors = false;
|
|
|
|
bool print_colors = false;
|
|
|
|
bool no_timestamps = false;
|
|
|
|
bool no_timestamps = false;
|
|
|
|
|
|
|
|
|
|
|
@ -86,57 +85,31 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (arg == "-s" || arg == "--seed") {
|
|
|
|
if (arg == "-h" || arg == "--help") {
|
|
|
|
params.seed = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-t" || arg == "--threads") {
|
|
|
|
|
|
|
|
params.n_threads = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-p" || arg == "--processors") {
|
|
|
|
|
|
|
|
params.n_processors = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-ot" || arg == "--offset-t") {
|
|
|
|
|
|
|
|
params.offset_t_ms = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-on" || arg == "--offset-n") {
|
|
|
|
|
|
|
|
params.offset_n = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-d" || arg == "--duration") {
|
|
|
|
|
|
|
|
params.duration_ms = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-mc" || arg == "--max-context") {
|
|
|
|
|
|
|
|
params.max_context = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-ml" || arg == "--max-len") {
|
|
|
|
|
|
|
|
params.max_len = std::stoi(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-wt" || arg == "--word-thold") {
|
|
|
|
|
|
|
|
params.word_thold = std::stof(argv[++i]);
|
|
|
|
|
|
|
|
} else if (arg == "-su" || arg == "--speed-up") {
|
|
|
|
|
|
|
|
params.speed_up = true;
|
|
|
|
|
|
|
|
} else if (arg == "-tr" || arg == "--translate") {
|
|
|
|
|
|
|
|
params.translate = true;
|
|
|
|
|
|
|
|
} else if (arg == "-l" || arg == "--language") {
|
|
|
|
|
|
|
|
params.language = argv[++i];
|
|
|
|
|
|
|
|
if (whisper_lang_id(params.language.c_str()) == -1) {
|
|
|
|
|
|
|
|
fprintf(stderr, "error: unknown language '%s'\n", params.language.c_str());
|
|
|
|
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (arg == "-otxt" || arg == "--output-txt") {
|
|
|
|
else if (arg == "-t" || arg == "--threads") { params.n_threads = std::stoi(argv[++i]); }
|
|
|
|
params.output_txt = true;
|
|
|
|
else if (arg == "-p" || arg == "--processors") { params.n_processors = std::stoi(argv[++i]); }
|
|
|
|
} else if (arg == "-ovtt" || arg == "--output-vtt") {
|
|
|
|
else if (arg == "-ot" || arg == "--offset-t") { params.offset_t_ms = std::stoi(argv[++i]); }
|
|
|
|
params.output_vtt = true;
|
|
|
|
else if (arg == "-on" || arg == "--offset-n") { params.offset_n = std::stoi(argv[++i]); }
|
|
|
|
} else if (arg == "-osrt" || arg == "--output-srt") {
|
|
|
|
else if (arg == "-d" || arg == "--duration") { params.duration_ms = std::stoi(argv[++i]); }
|
|
|
|
params.output_srt = true;
|
|
|
|
else if (arg == "-mc" || arg == "--max-context") { params.max_context = std::stoi(argv[++i]); }
|
|
|
|
} else if (arg == "-owts" || arg == "--output-words") {
|
|
|
|
else if (arg == "-ml" || arg == "--max-len") { params.max_len = std::stoi(argv[++i]); }
|
|
|
|
params.output_wts = true;
|
|
|
|
else if (arg == "-wt" || arg == "--word-thold") { params.word_thold = std::stof(argv[++i]); }
|
|
|
|
} else if (arg == "-ps" || arg == "--print_special") {
|
|
|
|
else if (arg == "-su" || arg == "--speed-up") { params.speed_up = true; }
|
|
|
|
params.print_special_tokens = true;
|
|
|
|
else if (arg == "-tr" || arg == "--translate") { params.translate = true; }
|
|
|
|
} else if (arg == "-pc" || arg == "--print_colors") {
|
|
|
|
else if (arg == "-otxt" || arg == "--output-txt") { params.output_txt = true; }
|
|
|
|
params.print_colors = true;
|
|
|
|
else if (arg == "-ovtt" || arg == "--output-vtt") { params.output_vtt = true; }
|
|
|
|
} else if (arg == "-nt" || arg == "--no_timestamps") {
|
|
|
|
else if (arg == "-osrt" || arg == "--output-srt") { params.output_srt = true; }
|
|
|
|
params.no_timestamps = true;
|
|
|
|
else if (arg == "-owts" || arg == "--output-words") { params.output_wts = true; }
|
|
|
|
} else if (arg == "-m" || arg == "--model") {
|
|
|
|
else if (arg == "-ps" || arg == "--print-special") { params.print_special = true; }
|
|
|
|
params.model = argv[++i];
|
|
|
|
else if (arg == "-pc" || arg == "--print-colors") { params.print_colors = true; }
|
|
|
|
} else if (arg == "-f" || arg == "--file") {
|
|
|
|
else if (arg == "-nt" || arg == "--no-timestamps") { params.no_timestamps = true; }
|
|
|
|
params.fname_inp.push_back(argv[++i]);
|
|
|
|
else if (arg == "-l" || arg == "--language") { params.language = argv[++i]; }
|
|
|
|
} else if (arg == "-h" || arg == "--help") {
|
|
|
|
else if (arg == "-m" || arg == "--model") { params.model = argv[++i]; }
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
else if (arg == "-f" || arg == "--file") { params.fname_inp.push_back(argv[++i]); }
|
|
|
|
exit(0);
|
|
|
|
else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
|
|
|
fprintf(stderr, "error: unknown argument: %s\n", arg.c_str());
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
@ -151,28 +124,27 @@ void whisper_print_usage(int argc, char ** argv, const whisper_params & params)
|
|
|
|
fprintf(stderr, "usage: %s [options] file0.wav file1.wav ...\n", argv[0]);
|
|
|
|
fprintf(stderr, "usage: %s [options] file0.wav file1.wav ...\n", argv[0]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "options:\n");
|
|
|
|
fprintf(stderr, "options:\n");
|
|
|
|
fprintf(stderr, " -h, --help show this help message and exit\n");
|
|
|
|
fprintf(stderr, " -h, --help [default] show this help message and exit\n");
|
|
|
|
fprintf(stderr, " -s SEED, --seed SEED RNG seed (default: -1)\n");
|
|
|
|
fprintf(stderr, " -t N, --threads N [%-7d] number of threads to use during computation\n", params.n_threads);
|
|
|
|
fprintf(stderr, " -t N, --threads N number of threads to use during computation (default: %d)\n", params.n_threads);
|
|
|
|
fprintf(stderr, " -p N, --processors N [%-7d] number of processors to use during computation\n", params.n_processors);
|
|
|
|
fprintf(stderr, " -p N, --processors N number of processors to use during computation (default: %d)\n", params.n_processors);
|
|
|
|
fprintf(stderr, " -ot N, --offset-t N [%-7d] time offset in milliseconds\n", params.offset_t_ms);
|
|
|
|
fprintf(stderr, " -ot N, --offset-t N time offset in milliseconds (default: %d)\n", params.offset_t_ms);
|
|
|
|
fprintf(stderr, " -on N, --offset-n N [%-7d] segment index offset\n", params.offset_n);
|
|
|
|
fprintf(stderr, " -on N, --offset-n N segment index offset (default: %d)\n", params.offset_n);
|
|
|
|
fprintf(stderr, " -d N, --duration N [%-7d] duration of audio to process in milliseconds\n", params.duration_ms);
|
|
|
|
fprintf(stderr, " -d N, --duration N duration of audio to process in milliseconds (default: %d)\n", params.duration_ms);
|
|
|
|
fprintf(stderr, " -mc N, --max-context N [%-7d] maximum number of text context tokens to store\n", params.max_context);
|
|
|
|
fprintf(stderr, " -mc N, --max-context N maximum number of text context tokens to store (default: max)\n");
|
|
|
|
fprintf(stderr, " -ml N, --max-len N [%-7d] maximum segment length in characters\n", params.max_len);
|
|
|
|
fprintf(stderr, " -ml N, --max-len N maximum segment length in characters (default: %d)\n", params.max_len);
|
|
|
|
fprintf(stderr, " -wt N, --word-thold N [%-7f] word timestamp probability threshold\n", params.word_thold);
|
|
|
|
fprintf(stderr, " -wt N, --word-thold N word timestamp probability threshold (default: %f)\n", params.word_thold);
|
|
|
|
fprintf(stderr, " -su, --speed-up [%-7s] speed up audio by x2 (reduced accuracy)\n", params.speed_up ? "true" : "false");
|
|
|
|
fprintf(stderr, " -su, --speed-up speed up audio by factor of 2 (faster processing, reduced accuracy, default: %s)\n", params.speed_up ? "true" : "false");
|
|
|
|
fprintf(stderr, " -tr, --translate [%-7s] translate from source language to english\n", params.translate ? "true" : "false");
|
|
|
|
fprintf(stderr, " -tr, --translate translate from source language to english\n");
|
|
|
|
fprintf(stderr, " -otxt, --output-txt [%-7s] output result in a text file\n", params.output_txt ? "true" : "false");
|
|
|
|
fprintf(stderr, " -otxt, --output-txt output result in a text file\n");
|
|
|
|
fprintf(stderr, " -ovtt, --output-vtt [%-7s] output result in a vtt file\n", params.output_vtt ? "true" : "false");
|
|
|
|
fprintf(stderr, " -ovtt, --output-vtt output result in a vtt file\n");
|
|
|
|
fprintf(stderr, " -osrt, --output-srt [%-7s] output result in a srt file\n", params.output_srt ? "true" : "false");
|
|
|
|
fprintf(stderr, " -osrt, --output-srt output result in a srt file\n");
|
|
|
|
fprintf(stderr, " -owts, --output-words [%-7s] output script for generating karaoke video\n", params.output_wts ? "true" : "false");
|
|
|
|
fprintf(stderr, " -owts, --output-words output script for generating karaoke video\n");
|
|
|
|
fprintf(stderr, " -ps, --print-special [%-7s] print special tokens\n", params.print_special ? "true" : "false");
|
|
|
|
fprintf(stderr, " -ps, --print_special print special tokens\n");
|
|
|
|
fprintf(stderr, " -pc, --print-colors [%-7s] print colors\n", params.print_colors ? "true" : "false");
|
|
|
|
fprintf(stderr, " -pc, --print_colors print colors\n");
|
|
|
|
fprintf(stderr, " -nt, --no-timestamps [%-7s] do not print timestamps\n", params.no_timestamps ? "false" : "true");
|
|
|
|
fprintf(stderr, " -nt, --no_timestamps do not print timestamps\n");
|
|
|
|
fprintf(stderr, " -l LANG, --language LANG [%-7s] spoken language\n", params.language.c_str());
|
|
|
|
fprintf(stderr, " -l LANG, --language LANG spoken language (default: %s)\n", params.language.c_str());
|
|
|
|
fprintf(stderr, " -m FNAME, --model FNAME [%-7s] model path\n", params.model.c_str());
|
|
|
|
fprintf(stderr, " -m FNAME, --model FNAME model path (default: %s)\n", params.model.c_str());
|
|
|
|
fprintf(stderr, " -f FNAME, --file FNAME [%-7s] input WAV file path\n", "");
|
|
|
|
fprintf(stderr, " -f FNAME, --file FNAME input WAV file path\n");
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -191,7 +163,7 @@ void whisper_print_segment_callback(struct whisper_context * ctx, int n_new, voi
|
|
|
|
if (params.no_timestamps) {
|
|
|
|
if (params.no_timestamps) {
|
|
|
|
if (params.print_colors) {
|
|
|
|
if (params.print_colors) {
|
|
|
|
for (int j = 0; j < whisper_full_n_tokens(ctx, i); ++j) {
|
|
|
|
for (int j = 0; j < whisper_full_n_tokens(ctx, i); ++j) {
|
|
|
|
if (params.print_special_tokens == false) {
|
|
|
|
if (params.print_special == false) {
|
|
|
|
const whisper_token id = whisper_full_get_token_id(ctx, i, j);
|
|
|
|
const whisper_token id = whisper_full_get_token_id(ctx, i, j);
|
|
|
|
if (id >= whisper_token_eot(ctx)) {
|
|
|
|
if (id >= whisper_token_eot(ctx)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -217,7 +189,7 @@ void whisper_print_segment_callback(struct whisper_context * ctx, int n_new, voi
|
|
|
|
if (params.print_colors) {
|
|
|
|
if (params.print_colors) {
|
|
|
|
printf("[%s --> %s] ", to_timestamp(t0).c_str(), to_timestamp(t1).c_str());
|
|
|
|
printf("[%s --> %s] ", to_timestamp(t0).c_str(), to_timestamp(t1).c_str());
|
|
|
|
for (int j = 0; j < whisper_full_n_tokens(ctx, i); ++j) {
|
|
|
|
for (int j = 0; j < whisper_full_n_tokens(ctx, i); ++j) {
|
|
|
|
if (params.print_special_tokens == false) {
|
|
|
|
if (params.print_special == false) {
|
|
|
|
const whisper_token id = whisper_full_get_token_id(ctx, i, j);
|
|
|
|
const whisper_token id = whisper_full_get_token_id(ctx, i, j);
|
|
|
|
if (id >= whisper_token_eot(ctx)) {
|
|
|
|
if (id >= whisper_token_eot(ctx)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -428,16 +400,18 @@ int main(int argc, char ** argv) {
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (params.seed < 0) {
|
|
|
|
|
|
|
|
params.seed = time(NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (params.fname_inp.empty()) {
|
|
|
|
if (params.fname_inp.empty()) {
|
|
|
|
fprintf(stderr, "error: no input files specified\n");
|
|
|
|
fprintf(stderr, "error: no input files specified\n");
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
return 2;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (whisper_lang_id(params.language.c_str()) == -1) {
|
|
|
|
|
|
|
|
fprintf(stderr, "error: unknown language '%s'\n", params.language.c_str());
|
|
|
|
|
|
|
|
whisper_print_usage(argc, argv, params);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// whisper init
|
|
|
|
// whisper init
|
|
|
|
|
|
|
|
|
|
|
|
struct whisper_context * ctx = whisper_init(params.model.c_str());
|
|
|
|
struct whisper_context * ctx = whisper_init(params.model.c_str());
|
|
|
@ -474,6 +448,8 @@ int main(int argc, char ** argv) {
|
|
|
|
fprintf(stderr, "error: failed to open WAV file from stdin\n");
|
|
|
|
fprintf(stderr, "error: failed to open WAV file from stdin\n");
|
|
|
|
return 4;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "%s: read %zu bytes from stdin\n", __func__, wav_data.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (drwav_init_file(&wav, fname_inp.c_str(), NULL) == false) {
|
|
|
|
else if (drwav_init_file(&wav, fname_inp.c_str(), NULL) == false) {
|
|
|
|
fprintf(stderr, "error: failed to open '%s' as WAV file\n", fname_inp.c_str());
|
|
|
|
fprintf(stderr, "error: failed to open '%s' as WAV file\n", fname_inp.c_str());
|
|
|
@ -495,7 +471,7 @@ int main(int argc, char ** argv) {
|
|
|
|
return 7;
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int n = wav.totalPCMFrameCount;
|
|
|
|
const uint64_t n = wav_data.empty() ? wav.totalPCMFrameCount : wav_data.size()/(wav.channels*wav.bitsPerSample/8);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<int16_t> pcm16;
|
|
|
|
std::vector<int16_t> pcm16;
|
|
|
|
pcm16.resize(n*wav.channels);
|
|
|
|
pcm16.resize(n*wav.channels);
|
|
|
@ -550,7 +526,7 @@ int main(int argc, char ** argv) {
|
|
|
|
wparams.print_realtime = false;
|
|
|
|
wparams.print_realtime = false;
|
|
|
|
wparams.print_progress = false;
|
|
|
|
wparams.print_progress = false;
|
|
|
|
wparams.print_timestamps = !params.no_timestamps;
|
|
|
|
wparams.print_timestamps = !params.no_timestamps;
|
|
|
|
wparams.print_special_tokens = params.print_special_tokens;
|
|
|
|
wparams.print_special = params.print_special;
|
|
|
|
wparams.translate = params.translate;
|
|
|
|
wparams.translate = params.translate;
|
|
|
|
wparams.language = params.language.c_str();
|
|
|
|
wparams.language = params.language.c_str();
|
|
|
|
wparams.n_threads = params.n_threads;
|
|
|
|
wparams.n_threads = params.n_threads;
|
|
|
|