Skip to content

Commit

Permalink
Merge pull request ggerganov#2 from bobqianic/patch
Browse files Browse the repository at this point in the history
Patch
  • Loading branch information
bobqianic committed Jan 15, 2024
2 parents 6648641 + c8528a7 commit 7047d32
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,19 @@ server: examples/server/server.cpp $(SRC_COMMON) $(WHISPER_OBJ)
$(CXX) $(CXXFLAGS) examples/server/server.cpp $(SRC_COMMON) $(WHISPER_OBJ) -o server $(LDFLAGS)

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

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

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

talk: examples/talk/talk.cpp examples/talk/gpt-2.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
$(CXX) $(CXXFLAGS) examples/talk/talk.cpp examples/talk/gpt-2.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ) -o talk $(CC_SDL) $(LDFLAGS)
$(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)

talk-llama: examples/talk-llama/talk-llama.cpp examples/talk-llama/llama.cpp $(SRC_COMMON) $(SRC_COMMON_SDL) $(WHISPER_OBJ)
$(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)
$(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)

#
# Audio samples
Expand Down
31 changes: 25 additions & 6 deletions examples/command/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "common-sdl.h"
#include "common.h"
#include "console.h"
#include "whisper.h"
#include "grammar-parser.h"

Expand Down Expand Up @@ -59,9 +60,9 @@ struct whisper_params {
std::string grammar;
};

