From 878a84d78f42474e9a1d66b2db163f4729f5bd5a Mon Sep 17 00:00:00 2001 From: Syahmi Azhar Date: Sun, 1 Jan 2023 20:37:42 +0800 Subject: [PATCH] whisper : rename whisper_init to whisper_init_from_file --- bindings/go/whisper.go | 2 +- bindings/javascript/emscripten.cpp | 2 +- examples/bench.wasm/emscripten.cpp | 2 +- examples/bench/bench.cpp | 2 +- examples/command.wasm/emscripten.cpp | 2 +- examples/command/command.cpp | 2 +- examples/main/main.cpp | 2 +- examples/stream.wasm/emscripten.cpp | 2 +- examples/stream/stream.cpp | 2 +- examples/talk.wasm/emscripten.cpp | 2 +- examples/talk/talk.cpp | 2 +- examples/whisper.android/app/src/main/jni/whisper/jni.c | 2 +- examples/whisper.objc/whisper.objc/ViewController.m | 2 +- examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift | 2 +- examples/whisper.wasm/emscripten.cpp | 2 +- whisper.cpp | 6 +++--- whisper.h | 6 +++--- 17 files changed, 21 insertions(+), 21 deletions(-) diff --git a/bindings/go/whisper.go b/bindings/go/whisper.go index 9381879..8d12fed 100644 --- a/bindings/go/whisper.go +++ b/bindings/go/whisper.go @@ -91,7 +91,7 @@ var ( func Whisper_init(path string) *Context { cPath := C.CString(path) defer C.free(unsafe.Pointer(cPath)) - if ctx := C.whisper_init(cPath); ctx != nil { + if ctx := C.whisper_init_from_file(cPath); ctx != nil { return (*Context)(ctx) } else { return nil diff --git a/bindings/javascript/emscripten.cpp b/bindings/javascript/emscripten.cpp index bda9630..789ad8b 100644 --- a/bindings/javascript/emscripten.cpp +++ b/bindings/javascript/emscripten.cpp @@ -20,7 +20,7 @@ struct whisper_context * g_context; EMSCRIPTEN_BINDINGS(whisper) { emscripten::function("init", emscripten::optional_override([](const std::string & path_model) { if (g_context == nullptr) { - g_context = whisper_init(path_model.c_str()); + g_context = whisper_init_from_file(path_model.c_str()); if (g_context != nullptr) { return true; } else { diff --git a/examples/bench.wasm/emscripten.cpp b/examples/bench.wasm/emscripten.cpp index 2e63315..9594147 100644 --- a/examples/bench.wasm/emscripten.cpp +++ b/examples/bench.wasm/emscripten.cpp @@ -52,7 +52,7 @@ EMSCRIPTEN_BINDINGS(bench) { emscripten::function("init", emscripten::optional_override([](const std::string & path_model) { for (size_t i = 0; i < g_contexts.size(); ++i) { if (g_contexts[i] == nullptr) { - g_contexts[i] = whisper_init(path_model.c_str()); + g_contexts[i] = whisper_init_from_file(path_model.c_str()); if (g_contexts[i] != nullptr) { if (g_worker.joinable()) { g_worker.join(); diff --git a/examples/bench/bench.cpp b/examples/bench/bench.cpp index 3ab5077..2fd2423 100644 --- a/examples/bench/bench.cpp +++ b/examples/bench/bench.cpp @@ -53,7 +53,7 @@ int main(int argc, char ** argv) { // whisper init - struct whisper_context * ctx = whisper_init(params.model.c_str()); + struct whisper_context * ctx = whisper_init_from_file(params.model.c_str()); { fprintf(stderr, "\n"); diff --git a/examples/command.wasm/emscripten.cpp b/examples/command.wasm/emscripten.cpp index d4bbb21..f2ba81e 100644 --- a/examples/command.wasm/emscripten.cpp +++ b/examples/command.wasm/emscripten.cpp @@ -324,7 +324,7 @@ EMSCRIPTEN_BINDINGS(command) { emscripten::function("init", emscripten::optional_override([](const std::string & path_model) { for (size_t i = 0; i < g_contexts.size(); ++i) { if (g_contexts[i] == nullptr) { - g_contexts[i] = whisper_init(path_model.c_str()); + g_contexts[i] = whisper_init_from_file(path_model.c_str()); if (g_contexts[i] != nullptr) { g_running = true; if (g_worker.joinable()) { diff --git a/examples/command/command.cpp b/examples/command/command.cpp index 4558a67..3dae3a5 100644 --- a/examples/command/command.cpp +++ b/examples/command/command.cpp @@ -931,7 +931,7 @@ int main(int argc, char ** argv) { // whisper init - struct whisper_context * ctx = whisper_init(params.model.c_str()); + struct whisper_context * ctx = whisper_init_from_file(params.model.c_str()); // print some info about the processing { diff --git a/examples/main/main.cpp b/examples/main/main.cpp index d387a77..48e0292 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -478,7 +478,7 @@ int main(int argc, char ** argv) { // whisper init - struct whisper_context * ctx = whisper_init(params.model.c_str()); + struct whisper_context * ctx = whisper_init_from_file(params.model.c_str()); if (ctx == nullptr) { fprintf(stderr, "error: failed to initialize whisper context\n"); diff --git a/examples/stream.wasm/emscripten.cpp b/examples/stream.wasm/emscripten.cpp index b75eee3..e4cdf63 100644 --- a/examples/stream.wasm/emscripten.cpp +++ b/examples/stream.wasm/emscripten.cpp @@ -129,7 +129,7 @@ EMSCRIPTEN_BINDINGS(stream) { emscripten::function("init", emscripten::optional_override([](const std::string & path_model) { for (size_t i = 0; i < g_contexts.size(); ++i) { if (g_contexts[i] == nullptr) { - g_contexts[i] = whisper_init(path_model.c_str()); + g_contexts[i] = whisper_init_from_file(path_model.c_str()); if (g_contexts[i] != nullptr) { g_running = true; if (g_worker.joinable()) { diff --git a/examples/stream/stream.cpp b/examples/stream/stream.cpp index 9caa614..c7aa871 100644 --- a/examples/stream/stream.cpp +++ b/examples/stream/stream.cpp @@ -456,7 +456,7 @@ int main(int argc, char ** argv) { exit(0); } - struct whisper_context * ctx = whisper_init(params.model.c_str()); + struct whisper_context * ctx = whisper_init_from_file(params.model.c_str()); std::vector pcmf32 (n_samples_30s, 0.0f); std::vector pcmf32_old(n_samples_30s, 0.0f); diff --git a/examples/talk.wasm/emscripten.cpp b/examples/talk.wasm/emscripten.cpp index c82f469..1ea9702 100644 --- a/examples/talk.wasm/emscripten.cpp +++ b/examples/talk.wasm/emscripten.cpp @@ -271,7 +271,7 @@ EMSCRIPTEN_BINDINGS(talk) { emscripten::function("init", emscripten::optional_override([](const std::string & path_model) { for (size_t i = 0; i < g_contexts.size(); ++i) { if (g_contexts[i] == nullptr) { - g_contexts[i] = whisper_init(path_model.c_str()); + g_contexts[i] = whisper_init_from_file(path_model.c_str()); if (g_contexts[i] != nullptr) { g_running = true; if (g_worker.joinable()) { diff --git a/examples/talk/talk.cpp b/examples/talk/talk.cpp index ec57a95..55cd46a 100644 --- a/examples/talk/talk.cpp +++ b/examples/talk/talk.cpp @@ -498,7 +498,7 @@ int main(int argc, char ** argv) { // whisper init - struct whisper_context * ctx_wsp = whisper_init(params.model_wsp.c_str()); + struct whisper_context * ctx_wsp = whisper_init_from_file(params.model_wsp.c_str()); // gpt init diff --git a/examples/whisper.android/app/src/main/jni/whisper/jni.c b/examples/whisper.android/app/src/main/jni/whisper/jni.c index e3fe695..0992943 100644 --- a/examples/whisper.android/app/src/main/jni/whisper/jni.c +++ b/examples/whisper.android/app/src/main/jni/whisper/jni.c @@ -23,7 +23,7 @@ Java_com_whispercppdemo_whisper_WhisperLib_00024Companion_initContext( UNUSED(thiz); struct whisper_context *context = NULL; const char *model_path_chars = (*env)->GetStringUTFChars(env, model_path_str, NULL); - context = whisper_init(model_path_chars); + context = whisper_init_from_file(model_path_chars); (*env)->ReleaseStringUTFChars(env, model_path_str, model_path_chars); return (jlong) context; } diff --git a/examples/whisper.objc/whisper.objc/ViewController.m b/examples/whisper.objc/whisper.objc/ViewController.m index d6aef36..8a1e876 100644 --- a/examples/whisper.objc/whisper.objc/ViewController.m +++ b/examples/whisper.objc/whisper.objc/ViewController.m @@ -61,7 +61,7 @@ void AudioInputCallback(void * inUserData, NSLog(@"Loading model from %@", modelPath); // create ggml context - stateInp.ctx = whisper_init([modelPath UTF8String]); + stateInp.ctx = whisper_init_from_file([modelPath UTF8String]); // check if the model was loaded successfully if (stateInp.ctx == NULL) { diff --git a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift index 9adfb42..e9645b3 100644 --- a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift +++ b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift @@ -55,7 +55,7 @@ actor WhisperContext { } static func createContext(path: String) throws -> WhisperContext { - let context = whisper_init(path) + let context = whisper_init_from_file(path) if let context { return WhisperContext(context: context) } else { diff --git a/examples/whisper.wasm/emscripten.cpp b/examples/whisper.wasm/emscripten.cpp index 33ae0a1..f92d814 100644 --- a/examples/whisper.wasm/emscripten.cpp +++ b/examples/whisper.wasm/emscripten.cpp @@ -18,7 +18,7 @@ EMSCRIPTEN_BINDINGS(whisper) { for (size_t i = 0; i < g_contexts.size(); ++i) { if (g_contexts[i] == nullptr) { - g_contexts[i] = whisper_init(path_model.c_str()); + g_contexts[i] = whisper_init_from_file(path_model.c_str()); if (g_contexts[i] != nullptr) { return i + 1; } else { diff --git a/whisper.cpp b/whisper.cpp index 62c40de..f7ddfe3 100644 --- a/whisper.cpp +++ b/whisper.cpp @@ -2232,7 +2232,7 @@ static std::vector tokenize(const whisper_vocab & vocab, cons // interface implementation // -struct whisper_context * whisper_init(const char * path_model) { +struct whisper_context * whisper_init_from_file(const char * path_model) { whisper_model_loader loader; fprintf(stderr, "%s: loading model from '%s'\n", __func__, path_model); @@ -2260,10 +2260,10 @@ struct whisper_context * whisper_init(const char * path_model) { fin->close(); }; - return whisper_init_loader(&loader); + return whisper_init(&loader); } -struct whisper_context * whisper_init_loader(struct whisper_model_loader * loader) { +struct whisper_context * whisper_init(struct whisper_model_loader * loader) { ggml_time_init(); whisper_context * ctx = new whisper_context; diff --git a/whisper.h b/whisper.h index 0fa936b..0d9c1cc 100644 --- a/whisper.h +++ b/whisper.h @@ -40,7 +40,7 @@ extern "C" { // // ... // - // struct whisper_context * ctx = whisper_init("/path/to/ggml-base.en.bin"); + // struct whisper_context * ctx = whisper_init_from_file("/path/to/ggml-base.en.bin"); // // if (whisper_full(ctx, wparams, pcmf32.data(), pcmf32.size()) != 0) { // fprintf(stderr, "failed to process audio\n"); @@ -94,8 +94,8 @@ extern "C" { // Allocates all memory needed for the model and loads the model from the given file. // Returns NULL on failure. - WHISPER_API struct whisper_context * whisper_init(const char * path_model); - WHISPER_API struct whisper_context * whisper_init_loader(struct whisper_model_loader * loader); + WHISPER_API struct whisper_context * whisper_init_from_file(const char * path_model); + WHISPER_API struct whisper_context * whisper_init(struct whisper_model_loader * loader); // Frees all memory allocated by the model. WHISPER_API void whisper_free(struct whisper_context * ctx);