suno-ai / bark

๐Ÿ”Š Text-Prompted Generative Audio Model
MIT License
35.53k stars 4.18k forks source link

Notice: Bark is Suno's open-source text-to-speech+ model. If you are looking for our text-to-music models, please visit us on our web page and join our community on Discord.

๐Ÿถ Bark

Twitter

๐Ÿ”— Examples โ€ข Suno Studio Waitlist โ€ข Updates โ€ข How to Use โ€ข Installation โ€ข FAQ



Bark is a transformer-based text-to-audio model created by Suno. Bark can generate highly realistic, multilingual speech as well as other audio - including music, background noise and simple sound effects. The model can also produce nonverbal communications like laughing, sighing and crying. To support the research community, we are providing access to pretrained model checkpoints, which are ready for inference and available for commercial use.

โš  Disclaimer

Bark was developed for research purposes. It is not a conventional text-to-speech model but instead a fully generative text-to-audio model, which can deviate in unexpected ways from provided prompts. Suno does not take responsibility for any output generated. Use at your own risk, and please act responsibly.

๐Ÿ“– Quick Index

๐ŸŽง Demos

Open in Spaces Open on Replicate Open In Colab

๐Ÿš€ Updates

2023.05.01

2023.04.20

๐Ÿ Usage in Python

๐Ÿช‘ Basics

