| 17 | } |
| 18 | |
| 19 | int main(int argc, char **argv) { |
| 20 | ggml_time_init(); |
| 21 | const int64_t t_main_start_us = ggml_time_us(); |
| 22 | |
| 23 | bark_params params; |
| 24 | bark_verbosity_level verbosity = bark_verbosity_level::LOW; |
| 25 | |
| 26 | if (bark_params_parse(argc, argv, params) > 0) { |
| 27 | fprintf(stderr, "%s: Could not parse arguments\n", __func__); |
| 28 | return 1; |
| 29 | } |
| 30 | |
| 31 | std::cout << R"( _ _ )" << "\n" |
| 32 | << R"(| | | | )" << "\n" |
| 33 | << R"(| |__ __ _ _ __ | | __ ___ _ __ _ __ )" << "\n" |
| 34 | << R"(| '_ \ / _` || '__|| |/ / / __|| '_ \ | '_ \ )" << "\n" |
| 35 | << R"(| |_) || (_| || | | < _ | (__ | |_) || |_) |)" << "\n" |
| 36 | << R"(|_.__/ \__,_||_| |_|\_\(_) \___|| .__/ | .__/ )" << "\n" |
| 37 | << R"( | | | | )" << "\n" |
| 38 | << R"( |_| |_| )" << "\n"; |
| 39 | |
| 40 | // initialize bark context |
| 41 | struct bark_context_params ctx_params = bark_context_default_params(); |
| 42 | |
| 43 | ctx_params.verbosity = verbosity; |
| 44 | ctx_params.progress_callback = bark_print_progress_callback; |
| 45 | ctx_params.progress_callback_user_data = nullptr; |
| 46 | |
| 47 | struct bark_context *bctx = bark_load_model(params.model_path.c_str(), ctx_params, params.seed); |
| 48 | if (!bctx) { |
| 49 | fprintf(stderr, "%s: Could not load model\n", __func__); |
| 50 | exit(1); |
| 51 | } |
| 52 | |
| 53 | // generate audio |
| 54 | if (!bark_generate_audio(bctx, params.prompt.c_str(), params.n_threads)) { |
| 55 | fprintf(stderr, "%s: An error occured. If the problem persists, feel free to open an issue to report it.\n", __func__); |
| 56 | exit(1); |
| 57 | } |
| 58 | |
| 59 | const float *audio_data = bark_get_audio_data(bctx); |
| 60 | if (audio_data == NULL) { |
| 61 | fprintf(stderr, "%s: Could not get audio data\n", __func__); |
| 62 | exit(1); |
| 63 | } |
| 64 | |
| 65 | const int audio_arr_size = bark_get_audio_data_size(bctx); |
| 66 | |
| 67 | std::vector<float> audio_arr(audio_data, audio_data + audio_arr_size); |
| 68 | |
| 69 | write_wav_on_disk(audio_arr, params.dest_wav_path); |
| 70 | |
| 71 | // report timing |
| 72 | { |
| 73 | const int64_t t_main_end_us = ggml_time_us(); |
| 74 | const int64_t t_load_us = bark_get_load_time(bctx); |
| 75 | const int64_t t_eval_us = bark_get_eval_time(bctx); |
| 76 |
nothing calls this directly
no test coverage detected