void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);

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

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

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

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = !params.no_timestamps;
wparams.translate = params.translate;
wparams.no_context = true;
Expand Down Expand Up @@ -356,7 +356,6 @@ int process_command_list(struct whisper_context * ctx, audio_async &audio, const

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = !params.no_timestamps;
wparams.translate = params.translate;
wparams.no_context = true;
Expand Down Expand Up @@ -678,7 +677,7 @@ int process_general_transcription(struct whisper_context * ctx, audio_async & au
return 0;
}

int main(int argc, char ** argv) {
int run(int argc, const char ** argv) {
whisper_params params;

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

return ret_val;
}

#if _WIN32
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
console::init(true, true);
atexit([]() { console::cleanup(); });
std::vector<std::string> buffer(argc);
std::vector<const char*> argv_UTF8(argc);
for (int i = 0; i < argc; ++i) {
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
argv_UTF8[i] = buffer[i].c_str();
}
return run(argc, argv_UTF8.data());
}
#else
int main(int argc, const char ** argv_UTF8) {
console::init(true, true);
atexit([]() { console::cleanup(); });
return run(argc, argv_UTF8);
}
#endif
2 changes: 0 additions & 2 deletions examples/lsp/lsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ json unguided_transcription(struct whisper_context * ctx, audio_async &audio, js
}
wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = false;
wparams.translate = params.translate;
wparams.no_context = jparams.value("no_context", true);
Expand Down Expand Up @@ -210,7 +209,6 @@ json guided_transcription(struct whisper_context * ctx, audio_async &audio, cons

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = false;
wparams.translate = params.translate;
wparams.no_context = true;
Expand Down
34 changes: 29 additions & 5 deletions examples/stream/stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
#include "common-sdl.h"
#include "common.h"
#include "console.h"
#include "whisper.h"

#include <cassert>
Expand Down Expand Up @@ -56,9 +57,9 @@ struct whisper_params {
std::string fname_out;
};

void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);

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

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

void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & params) {
void whisper_print_usage(int /*argc*/, const char ** argv, const whisper_params & params) {
fprintf(stderr, "\n");
fprintf(stderr, "usage: %s [options]\n", argv[0]);
fprintf(stderr, "\n");
Expand Down Expand Up @@ -126,7 +127,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
fprintf(stderr, "\n");
}

int main(int argc, char ** argv) {
int run(int argc, const char ** argv) {
whisper_params params;

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

std::ofstream fout;
if (params.fname_out.length() > 0) {
#if _WIN32
fout.open(console::UTF8toUTF16(params.fname_out));
#else
fout.open(params.fname_out);
#endif
if (!fout.is_open()) {
fprintf(stderr, "%s: failed to open output file '%s'!\n", __func__, params.fname_out.c_str());
return 1;
Expand Down Expand Up @@ -314,7 +319,6 @@ int main(int argc, char ** argv) {

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = !params.no_timestamps;
wparams.translate = params.translate;
wparams.single_segment = !use_vad;
Expand Down Expand Up @@ -431,3 +435,23 @@ int main(int argc, char ** argv) {

return 0;
}

#if _WIN32
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
console::init(true, true);
atexit([]() { console::cleanup(); });
std::vector<std::string> buffer(argc);
std::vector<const char*> argv_UTF8(argc);
for (int i = 0; i < argc; ++i) {
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
argv_UTF8[i] = buffer[i].c_str();
}
return run(argc, argv_UTF8.data());
}
#else
int main(int argc, const char ** argv_UTF8) {
console::init(true, true);
atexit([]() { console::cleanup(); });
return run(argc, argv_UTF8);
}
#endif
30 changes: 25 additions & 5 deletions examples/talk-llama/talk-llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "common-sdl.h"
#include "common.h"
#include "console.h"
#include "whisper.h"
#include "llama.h"

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

void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);

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

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

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

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = !params.no_timestamps;
wparams.translate = params.translate;
wparams.no_context = true;
Expand Down Expand Up @@ -247,7 +247,7 @@ The transcript only includes text, it does not include markup like HTML and Mark
{1}{4} Blue
{0}{4})";

int main(int argc, char ** argv) {
int run(int argc, const char ** argv) {
whisper_params params;

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

return 0;
}

#if _WIN32
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
console::init(true, true);
atexit([]() { console::cleanup(); });
std::vector<std::string> buffer(argc);
std::vector<const char*> argv_UTF8(argc);
for (int i = 0; i < argc; ++i) {
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
argv_UTF8[i] = buffer[i].c_str();
}
return run(argc, argv_UTF8.data());
}
#else
int main(int argc, const char ** argv_UTF8) {
console::init(true, true);
atexit([]() { console::cleanup(); });
return run(argc, argv_UTF8);
}
#endif
30 changes: 25 additions & 5 deletions examples/talk/talk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "common-sdl.h"
#include "common.h"
#include "console.h"
#include "whisper.h"
#include "gpt-2.h"

Expand Down Expand Up @@ -41,9 +42,9 @@ struct whisper_params {
std::string fname_out;
};

void whisper_print_usage(int argc, char ** argv, const whisper_params & params);
void whisper_print_usage(int argc, const char ** argv, const whisper_params & params);

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

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

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

wparams.print_progress = false;
wparams.print_special = params.print_special;
wparams.print_realtime = false;
wparams.print_timestamps = !params.no_timestamps;
wparams.translate = params.translate;
wparams.no_context = true;
Expand Down Expand Up @@ -170,7 +170,7 @@ Here is how {0} (A) continues the dialogue:
A:)";

int main(int argc, char ** argv) {
int run(int argc, const char ** argv) {
whisper_params params;

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

return 0;
}

#if _WIN32
int wmain(int argc, const wchar_t ** argv_UTF16LE) {
console::init(true, true);
atexit([]() { console::cleanup(); });
std::vector<std::string> buffer(argc);
std::vector<const char*> argv_UTF8(argc);
for (int i = 0; i < argc; ++i) {
buffer[i] = console::UTF16toUTF8(argv_UTF16LE[i]);
argv_UTF8[i] = buffer[i].c_str();
}
return run(argc, argv_UTF8.data());
}
#else
int main(int argc, const char ** argv_UTF8) {
console::init(true, true);
atexit([]() { console::cleanup(); });
return run(argc, argv_UTF8);
}
#endif

0 comments on commit 7047d32

Please sign in to comment.