```python from bark import SAMPLE_RATE, generate_audio, preload_models from scipy.io.wavfile import write as write_wav from IPython.display import Audio # download and load all models preload_models() # generate audio from text text_prompt = """ Hello, my name is Suno. And, uh โ€” and I like pizza. [laughs] But I also have other interests such as playing tic tac toe. """ audio_array = generate_audio(text_prompt) # save audio to disk write_wav("bark_generation.wav", SAMPLE_RATE, audio_array) # play text in notebook Audio(audio_array, rate=SAMPLE_RATE) ``` [pizza1.webm](https://user-images.githubusercontent.com/34592747/cfa98e54-721c-4b9c-b962-688e09db684f.webm)

๐ŸŒŽ Foreign Language


Bark supports various languages out-of-the-box and automatically determines language from input text. When prompted with code-switched text, Bark will attempt to employ the native accent for the respective languages. English quality is best for the time being, and we expect other languages to further improve with scaling.

```python text_prompt = """ ์ถ”์„์€ ๋‚ด๊ฐ€ ๊ฐ€์žฅ ์ข‹์•„ํ•˜๋Š” ๋ช…์ ˆ์ด๋‹ค. ๋‚˜๋Š” ๋ฉฐ์น  ๋™์•ˆ ํœด์‹์„ ์ทจํ•˜๊ณ  ์นœ๊ตฌ ๋ฐ ๊ฐ€์กฑ๊ณผ ์‹œ๊ฐ„์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. """ audio_array = generate_audio(text_prompt) ``` [suno_korean.webm](https://user-images.githubusercontent.com/32879321/235313033-dc4477b9-2da0-4b94-9c8b-a8c2d8f5bb5e.webm) *Note: since Bark recognizes languages automatically from input text, it is possible to use, for example, a german history prompt with english text. This usually leads to english audio with a german accent.* ```python text_prompt = """ Der DreiรŸigjรคhrige Krieg (1618-1648) war ein verheerender Konflikt, der Europa stark geprรคgt hat. This is a beginning of the history. If you want to hear more, please continue. """ audio_array = generate_audio(text_prompt) ``` [suno_german_accent.webm](https://user-images.githubusercontent.com/34592747/3f96ab3e-02ec-49cb-97a6-cf5af0b3524a.webm)

๐ŸŽถ Music

Bark can generate all types of audio, and, in principle, doesn't see a difference between speech and music. Sometimes Bark chooses to generate text as music, but you can help it out by adding music notes around your lyrics.

```python text_prompt = """ โ™ช In the jungle, the mighty jungle, the lion barks tonight โ™ช """ audio_array = generate_audio(text_prompt) ``` [lion.webm](https://user-images.githubusercontent.com/5068315/230684766-97f5ea23-ad99-473c-924b-66b6fab24289.webm)

๐ŸŽค Voice Presets

Bark supports 100+ speaker presets across [supported languages](#supported-languages). You can browse the library of supported voice presets [HERE](https://suno-ai.notion.site/8b8e8749ed514b0cbf3f699013548683?v=bc67cff786b04b50b3ceb756fd05f68c), or in the [code](bark/assets/prompts). The community also often shares presets in [Discord](https://discord.gg/J2B2vsjKuE). > Bark tries to match the tone, pitch, emotion and prosody of a given preset, but does not currently support custom voice cloning. The model also attempts to preserve music, ambient noise, etc. ```python text_prompt = """ I have a silky smooth voice, and today I will tell you about the exercise regimen of the common sloth. """ audio_array = generate_audio(text_prompt, history_prompt="v2/en_speaker_1") ``` [sloth.webm](https://user-images.githubusercontent.com/5068315/230684883-a344c619-a560-4ff5-8b99-b4463a34487b.webm)

๐Ÿ“ƒ Generating Longer Audio

By default, generate_audio works well with around 13 seconds of spoken text. For an example of how to do long-form generation, see ๐Ÿ‘‰ Notebook ๐Ÿ‘ˆ

Click to toggle example long-form generations (from the example notebook) [dialog.webm](https://user-images.githubusercontent.com/2565833/235463539-f57608da-e4cb-4062-8771-148e29512b01.webm) [longform_advanced.webm](https://user-images.githubusercontent.com/2565833/235463547-1c0d8744-269b-43fe-9630-897ea5731652.webm) [longform_basic.webm](https://user-images.githubusercontent.com/2565833/235463559-87efe9f8-a2db-4d59-b764-57db83f95270.webm)

Command line

python -m bark --text "Hello, my name is Suno." --output_filename "example.wav"

๐Ÿ’ป Installation

โ€ผ๏ธ CAUTION โ€ผ๏ธ Do NOT use pip install bark. It installs a different package, which is not managed by Suno.

pip install git+https://github.com/suno-ai/bark.git

or

git clone https://github.com/suno-ai/bark
cd bark && pip install . 

๐Ÿค— Transformers Usage

Bark is available in the ๐Ÿค— Transformers library from version 4.31.0 onwards, requiring minimal dependencies and additional packages. Steps to get started:

  1. First install the ๐Ÿค— Transformers library from main:
pip install git+https://github.com/huggingface/transformers.git
  1. Run the following Python code to generate speech samples:
from transformers import AutoProcessor, BarkModel

processor = AutoProcessor.from_pretrained("suno/bark")
model = BarkModel.from_pretrained("suno/bark")

voice_preset = "v2/en_speaker_6"

inputs = processor("Hello, my dog is cute", voice_preset=voice_preset)

audio_array = model.generate(**inputs)
audio_array = audio_array.cpu().numpy().squeeze()
  1. Listen to the audio samples either in an ipynb notebook:
from IPython.display import Audio

sample_rate = model.generation_config.sample_rate
Audio(audio_array, rate=sample_rate)

Or save them as a .wav file using a third-party library, e.g. scipy:

import scipy

sample_rate = model.generation_config.sample_rate
scipy.io.wavfile.write("bark_out.wav", rate=sample_rate, data=audio_array)

For more details on using the Bark model for inference using the ๐Ÿค— Transformers library, refer to the Bark docs or the hands-on Google Colab.

๐Ÿ› ๏ธ Hardware and Inference Speed

Bark has been tested and works on both CPU and GPU (pytorch 2.0+, CUDA 11.7 and CUDA 12.0).

On enterprise GPUs and PyTorch nightly, Bark can generate audio in roughly real-time. On older GPUs, default colab, or CPU, inference time might be significantly slower. For older GPUs or CPU you might want to consider using smaller models. Details can be found in out tutorial sections here.

The full version of Bark requires around 12GB of VRAM to hold everything on GPU at the same time. To use a smaller version of the models, which should fit into 8GB VRAM, set the environment flag SUNO_USE_SMALL_MODELS=True.

If you don't have hardware available or if you want to play with bigger versions of our models, you can also sign up for early access to our model playground here.

โš™๏ธ Details

Bark is fully generative text-to-audio model devolved for research and demo purposes. It follows a GPT style architecture similar to AudioLM and Vall-E and a quantized Audio representation from EnCodec. It is not a conventional TTS model, but instead a fully generative text-to-audio model capable of deviating in unexpected ways from any given script. Different to previous approaches, the input text prompt is converted directly to audio without the intermediate use of phonemes. It can therefore generalize to arbitrary instructions beyond speech such as music lyrics, sound effects or other non-speech sounds.

Below is a list of some known non-speech sounds, but we are finding more every day. Please let us know if you find patterns that work particularly well on Discord!

Supported Languages

Language Status
English (en) โœ…
German (de) โœ…
Spanish (es) โœ…
French (fr) โœ…
Hindi (hi) โœ…
Italian (it) โœ…
Japanese (ja) โœ…
Korean (ko) โœ…
Polish (pl) โœ…
Portuguese (pt) โœ…
Russian (ru) โœ…
Turkish (tr) โœ…
Chinese, simplified (zh) โœ…

Requests for future language support here or in the #forums channel on Discord.

๐Ÿ™ Appreciation

ยฉ License

Bark is licensed under the MIT License.

๐Ÿ“ฑย Community

๐ŸŽงย Suno Studio (Early Access)

Weโ€™re developing a playground for our models, including Bark.

If you are interested, you can sign up for early access here.

โ“ FAQ

How do I specify where models are downloaded and cached?

Bark's generations sometimes differ from my prompts. What's happening?

What voices are supported by Bark?

Why is the output limited to ~13-14 seconds?

How much VRAM do I need?

import os
os.environ["SUNO_OFFLOAD_CPU"] = "True"
os.environ["SUNO_USE_SMALL_MODELS"] = "True"

My generated audio sounds like a 1980s phone call. What's happening?