MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / EMSCRIPTEN_BINDINGS

Function EMSCRIPTEN_BINDINGS

examples/wasm/emscripten.cpp:13–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11std::vector<struct bark_context *> g_contexts(4, nullptr);
12
13EMSCRIPTEN_BINDINGS(bark) {
14 emscripten::function("init", emscripten::optional_override([](const std::string &path_model) {
15 if (g_worker.joinable()) {
16 g_worker.join();
17 }
18
19 for (size_t i = 0; i < g_contexts.size(); i++) {
20 if (g_contexts[i] == nullptr) {
21 bark_verbosity_level verbosity = bark_verbosity_level::LOW;
22 bark_context_params ctx_params = bark_context_default_params();
23 ctx_params.verbosity = verbosity;
24 g_contexts[i] = bark_load_model(path_model.c_str(), ctx_params, 0 /* seed */);
25 if (g_contexts[i] != nullptr) {
26 return i + 1;
27 } else {
28 return (size_t)0;
29 }
30 }
31 }
32
33 return (size_t)0;
34 }));
35
36 emscripten::function("free", emscripten::optional_override([](size_t index) {
37 if (g_worker.joinable()) {
38 g_worker.join();
39 }
40
41 --index;
42
43 if (index < g_contexts.size()) {
44 bark_free(g_contexts[index]);
45 g_contexts[index] = nullptr;
46 }
47 }));
48
49 emscripten::function("generate", emscripten::optional_override([](size_t index, const std::string &prompt, int n_threads) {
50 if (g_worker.joinable()) {
51 g_worker.join();
52 }
53
54 --index;
55
56 if (index >= g_contexts.size()) {
57 return -1;
58 }
59
60 if (g_contexts[index] == nullptr) {
61 return -2;
62 }
63
64 // print system information
65 {
66 printf("system_info: n_threads = %d / %d \n",
67 n_threads, std::thread::hardware_concurrency());
68
69 printf("\n");
70 }

Callers

nothing calls this directly

Calls 10

nullFunction · 0.85
bark_load_modelFunction · 0.50
bark_freeFunction · 0.50
bark_generate_audioFunction · 0.50
bark_get_load_timeFunction · 0.50
bark_get_eval_timeFunction · 0.50
bark_get_audio_dataFunction · 0.50
bark_get_audio_data_sizeFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected