From 00ddb10fe256fd23c502ddf00c24a09d202e0562 Mon Sep 17 00:00:00 2001
From: Judd <foldl@boxvest.com>
Date: Wed, 19 Feb 2025 16:40:51 +0800
Subject: [PATCH] select utf8 codepage on windows

---
 examples/command/command.cpp       | 9 +++++++++
 examples/stream/stream.cpp         | 9 +++++++++
 examples/talk-llama/talk-llama.cpp | 9 +++++++++
 3 files changed, 27 insertions(+)

diff --git a/examples/command/command.cpp b/examples/command/command.cpp
index 49f40342..49f8f755 100644
--- a/examples/command/command.cpp
+++ b/examples/command/command.cpp
@@ -23,6 +23,11 @@
 #include <map>
 #include <chrono>
 
+#if defined(_WIN32)
+#define NOMINMAX
+#include <windows.h>
+#endif
+
 // command-line parameters
 struct whisper_params {
     int32_t n_threads  = std::min(4, (int32_t) std::thread::hardware_concurrency());
@@ -680,6 +685,10 @@ static int process_general_transcription(struct whisper_context * ctx, audio_asy
 }
 
 int main(int argc, char ** argv) {
+#if defined(_WIN32)
+    SetConsoleOutputCP(CP_UTF8);
+#endif
+
     whisper_params params;
 
     if (whisper_params_parse(argc, argv, params) == false) {
diff --git a/examples/stream/stream.cpp b/examples/stream/stream.cpp
index 5f7387f7..bd7e05c1 100644
--- a/examples/stream/stream.cpp
+++ b/examples/stream/stream.cpp
@@ -14,6 +14,11 @@
 #include <fstream>
 #include <chrono>
 
+#if defined(_WIN32)
+#define NOMINMAX
+#include <windows.h>
+#endif
+
 // command-line parameters
 struct whisper_params {
     int32_t n_threads  = std::min(4, (int32_t) std::thread::hardware_concurrency());
@@ -113,6 +118,10 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
 }
 
 int main(int argc, char ** argv) {
+#if defined(_WIN32)
+    SetConsoleOutputCP(CP_UTF8);
+#endif
+
     whisper_params params;
 
     if (whisper_params_parse(argc, argv, params) == false) {
diff --git a/examples/talk-llama/talk-llama.cpp b/examples/talk-llama/talk-llama.cpp
index 51658700..d40667bb 100644
--- a/examples/talk-llama/talk-llama.cpp
+++ b/examples/talk-llama/talk-llama.cpp
@@ -17,6 +17,11 @@
 #include <sstream>
 #include <chrono>
 
+#if defined(_WIN32)
+#define NOMINMAX
+#include <windows.h>
+#endif
+
 static std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::string & text, bool add_bos) {
     const llama_model * model = llama_get_model(ctx);
     const llama_vocab * vocab = llama_model_get_vocab(model);
@@ -273,6 +278,10 @@ The transcript only includes text, it does not include markup like HTML and Mark
 {0}{4})";
 
 int main(int argc, char ** argv) {
+#if defined(_WIN32)
+    SetConsoleOutputCP(CP_UTF8);
+#endif
+
     whisper_params params;
 
     if (whisper_params_parse(argc, argv, params) == false) {