@@ -68,28 +68,32 @@ struct whisper_params {
68
68
float entropy_thold = 2 .40f ;
69
69
float logprob_thold = -1 .00f ;
70
70
71
- bool speed_up = false ;
72
- bool translate = false ;
73
- bool detect_language= false ;
74
- bool diarize = false ;
75
- bool split_on_word = false ;
76
- bool no_fallback = false ;
77
- bool output_txt = false ;
78
- bool output_vtt = false ;
79
- bool output_srt = false ;
80
- bool output_wts = false ;
81
- bool output_csv = false ;
82
- bool output_jsn = false ;
83
- bool output_lrc = false ;
84
- bool print_special = false ;
85
- bool print_colors = false ;
86
- bool print_progress = false ;
87
- bool no_timestamps = false ;
88
-
89
- std::string language = " en" ;
71
+ bool speed_up = false ;
72
+ bool translate = false ;
73
+ bool detect_language = false ;
74
+ bool diarize = false ;
75
+ bool tinydiarize = false ;
76
+ bool split_on_word = false ;
77
+ bool no_fallback = false ;
78
+ bool output_txt = false ;
79
+ bool output_vtt = false ;
80
+ bool output_srt = false ;
81
+ bool output_wts = false ;
82
+ bool output_csv = false ;
83
+ bool output_jsn = false ;
84
+ bool output_lrc = false ;
85
+ bool print_special = false ;
86
+ bool print_colors = false ;
87
+ bool print_progress = false ;
88
+ bool no_timestamps = false ;
89
+
90
+ std::string language = " en" ;
90
91
std::string prompt;
91
92
std::string font_path = " /System/Library/Fonts/Supplemental/Courier New Bold.ttf" ;
92
- std::string model = " models/ggml-base.en.bin" ;
93
+ std::string model = " models/ggml-base.en.bin" ;
94
+
95
+ // [TDRZ] speaker turn string
96
+ std::string tdrz_speaker_turn = " [SPEAKER_TURN]" ; // TODO: set from command line
93
97
94
98
std::vector<std::string> fname_inp = {};
95
99
std::vector<std::string> fname_out = {};
@@ -115,41 +119,42 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
115
119
whisper_print_usage (argc, argv, params);
116
120
exit (0 );
117
121
}
118
- else if (arg == " -t" || arg == " --threads" ) { params.n_threads = std::stoi (argv[++i]); }
119
- else if (arg == " -p" || arg == " --processors" ) { params.n_processors = std::stoi (argv[++i]); }
120
- else if (arg == " -ot" || arg == " --offset-t" ) { params.offset_t_ms = std::stoi (argv[++i]); }
121
- else if (arg == " -on" || arg == " --offset-n" ) { params.offset_n = std::stoi (argv[++i]); }
122
- else if (arg == " -d" || arg == " --duration" ) { params.duration_ms = std::stoi (argv[++i]); }
123
- else if (arg == " -mc" || arg == " --max-context" ) { params.max_context = std::stoi (argv[++i]); }
124
- else if (arg == " -ml" || arg == " --max-len" ) { params.max_len = std::stoi (argv[++i]); }
125
- else if (arg == " -bo" || arg == " --best-of" ) { params.best_of = std::stoi (argv[++i]); }
126
- else if (arg == " -bs" || arg == " --beam-size" ) { params.beam_size = std::stoi (argv[++i]); }
127
- else if (arg == " -wt" || arg == " --word-thold" ) { params.word_thold = std::stof (argv[++i]); }
128
- else if (arg == " -et" || arg == " --entropy-thold" ) { params.entropy_thold = std::stof (argv[++i]); }
129
- else if (arg == " -lpt" || arg == " --logprob-thold" ) { params.logprob_thold = std::stof (argv[++i]); }
130
- else if (arg == " -su" || arg == " --speed-up" ) { params.speed_up = true ; }
131
- else if (arg == " -tr" || arg == " --translate" ) { params.translate = true ; }
132
- else if (arg == " -di" || arg == " --diarize" ) { params.diarize = true ; }
133
- else if (arg == " -sow" || arg == " --split-on-word" ) { params.split_on_word = true ; }
134
- else if (arg == " -nf" || arg == " --no-fallback" ) { params.no_fallback = true ; }
135
- else if (arg == " -otxt" || arg == " --output-txt" ) { params.output_txt = true ; }
136
- else if (arg == " -ovtt" || arg == " --output-vtt" ) { params.output_vtt = true ; }
137
- else if (arg == " -osrt" || arg == " --output-srt" ) { params.output_srt = true ; }
138
- else if (arg == " -owts" || arg == " --output-words" ) { params.output_wts = true ; }
139
- else if (arg == " -olrc" || arg == " --output-lrc" ) { params.output_lrc = true ; }
140
- else if (arg == " -fp" || arg == " --font-path" ) { params.font_path = argv[++i]; }
141
- else if (arg == " -ocsv" || arg == " --output-csv" ) { params.output_csv = true ; }
142
- else if (arg == " -oj" || arg == " --output-json" ) { params.output_jsn = true ; }
143
- else if (arg == " -of" || arg == " --output-file" ) { params.fname_out .emplace_back (argv[++i]); }
144
- else if (arg == " -ps" || arg == " --print-special" ) { params.print_special = true ; }
145
- else if (arg == " -pc" || arg == " --print-colors" ) { params.print_colors = true ; }
146
- else if (arg == " -pp" || arg == " --print-progress" ) { params.print_progress = true ; }
147
- else if (arg == " -nt" || arg == " --no-timestamps" ) { params.no_timestamps = true ; }
148
- else if (arg == " -l" || arg == " --language" ) { params.language = argv[++i]; }
149
- else if (arg == " -dl" || arg == " --detect-language" ){ params.detect_language = true ; }
150
- else if ( arg == " --prompt" ) { params.prompt = argv[++i]; }
151
- else if (arg == " -m" || arg == " --model" ) { params.model = argv[++i]; }
152
- else if (arg == " -f" || arg == " --file" ) { params.fname_inp .emplace_back (argv[++i]); }
122
+ else if (arg == " -t" || arg == " --threads" ) { params.n_threads = std::stoi (argv[++i]); }
123
+ else if (arg == " -p" || arg == " --processors" ) { params.n_processors = std::stoi (argv[++i]); }
124
+ else if (arg == " -ot" || arg == " --offset-t" ) { params.offset_t_ms = std::stoi (argv[++i]); }
125
+ else if (arg == " -on" || arg == " --offset-n" ) { params.offset_n = std::stoi (argv[++i]); }
126
+ else if (arg == " -d" || arg == " --duration" ) { params.duration_ms = std::stoi (argv[++i]); }
127
+ else if (arg == " -mc" || arg == " --max-context" ) { params.max_context = std::stoi (argv[++i]); }
128
+ else if (arg == " -ml" || arg == " --max-len" ) { params.max_len = std::stoi (argv[++i]); }
129
+ else if (arg == " -bo" || arg == " --best-of" ) { params.best_of = std::stoi (argv[++i]); }
130
+ else if (arg == " -bs" || arg == " --beam-size" ) { params.beam_size = std::stoi (argv[++i]); }
131
+ else if (arg == " -wt" || arg == " --word-thold" ) { params.word_thold = std::stof (argv[++i]); }
132
+ else if (arg == " -et" || arg == " --entropy-thold" ) { params.entropy_thold = std::stof (argv[++i]); }
133
+ else if (arg == " -lpt" || arg == " --logprob-thold" ) { params.logprob_thold = std::stof (argv[++i]); }
134
+ else if (arg == " -su" || arg == " --speed-up" ) { params.speed_up = true ; }
135
+ else if (arg == " -tr" || arg == " --translate" ) { params.translate = true ; }
136
+ else if (arg == " -di" || arg == " --diarize" ) { params.diarize = true ; }
137
+ else if (arg == " -tdrz" || arg == " --tinydiarize" ) { params.tinydiarize = true ; }
138
+ else if (arg == " -sow" || arg == " --split-on-word" ) { params.split_on_word = true ; }
139
+ else if (arg == " -nf" || arg == " --no-fallback" ) { params.no_fallback = true ; }
140
+ else if (arg == " -otxt" || arg == " --output-txt" ) { params.output_txt = true ; }
141
+ else if (arg == " -ovtt" || arg == " --output-vtt" ) { params.output_vtt = true ; }
142
+ else if (arg == " -osrt" || arg == " --output-srt" ) { params.output_srt = true ; }
143
+ else if (arg == " -owts" || arg == " --output-words" ) { params.output_wts = true ; }
144
+ else if (arg == " -olrc" || arg == " --output-lrc" ) { params.output_lrc = true ; }
145
+ else if (arg == " -fp" || arg == " --font-path" ) { params.font_path = argv[++i]; }
146
+ else if (arg == " -ocsv" || arg == " --output-csv" ) { params.output_csv = true ; }
147
+ else if (arg == " -oj" || arg == " --output-json" ) { params.output_jsn = true ; }
148
+ else if (arg == " -of" || arg == " --output-file" ) { params.fname_out .emplace_back (argv[++i]); }
149
+ else if (arg == " -ps" || arg == " --print-special" ) { params.print_special = true ; }
150
+ else if (arg == " -pc" || arg == " --print-colors" ) { params.print_colors = true ; }
151
+ else if (arg == " -pp" || arg == " --print-progress" ) { params.print_progress = true ; }
152
+ else if (arg == " -nt" || arg == " --no-timestamps" ) { params.no_timestamps = true ; }
153
+ else if (arg == " -l" || arg == " --language" ) { params.language = argv[++i]; }
154
+ else if (arg == " -dl" || arg == " --detect-language" ) { params.detect_language = true ; }
155
+ else if ( arg == " --prompt" ) { params.prompt = argv[++i]; }
156
+ else if (arg == " -m" || arg == " --model" ) { params.model = argv[++i]; }
157
+ else if (arg == " -f" || arg == " --file" ) { params.fname_inp .emplace_back (argv[++i]); }
153
158
else {
154
159
fprintf (stderr, " error: unknown argument: %s\n " , arg.c_str ());
155
160
whisper_print_usage (argc, argv, params);
@@ -182,6 +187,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
182
187
fprintf (stderr, " -su, --speed-up [%-7s] speed up audio by x2 (reduced accuracy)\n " , params.speed_up ? " true" : " false" );
183
188
fprintf (stderr, " -tr, --translate [%-7s] translate from source language to english\n " , params.translate ? " true" : " false" );
184
189
fprintf (stderr, " -di, --diarize [%-7s] stereo audio diarization\n " , params.diarize ? " true" : " false" );
190
+ fprintf (stderr, " -tdrz, --tinydiarize [%-7s] enable tinydiarize (requires a tdrz model)\n " , params.tinydiarize ? " true" : " false" );
185
191
fprintf (stderr, " -nf, --no-fallback [%-7s] do not use temperature fallback while decoding\n " , params.no_fallback ? " true" : " false" );
186
192
fprintf (stderr, " -otxt, --output-txt [%-7s] output result in a text file\n " , params.output_txt ? " true" : " false" );
187
193
fprintf (stderr, " -ovtt, --output-vtt [%-7s] output result in a vtt file\n " , params.output_vtt ? " true" : " false" );
@@ -297,6 +303,12 @@ void whisper_print_segment_callback(struct whisper_context * ctx, struct whisper
297
303
printf (" %s%s" , speaker.c_str (), text);
298
304
}
299
305
306
+ if (params.tinydiarize ) {
307
+ if (whisper_full_get_segment_speaker_turn_next (ctx, i)) {
308
+ printf (" %s" , params.tdrz_speaker_turn .c_str ());
309
+ }
310
+ }
311
+
300
312
// with timestamps or speakers: each segment on new line
301
313
if (!params.no_timestamps || params.diarize ) {
302
314
printf (" \n " );
@@ -564,6 +576,7 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
564
576
const int n_segments = whisper_full_n_segments (ctx);
565
577
for (int i = 0 ; i < n_segments; ++i) {
566
578
const char * text = whisper_full_get_segment_text (ctx, i);
579
+
567
580
const int64_t t0 = whisper_full_get_segment_t0 (ctx, i);
568
581
const int64_t t1 = whisper_full_get_segment_t1 (ctx, i);
569
582
@@ -576,11 +589,15 @@ bool output_json(struct whisper_context * ctx, const char * fname, const whisper
576
589
value_i (" from" , t0 * 10 , false );
577
590
value_i (" to" , t1 * 10 , true );
578
591
end_obj (false );
579
- value_s (" text" , text, !params.diarize );
592
+ value_s (" text" , text, !params.diarize && !params. tinydiarize );
580
593
581
594
if (params.diarize && pcmf32s.size () == 2 ) {
582
595
value_s (" speaker" , estimate_diarization_speaker (pcmf32s, t0, t1, true ).c_str (), true );
583
596
}
597
+
598
+ if (params.tinydiarize ) {
599
+ value_b (" speaker_turn_next" , whisper_full_get_segment_speaker_turn_next (ctx, i), true );
600
+ }
584
601
end_obj (i == (n_segments - 1 ));
585
602
}
586
603
@@ -777,6 +794,12 @@ int main(int argc, char ** argv) {
777
794
exit (0 );
778
795
}
779
796
797
+ if (params.diarize && params.tinydiarize ) {
798
+ fprintf (stderr, " error: cannot use both --diarize and --tinydiarize\n " );
799
+ whisper_print_usage (argc, argv, params);
800
+ exit (0 );
801
+ }
802
+
780
803
// whisper init
781
804
782
805
struct whisper_context * ctx = whisper_init_from_file (params.model .c_str ());
@@ -818,11 +841,12 @@ int main(int argc, char ** argv) {
818
841
if (params.detect_language ) {
819
842
params.language = " auto" ;
820
843
}
821
- fprintf (stderr, " %s: processing '%s' (%d samples, %.1f sec), %d threads, %d processors, lang = %s, task = %s, timestamps = %d ...\n " ,
844
+ fprintf (stderr, " %s: processing '%s' (%d samples, %.1f sec), %d threads, %d processors, lang = %s, task = %s, %stimestamps = %d ...\n " ,
822
845
__func__, fname_inp.c_str (), int (pcmf32.size ()), float (pcmf32.size ())/WHISPER_SAMPLE_RATE,
823
846
params.n_threads , params.n_processors ,
824
847
params.language .c_str (),
825
848
params.translate ? " translate" : " transcribe" ,
849
+ params.tinydiarize ? " tdrz = 1, " : " " ,
826
850
params.no_timestamps ? 0 : 1 );
827
851
828
852
fprintf (stderr, " \n " );
@@ -853,6 +877,8 @@ int main(int argc, char ** argv) {
853
877
854
878
wparams.speed_up = params.speed_up ;
855
879
880
+ wparams.tdrz_enable = params.tinydiarize ; // [TDRZ]
881
+
856
882
wparams.initial_prompt = params.prompt .c_str ();
857
883
858
884
wparams.greedy .best_of = params.best_of ;
0 commit comments