Skip to content

Commit 7047d32

Browse files
authored
Merge pull request ggml-org#2 from bobqianic/patch
Patch
2 parents 6648641 + c8528a7 commit 7047d32

File tree

6 files changed

+108
-27
lines changed

6 files changed

+108
-27
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,19 @@ server: examples/server/server.cpp $(SRC_COMMON) $(WHISPER_OBJ)
364364
$(CXX) $(CXXFLAGS) examples/server/server.cpp $(SRC_COMMON) $(WHISPER_OBJ) -o server $(LDFLAGS)
365365

366366
stream: examples/stream/stream.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
367-
$(CXX) $(CXXFLAGS) examples/stream/stream.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o stream $(CC_SDL) $(LDFLAGS)
367+
$(CXX) $(CXXFLAGS) examples/stream/stream.cpp $(SRC_COMMON) $(SRC_CONSOLE) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o stream $(CC_SDL) $(LDFLAGS)
368368

369-
command: examples/command/command.cpp examples/grammar-parser.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
369+
command: examples/command/command.cpp examples/grammar-parser.cpp $(SRC_COMMON) $(SRC_CONSOLE) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
370370
$(CXX) $(CXXFLAGS) examples/command/command.cpp examples/grammar-parser.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o command $(CC_SDL) $(LDFLAGS)
371371

372372
lsp: examples/lsp/lsp.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
373373
$(CXX) $(CXXFLAGS) examples/lsp/lsp.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o lsp $(CC_SDL) $(LDFLAGS)
374374

375375
talk: examples/talk/talk.cpp examples/talk/gpt-2.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
376-
$(CXX) $(CXXFLAGS) examples/talk/talk.cpp examples/talk/gpt-2.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o talk $(CC_SDL) $(LDFLAGS)
376+
$(CXX) $(CXXFLAGS) examples/talk/talk.cpp examples/talk/gpt-2.cpp $(SRC_COMMON) $(SRC_CONSOLE) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o talk $(CC_SDL) $(LDFLAGS)
377377

378378
talk-llama: examples/talk-llama/talk-llama.cpp examples/talk-llama/llama.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
379-
$(CXX) $(CXXFLAGS) examples/talk-llama/talk-llama.cpp examples/talk-llama/llama.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o talk-llama $(CC_SDL) $(LDFLAGS)
379+
$(CXX) $(CXXFLAGS) examples/talk-llama/talk-llama.cpp examples/talk-llama/llama.cpp $(SRC_COMMON) $(SRC_CONSOLE) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o talk-llama $(CC_SDL) $(LDFLAGS)
380380

381381
#
382382
# Audio samples

examples/command/command.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "common-sdl.h"
1010
#include "common.h"
11+
#include "console.h"
1112
#include "whisper.h"
1213
#include "grammar-parser.h"
1314

@@ -59,9 +60,9 @@ struct whisper_params {
5960
std::string grammar;
6061
};
6162

62-
void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
63+
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);
6364

