ITADN
PABannier/bark.cpp
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

bark.cpp

bark.cpp

Actions Status License: MIT

Roadmap / encodec.cpp / ggml

纯 C/C++ 中 SunoAI 的 bark 模型 的推理。

描述

借助 bark.cpp,我们的目标是为社区带来实时、逼真的多语言文本转语音生成。

  • 无依赖的纯 C/C++ 实现
  • 支持 x86 架构的 AVX、AVX2 和 AVX512
  • 兼容 CPU 和 GPU 的后端
  • 混合 F16 / F32 精度
  • 4 位、5 位和 8 位整数量化
  • Metal 和 CUDA 后端

支持的模型

我们希望实现的模型!请提交 PR :)

Google Colab 上的演示 (#95)


以下是使用 bark.cpp 的典型运行示例:

./main -p "This is an audio generated by bark.cpp"

   __               __
   / /_  ____ ______/ /__        _________  ____
  / __ \/ __ `/ ___/ //_/       / ___/ __ \/ __ \
 / /_/ / /_/ / /  / ,<    _    / /__/ /_/ / /_/ /
/_.___/\__,_/_/  /_/|_|  (_)   \___/ .___/ .___/
                                  /_/   /_/

bark_tokenize_input: prompt: 'This is an audio generated by bark.cpp'
bark_tokenize_input: number of tokens in prompt = 513, first 8 tokens: 20795 20172 20199 33733 58966 20203 28169 20222

Generating semantic tokens: 17%

bark_print_statistics:   sample time =    10.98 ms / 138 tokens
bark_print_statistics:  predict time =   614.96 ms / 4.46 ms per token
bark_print_statistics:    total time =   633.54 ms

Generating coarse tokens: 100%

bark_print_statistics:   sample time =     3.75 ms / 410 tokens
bark_print_statistics:  predict time =  3263.17 ms / 7.96 ms per token
bark_print_statistics:    total time =  3274.00 ms

Generating fine tokens: 100%

bark_print_statistics:   sample time =    38.82 ms / 6144 tokens
bark_print_statistics:  predict time =  4729.86 ms / 0.77 ms per token
bark_print_statistics:    total time =  4772.92 ms

write_wav_on_disk: Number of frames written = 65600.

main:     load time =   324.14 ms
main:     eval time =  8806.57 ms
main:    total time =  9131.68 ms

这是 Bark 在 iPhone 上运行的视频:

https://github.com/PABannier/bark.cpp/assets/12958149/bc807c0b-adfa-4c47-a05b-a2d8ba157dd8

用法

以下是使用 Bark.cpp 的步骤

获取代码

git clone --recursive https://github.com/PABannier/bark.cpp.git
cd bark.cpp
git submodule update --init --recursive

构建

要构建 bark.cpp,你必须使用 CMake

mkdir build
cd build
# To enable nvidia gpu, use the following option
# cmake -DGGML_CUBLAS=ON ..
cmake ..
cmake --build . --config Release

准备数据 & 运行

# Install Python dependencies
python3 -m pip install -r requirements.txt

# Download the Bark checkpoints and vocabulary
python3 download_weights.py --out-dir ./models --models bark-small bark

# Convert the model to ggml format
python3 convert.py --dir-model ./models/bark-small --use-f16

# run the inference
./build/examples/main/main -m ./models/bark-small/ggml_weights.bin -p "this is an audio generated by bark.cpp" -t 4

(可选)量化权重

可以使用以下策略对权重进行量化:q4_0, q4_1, q5_0, q5_1, q8_0

请注意,为了保持音频质量,我们不对编解码器模型进行量化。大部分计算量在于 GPT 模型的前向传播中。

./build/examples/quantize/quantize ./ggml_weights.bin ./ggml_weights_q4.bin q4_0

奠基性论文

贡献

bark.cpp 是一项持续的事业,其存续与演进依赖于社区的努力。欢迎你的贡献,且极具价值。它可以是

  • bug 报告:你在使用 bark.cpp 时可能会遇到 bug。请毫不犹豫地在 issue 部分报告它。
  • 功能请求:你想添加一个新模型或支持一个新平台。你可以使用 issue 部分提出建议。
  • pull request:你可能修复了一个 bug,添加了一个功能,甚至修复了文档中的一个小拼写错误,……你可以提交一个 pull request,审核人员会联系你。

编码指南

  • 避免添加第三方依赖、额外文件、额外头文件等。
  • 始终考虑与其他操作系统和架构的交叉兼容性