Skip to content

Commit fe2d657

Browse files
ggerganovjiahansu
authored andcommitted
main : add cli option to disable system prints (ggml-org#1740)
1 parent a6c6ea0 commit fe2d657

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

examples/main/main.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct whisper_params {
8585
bool output_jsn = false;
8686
bool output_jsn_full = false;
8787
bool output_lrc = false;
88+
bool no_prints = false;
8889
bool print_special = false;
8990
bool print_colors = false;
9091
bool print_progress = false;
@@ -155,6 +156,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
155156
else if (arg == "-oj" || arg == "--output-json") { params.output_jsn = true; }
156157
else if (arg == "-ojf" || arg == "--output-json-full"){ params.output_jsn_full = params.output_jsn = true; }
157158
else if (arg == "-of" || arg == "--output-file") { params.fname_out.emplace_back(argv[++i]); }
159+
else if (arg == "-np" || arg == "--no-prints") { params.no_prints = true; }
158160
else if (arg == "-ps" || arg == "--print-special") { params.print_special = true; }
159161
else if (arg == "-pc" || arg == "--print-colors") { params.print_colors = true; }
160162
else if (arg == "-pp" || arg == "--print-progress") { params.print_progress = true; }
@@ -212,6 +214,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
212214
fprintf(stderr, " -oj, --output-json [%-7s] output result in a JSON file\n", params.output_jsn ? "true" : "false");
213215
fprintf(stderr, " -ojf, --output-json-full [%-7s] include more information in the JSON file\n", params.output_jsn_full ? "true" : "false");
214216
fprintf(stderr, " -of FNAME, --output-file FNAME [%-7s] output file path (without file extension)\n", "");
217+
fprintf(stderr, " -np, --no-prints [%-7s] do not print anything other than the results\n", params.no_prints ? "true" : "false");
215218
fprintf(stderr, " -ps, --print-special [%-7s] print special tokens\n", params.print_special ? "true" : "false");
216219
fprintf(stderr, " -pc, --print-colors [%-7s] print colors\n", params.print_colors ? "true" : "false");
217220
fprintf(stderr, " -pp, --print-progress [%-7s] print progress\n", params.print_progress ? "true" : "false");
@@ -852,6 +855,9 @@ bool output_lrc(struct whisper_context * ctx, const char * fname, const whisper_
852855
return true;
853856
}
854857

858+
859+
void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
860+
855861
int main(int argc, char ** argv) {
856862
whisper_params params;
857863

@@ -878,6 +884,10 @@ int main(int argc, char ** argv) {
878884
exit(0);
879885
}
880886

887+
if (params.no_prints) {
888+
whisper_log_set(cb_log_disable, NULL);
889+
}
890+
881891
// whisper init
882892

883893
struct whisper_context_params cparams;
@@ -905,26 +915,25 @@ int main(int argc, char ** argv) {
905915
continue;
906916
}
907917

908-
// print system information
909-
{
918+
if (!whisper_is_multilingual(ctx)) {
919+
if (params.language != "en" || params.translate) {
920+
params.language = "en";
921+
params.translate = false;
922+
fprintf(stderr, "%s: WARNING: model is not multilingual, ignoring language and translation options\n", __func__);
923+
}
924+
}
925+
if (params.detect_language) {
926+
params.language = "auto";
927+
}
928+
929+
if (!params.no_prints) {
930+
// print system information
910931
fprintf(stderr, "\n");
911932
fprintf(stderr, "system_info: n_threads = %d / %d | %s\n",
912933
params.n_threads*params.n_processors, std::thread::hardware_concurrency(), whisper_print_system_info());
913-
}
914934

915-
// print some info about the processing
916-
{
935+
// print some info about the processing
917936
fprintf(stderr, "\n");
918-
if (!whisper_is_multilingual(ctx)) {
919-
if (params.language != "en" || params.translate) {
920-
params.language = "en";
921-
params.translate = false;
922-
fprintf(stderr, "%s: WARNING: model is not multilingual, ignoring language and translation options\n", __func__);
923-
}
924-
}
925-
if (params.detect_language) {
926-
params.language = "auto";
927-
}
928937
fprintf(stderr, "%s: processing '%s' (%d samples, %.1f sec), %d threads, %d processors, %d beams + best of %d, lang = %s, task = %s, %stimestamps = %d ...\n",
929938
__func__, fname_inp.c_str(), int(pcmf32.size()), float(pcmf32.size())/WHISPER_SAMPLE_RATE,
930939
params.n_threads, params.n_processors, params.beam_size, params.best_of,

whisper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static ggml_backend_t whisper_backend_init(const whisper_context_params & params
10701070
#ifdef GGML_USE_METAL
10711071
if (params.use_gpu) {
10721072
WHISPER_LOG_INFO("%s: using Metal backend\n", __func__);
1073-
ggml_metal_log_set_callback(whisper_log_callback_default, nullptr);
1073+
ggml_metal_log_set_callback(g_state.log_callback, g_state.log_callback_user_data);
10741074
backend_gpu = ggml_backend_metal_init();
10751075
if (!backend_gpu) {
10761076
WHISPER_LOG_ERROR("%s: ggml_backend_metal_init() failed\n", __func__);

0 commit comments

Comments
 (0)