64-
bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
65+
bool whisper_params_parse(int argc, const char ** argv, whisper_params & params) {
6566
for (int i = 1; i < argc; i++) {
6667
std::string arg = argv[i];
6768

@@ -100,7 +101,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
100101
return true;
101102
}
102103

103-
void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & params) {
104+
void whisper_print_usage(int /*argc*/, const char ** argv, const whisper_params & params) {
104105
fprintf(stderr, "\n");
105106
fprintf(stderr, "usage: %s [options]\n", argv[0]);
106107
fprintf(stderr, "\n");
@@ -151,7 +152,6 @@ std::string transcribe(
151152

152153
wparams.print_progress = false;
153154
wparams.print_special = params.print_special;
154-
wparams.print_realtime = false;
155155
wparams.print_timestamps = !params.no_timestamps;
156156
wparams.translate = params.translate;
157157
wparams.no_context = true;
@@ -356,7 +356,6 @@ int process_command_list(struct whisper_context * ctx, audio_async &audio, const
356356

357357
wparams.print_progress = false;
358358
wparams.print_special = params.print_special;
359-
wparams.print_realtime = false;
360359
wparams.print_timestamps = !params.no_timestamps;
361360
wparams.translate = params.translate;
362361
wparams.no_context = true;
@@ -678,7 +677,7 @@ int process_general_transcription(struct whisper_context * ctx, audio_async & au
678677
return 0;
679678
}
680679

681-
int main(int argc, char ** argv) {
680+
int run(int argc, const char ** argv) {
682681
whisper_params params;
683682

684683
if (whisper_params_parse(argc, argv, params) == false) {
@@ -773,3 +772,23 @@ int main(int argc, char ** argv) {
773772

774773
return ret_val;
775774
}
775+
776+
#if _WIN32
777+
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
778+
console::init(true, true);
779+
atexit([]() { console::cleanup(); });
780+
std::vector<std::string> buffer(argc);
781+
std::vector<const char*> argv_UTF8(argc);
782+
for (int i = 0; i < argc; ++i) {
783+
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
784+
argv_UTF8[i] = buffer[i].c_str();
785+
}
786+
return run(argc, argv_UTF8.data());
787+
}
788+
#else
789+
int main(int argc, const char ** argv_UTF8) {
790+
console::init(true, true);
791+
atexit([]() { console::cleanup(); });
792+
return run(argc, argv_UTF8);
793+
}
794+
#endif

examples/lsp/lsp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ json unguided_transcription(struct whisper_context * ctx, audio_async &audio, js
171171
}
172172
wparams.print_progress = false;
173173
wparams.print_special = params.print_special;
174-
wparams.print_realtime = false;
175174
wparams.print_timestamps = false;
176175
wparams.translate = params.translate;
177176
wparams.no_context = jparams.value("no_context", true);
@@ -210,7 +209,6 @@ json guided_transcription(struct whisper_context * ctx, audio_async &audio, cons
210209

211210
wparams.print_progress = false;
212211
wparams.print_special = params.print_special;
213-
wparams.print_realtime = false;
214212
wparams.print_timestamps = false;
215213
wparams.translate = params.translate;
216214
wparams.no_context = true;

examples/stream/stream.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55
#include "common-sdl.h"
66
#include "common.h"
7+
#include "console.h"
78
#include "whisper.h"
89

910
#include <cassert>
@@ -56,9 +57,9 @@ struct whisper_params {
5657
std::string fname_out;
5758
};
5859

59-
void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
60+
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);
6061

61-
bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
62+
bool whisper_params_parse(int argc, const char ** argv, whisper_params & params) {
6263
for (int i = 1; i < argc; i++) {
6364
std::string arg = argv[i];
6465

@@ -97,7 +98,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
9798
return true;
9899
}
99100

100-
void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & params) {
101+
void whisper_print_usage(int /*argc*/, const char ** argv, const whisper_params & params) {
101102
fprintf(stderr, "\n");
102103
fprintf(stderr, "usage: %s [options]\n", argv[0]);
103104
fprintf(stderr, "\n");
@@ -126,7 +127,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
126127
fprintf(stderr, "\n");
127128
}
128129

129-
int main(int argc, char ** argv) {
130+
int run(int argc, const char ** argv) {
130131
whisper_params params;
131132

132133
if (whisper_params_parse(argc, argv, params) == false) {
@@ -213,7 +214,11 @@ int main(int argc, char ** argv) {
213214

214215
std::ofstream fout;
215216
if (params.fname_out.length() > 0) {
217+
#if _WIN32
218+
fout.open(console::UTF8toUTF16(params.fname_out));
219+
#else
216220
fout.open(params.fname_out);
221+
#endif
217222
if (!fout.is_open()) {
218223
fprintf(stderr, "%s: failed to open output file '%s'!\n", __func__, params.fname_out.c_str());
219224
return 1;
@@ -314,7 +319,6 @@ int main(int argc, char ** argv) {
314319

315320
wparams.print_progress = false;
316321
wparams.print_special = params.print_special;
317-
wparams.print_realtime = false;
318322
wparams.print_timestamps = !params.no_timestamps;
319323
wparams.translate = params.translate;
320324
wparams.single_segment = !use_vad;
@@ -431,3 +435,23 @@ int main(int argc, char ** argv) {
431435

432436
return 0;
433437
}
438+
439+
#if _WIN32
440+
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
441+
console::init(true, true);
442+
atexit([]() { console::cleanup(); });
443+
std::vector<std::string> buffer(argc);
444+
std::vector<const char*> argv_UTF8(argc);
445+
for (int i = 0; i < argc; ++i) {
446+
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
447+
argv_UTF8[i] = buffer[i].c_str();
448+
}
449+
return run(argc, argv_UTF8.data());
450+
}
451+
#else
452+
int main(int argc, const char ** argv_UTF8) {
453+
console::init(true, true);
454+
atexit([]() { console::cleanup(); });
455+
return run(argc, argv_UTF8);
456+
}
457+
#endif

examples/talk-llama/talk-llama.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "common-sdl.h"
55
#include "common.h"
6+
#include "console.h"
67
#include "whisper.h"
78
#include "llama.h"
89

@@ -77,9 +78,9 @@ struct whisper_params {
7778
std::string path_session = ""; // path to file for saving/loading model eval state
7879
};
7980

80-
void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
81+
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);
8182

82-
bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
83+
bool whisper_params_parse(int argc, const char ** argv, whisper_params & params) {
8384
for (int i = 1; i < argc; i++) {
8485
std::string arg = argv[i];
8586

@@ -127,7 +128,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
127128
return true;
128129
}
129130

130-
void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & params) {
131+
void whisper_print_usage(int /*argc*/, const char ** argv, const whisper_params & params) {
131132
fprintf(stderr, "\n");
132133
fprintf(stderr, "usage: %s [options]\n", argv[0]);
133134
fprintf(stderr, "\n");
@@ -180,7 +181,6 @@ std::string transcribe(
180181

181182
wparams.print_progress = false;
182183
wparams.print_special = params.print_special;
183-
wparams.print_realtime = false;
184184
wparams.print_timestamps = !params.no_timestamps;
185185
wparams.translate = params.translate;
186186
wparams.no_context = true;
@@ -247,7 +247,7 @@ The transcript only includes text, it does not include markup like HTML and Mark
247247
{1}{4} Blue
248248
{0}{4})";
249249

250-
int main(int argc, char ** argv) {
250+
int run(int argc, const char ** argv) {
251251
whisper_params params;
252252

253253
if (whisper_params_parse(argc, argv, params) == false) {
@@ -708,3 +708,23 @@ int main(int argc, char ** argv) {
708708

709709
return 0;
710710
}
711+
712+
#if _WIN32
713+
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
714+
console::init(true, true);
715+
atexit([]() { console::cleanup(); });
716+
std::vector<std::string> buffer(argc);
717+
std::vector<const char*> argv_UTF8(argc);
718+
for (int i = 0; i < argc; ++i) {
719+
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
720+
argv_UTF8[i] = buffer[i].c_str();
721+
}
722+
return run(argc, argv_UTF8.data());
723+
}
724+
#else
725+
int main(int argc, const char ** argv_UTF8) {
726+
console::init(true, true);
727+
atexit([]() { console::cleanup(); });
728+
return run(argc, argv_UTF8);
729+
}
730+
#endif

examples/talk/talk.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "common-sdl.h"
55
#include "common.h"
6+
#include "console.h"
67
#include "whisper.h"
78
#include "gpt-2.h"
89

@@ -41,9 +42,9 @@ struct whisper_params {
4142
std::string fname_out;
4243
};
4344

44-
void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
45+
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);
4546

46-
bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
47+
bool whisper_params_parse(int argc, const char ** argv, whisper_params & params) {
4748
for (int i = 1; i < argc; i++) {
4849
std::string arg = argv[i];
4950

@@ -79,7 +80,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params) {
7980
return true;
8081
}
8182

82-
void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & params) {
83+
void whisper_print_usage(int /*argc*/, const char ** argv, const whisper_params & params) {
8384
fprintf(stderr, "\n");
8485
fprintf(stderr, "usage: %s [options]\n", argv[0]);
8586
fprintf(stderr, "\n");
@@ -116,7 +117,6 @@ std::string transcribe(whisper_context * ctx, const whisper_params & params, con
116117

117118
wparams.print_progress = false;
118119
wparams.print_special = params.print_special;
119-
wparams.print_realtime = false;
120120
wparams.print_timestamps = !params.no_timestamps;
121121
wparams.translate = params.translate;
122122
wparams.no_context = true;
@@ -170,7 +170,7 @@ Here is how {0} (A) continues the dialogue:
170170
171171
A:)";
172172

173-
int main(int argc, char ** argv) {
173+
int run(int argc, const char ** argv) {
174174
whisper_params params;
175175

176176
if (whisper_params_parse(argc, argv, params) == false) {
@@ -373,3 +373,23 @@ int main(int argc, char ** argv) {
373373

374374
return 0;
375375
}
376+
377+
#if _WIN32
378+
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
379+
console::init(true, true);
380+
atexit([]() { console::cleanup(); });
381+
std::vector<std::string> buffer(argc);
382+
std::vector<const char*> argv_UTF8(argc);
383+
for (int i = 0; i < argc; ++i) {
384+
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
385+
argv_UTF8[i] = buffer[i].c_str();
386+
}
387+
return run(argc, argv_UTF8.data());
388+
}
389+
#else
390+
int main(int argc, const char ** argv_UTF8) {
391+
console::init(true, true);
392+
atexit([]() { console::cleanup(); });
393+
return run(argc, argv_UTF8);
394+
}
395+
#endif

0 commit comments

Comments
 (0)