yum-archive/TaSTT-Whisper
High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model
git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper
8c4603c
master
1#include "params.h" 2#include <algorithm> 3#include <thread> 4#include "miscUtils.h" 5 6whisper_params::whisper_params () 7{ 8#ifdef _DEBUG 9n_threads = 2 ; 10#else 11n_threads = std::min (4u , std::thread::hardware_concurrency () ); 12#endif 13} 14 15namespace 16{ 17const char * cstr (bool b ) 18 { 19return b ?"true" :"false" ; 20 } 21} 22 23void whisper_print_usage (int argc ,wchar_t ** argv ,const whisper_params & params ) 24{ 25fprintf (stderr ,"\n" ); 26fprintf (stderr ,"usage: %S [options] file0.wav file1.wav ...\n" ,argv [0 ] ); 27fprintf (stderr ,"\n" ); 28fprintf (stderr ,"options:\n" ); 29fprintf (stderr ," -h, --help [default] show this help message and exit\n" ); 30fprintf (stderr ," -t N, --threads N [%-7d] number of threads to use during computation\n" ,params .n_threads ); 31fprintf (stderr ," -p N, --processors N [%-7d] number of processors to use during computation\n" ,params .n_processors ); 32fprintf (stderr ," -ot N, --offset-t N [%-7d] time offset in milliseconds\n" ,params .offset_t_ms ); 33fprintf (stderr ," -on N, --offset-n N [%-7d] segment index offset\n" ,params .offset_n ); 34fprintf (stderr ," -d N, --duration N [%-7d] duration of audio to process in milliseconds\n" ,params .duration_ms ); 35fprintf (stderr ," -mc N, --max-context N [%-7d] maximum number of text context tokens to store\n" ,params .max_context ); 36fprintf (stderr ," -ml N, --max-len N [%-7d] maximum segment length in characters\n" ,params .max_len ); 37fprintf (stderr ," -wt N, --word-thold N [%-7.2f] word timestamp probability threshold\n" ,params .word_thold ); 38fprintf (stderr ," -su, --speed-up [%-7s] speed up audio by x2 (reduced accuracy)\n" ,cstr (params .speed_up ) ); 39fprintf (stderr ," -tr, --translate [%-7s] translate from source language to english\n" ,cstr (params .translate ) ); 40fprintf (stderr ," -di, --diarize [%-7s] stereo audio diarization\n" ,cstr (params .diarize ) ); 41fprintf (stderr ," -otxt, --output-txt [%-7s] output result in a text file\n" ,cstr (params .output_txt ) ); 42fprintf (stderr ," -ovtt, --output-vtt [%-7s] output result in a vtt file\n" ,cstr (params .output_vtt ) ); 43fprintf (stderr ," -osrt, --output-srt [%-7s] output result in a srt file\n" ,cstr (params .output_srt ) ); 44fprintf (stderr ," -owts, --output-words [%-7s] output script for generating karaoke video\n" ,cstr (params .output_wts ) ); 45fprintf (stderr ," -ps, --print-special [%-7s] print special tokens\n" ,cstr (params .print_special ) ); 46fprintf (stderr ," -nc, --no-colors [%-7s] do not print colors\n" ,cstr ( !params .print_colors ) ); 47fprintf (stderr ," -nt, --no-timestamps [%-7s] do not print timestamps\n" ,cstr (params .no_timestamps ) ); 48fprintf (stderr ," -l LANG, --language LANG [%-7s] spoken language\n" ,params .language .c_str () ); 49fprintf (stderr ," -m FNAME, --model FNAME [%-7S] model path\n" ,params .model .c_str () ); 50fprintf (stderr ," -f FNAME, --file FNAME [%-7s] path of the input audio file\n" ,"" ); 51fprintf (stderr ,"\n" ); 52} 53 54bool whisper_params::parse (int argc ,wchar_t * argv [] ) 55{ 56for (int i = 1 ;i < argc ;i ++ ) 57 { 58 std::wstring arg = argv [i ]; 59 60if (arg [0 ]!= '-' ) 61 { 62fname_inp .push_back (arg ); 63continue ; 64 } 65 66if (arg == L"-h" || arg == L"--help" ) 67 { 68whisper_print_usage (argc ,argv ,* this ); 69return false; 70 } 71 72else if (arg == L"-t" || arg == L"--threads" ) {n_threads = std::stoul (argv [++ i ] ); } 73else if (arg == L"-p" || arg == L"--processors" ) {n_processors = std::stoul (argv [++ i ] ); } 74else if (arg == L"-ot" || arg == L"--offset-t" ) {offset_t_ms = std::stoul (argv [++ i ] ); } 75else if (arg == L"-on" || arg == L"--offset-n" ) {offset_n = std::stoul (argv [++ i ] ); } 76else if (arg == L"-d" || arg == L"--duration" ) {duration_ms = std::stoul (argv [++ i ] ); } 77else if (arg == L"-mc" || arg == L"--max-context" ) {max_context = std::stoul (argv [++ i ] ); } 78else if (arg == L"-ml" || arg == L"--max-len" ) {max_len = std::stoul (argv [++ i ] ); } 79else if (arg == L"-wt" || arg == L"--word-thold" ) {word_thold = std::stof (argv [++ i ] ); } 80else if (arg == L"-su" || arg == L"--speed-up" ) {speed_up = true; } 81else if (arg == L"-tr" || arg == L"--translate" ) {translate = true; } 82else if (arg == L"-di" || arg == L"--diarize" ) {diarize = true; } 83else if (arg == L"-otxt" || arg == L"--output-txt" ) {output_txt = true; } 84else if (arg == L"-ovtt" || arg == L"--output-vtt" ) {output_vtt = true; } 85else if (arg == L"-osrt" || arg == L"--output-srt" ) {output_srt = true; } 86else if (arg == L"-owts" || arg == L"--output-words" ) {output_wts = true; } 87else if (arg == L"-ps" || arg == L"--print-special" ) {print_special = true; } 88else if (arg == L"-nc" || arg == L"--no-colors" ) {print_colors = false; } 89else if (arg == L"-nt" || arg == L"--no-timestamps" ) {no_timestamps = true; } 90else if (arg == L"-l" || arg == L"--language" ) {language = utf8 (argv [++ i ] ); } 91else if (arg == L"-m" || arg == L"--model" ) {model = argv [++ i ]; } 92else if (arg == L"-f" || arg == L"--file" ) {fname_inp .push_back (argv [++ i ] ); } 93else 94 { 95fprintf (stderr ,"error: unknown argument: %S\n" ,arg .c_str () ); 96whisper_print_usage (argc ,argv ,* this ); 97return false; 98 } 99 } 100return true; 101}