Spaces:
Runtime error
Runtime error
File size: 6,547 Bytes
2b0ab45 19020ff 2b0ab45 19020ff 2b0ab45 19020ff 2b0ab45 19020ff b7c6f09 19020ff 2b0ab45 24482bf 2b0ab45 19020ff 2b0ab45 19020ff 2b0ab45 19020ff 2b0ab45 19020ff 2b0ab45 d4a4962 19020ff d4a4962 19020ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
import gradio as gr
import numpy as np
import os
from bark import SAMPLE_RATE, generate_audio, semantic_to_waveform
def predict_without_prompt(text_prompt):
if len(text_prompt.strip()) == 0:
return (16000, np.zeros(0).astype(np.int16))
audio_array = generate_audio(text_prompt)
audio_array = (audio_array * 32767).astype(np.int16)
return (SAMPLE_RATE, audio_array)
def predict_with_prompt(text_prompt, speaker_prompt):
if len(text_prompt.strip()) == 0:
return (16000, np.zeros(0).astype(np.int16))
prompt_path = os.path.join(os.getcwd(), "assets", "prompts", f"speech_{speaker_prompt}.npz")
semantic_history = np.load(prompt_path)["semantic_prompt"]
prompt_array = semantic_to_waveform(semantic_history)
prompt_array = (prompt_array * 32767).astype(np.int16)
audio_array = generate_audio(text_prompt, history_prompt=f"speech_{speaker_prompt}")
audio_array = (audio_array * 32767).astype(np.int16)
return (SAMPLE_RATE, prompt_array), (SAMPLE_RATE, audio_array)
title = "🐶 Bark"
description = """
<div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400">
<p><b>Update:</b> This space has been deprecated in favour of the Space <a href="https://huggingface.co/spaces/suno/bark"> suno/bark </a>. Please use this updated Space for new hardware and feature updates. </p>
</div>
Bark is a transformer-based text-to-audio model created by [Suno](https://suno.ai/). 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.
Bark has the capability to fully clone voices - including tone, pitch, emotion and prosody. The model also attempts to preserve music, ambient noise, etc. from the input audio prompt. However, to mitigate misuse of this technology, we limit the audio history prompts to a limited set of Suno-provided, fully synthetic options."""
article = """
## 🌎 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 even attempt to employ the native accent for the respective languages in the same voice.
Try the prompt:
```
Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.
```
## 🤭 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!
* [laughter]
* [laughs]
* [sighs]
* [music]
* [gasps]
* [clears throat]
* — or ... for hesitations
* ♪ for song lyrics
* capitalization for emphasis of a word
* MAN/WOMAN: for bias towards speaker
Try the prompt:
```
" [clears throat] Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as... ♪ singing ♪."
```
## 🎶 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.
Try the prompt:
```
♪ In the jungle, the mighty jungle, the lion barks tonight ♪
```
## 👥 Speaker Prompts
You can provide certain speaker prompts such as NARRATOR, MAN, WOMAN, etc. Please note that these are not always respected, especially if a conflicting audio history prompt is given.
Try the prompt:
```
WOMAN: I would like an oatmilk latte please.
MAN: Wow, that's expensive!
```
## 🧬 Voice Cloning
Bark has the capability to fully clone voices - including tone, pitch, emotion and prosody. The model also attempts to preserve music, ambient noise, etc. from input audio. However, to mitigate misuse of this technology, we limit the audio history prompts to a limited set of Suno-provided, fully synthetic options to choose from.
Voice cloning can be trialled using the demo tab "Text Prompt + Voice Clone". The slider bar is used to select the speaker prompt index, which ranges from 0-7 (8 possible prompts).
## Details
Bark model by [Suno](https://suno.ai/), including official [code](https://github.com/suno-ai/bark/tree/main) and model weights. Gradio demo by 🤗 Hugging Face. Bark is licensed under a non-commercial license: CC-BY 4.0 NC.
"""
examples = [
["Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as playing tic tac toe."],
["Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible."],
["♪ In the jungle, the mighty jungle, the lion barks tonight ♪"],
["WOMAN: I would like an oatmilk latte please. MAN: Wow, that's expensive!"],
]
examples_with_speaker_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.", 0],
["Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as playing tic tac toe.", 1],
["Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.", 2],
["Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.", 3],
]
unprompted = gr.Interface(
fn=predict_without_prompt,
inputs=[
gr.Text(label="Input Text"),
],
outputs=[
gr.Audio(label="Generated Speech", type="numpy"),
],
title=title,
description=description,
article=article,
examples=examples,
cache_examples=False,
)
prompted = gr.Interface(
fn=predict_with_prompt,
inputs=[
gr.Text(label="Input Text"),
gr.Slider(0, 7, value=0, step=1, label="Speaker Prompt Index"),
],
outputs=[
gr.Audio(label="Speaker Prompt", type="numpy"),
gr.Audio(label="Generated Speech", type="numpy"),
],
title=title,
description=description,
article=article,
examples=examples_with_speaker_prompt,
cache_examples=False,
)
demo = gr.Blocks()
with demo:
gr.TabbedInterface([unprompted, prompted], ["Text Prompt", "Text Prompt + Voice Clone"])
demo.launch(enable_queue=True)
|