Commit
•
ac94857
0
Parent(s):
Duplicate from suno/bark
Browse filesCo-authored-by: Georg Kucsko <georg-suno@users.noreply.huggingface.co>
- .gitattributes +34 -0
- .gitignore +3 -0
- README.md +15 -0
- app.py +197 -0
- requirements.txt +5 -0
- share_btn.py +75 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio_cached_examples/
|
2 |
+
__pycache__/
|
3 |
+
venv/
|
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Bark
|
3 |
+
emoji: 🐶
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: blue
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.27.0
|
8 |
+
python_version: 3.8.15
|
9 |
+
app_file: app.py
|
10 |
+
pinned: false
|
11 |
+
license: cc-by-nc-4.0
|
12 |
+
duplicated_from: suno/bark
|
13 |
+
---
|
14 |
+
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
from bark import SAMPLE_RATE, generate_audio, preload_models
|
4 |
+
from bark.generation import SUPPORTED_LANGS
|
5 |
+
from share_btn import community_icon_html, loading_icon_html, share_js
|
6 |
+
|
7 |
+
DEBUG_MODE = False
|
8 |
+
|
9 |
+
if not DEBUG_MODE:
|
10 |
+
_ = preload_models()
|
11 |
+
|
12 |
+
AVAILABLE_PROMPTS = ["Unconditional", "Announcer"]
|
13 |
+
PROMPT_LOOKUP = {}
|
14 |
+
for _, lang in SUPPORTED_LANGS:
|
15 |
+
for n in range(10):
|
16 |
+
label = f"Speaker {n} ({lang})"
|
17 |
+
AVAILABLE_PROMPTS.append(label)
|
18 |
+
PROMPT_LOOKUP[label] = f"{lang}_speaker_{n}"
|
19 |
+
PROMPT_LOOKUP["Unconditional"] = None
|
20 |
+
PROMPT_LOOKUP["Announcer"] = "announcer"
|
21 |
+
|
22 |
+
default_text = "Hello, my name is Suno. And, uh — and I like pizza. [laughs]\nBut I also have other interests such as playing tic tac toe."
|
23 |
+
|
24 |
+
title = "# 🐶 Bark</div>"
|
25 |
+
|
26 |
+
description = """
|
27 |
+
<div>
|
28 |
+
<a style="display:inline-block" href='https://github.com/suno-ai/bark'><img src='https://img.shields.io/github/stars/suno-ai/bark?style=social' /></a>
|
29 |
+
<a style='display:inline-block' href='https://discord.gg/J2B2vsjKuE'><img src='https://dcbadge.vercel.app/api/server/J2B2vsjKuE?compact=true&style=flat' /></a>
|
30 |
+
<a style="display:inline-block; margin-left: 1em" href="https://huggingface.co/spaces/suno/bark?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space%20to%20skip%20the%20queue-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a>
|
31 |
+
</div>
|
32 |
+
Bark is a universal text-to-audio model created by [Suno](www.suno.ai), with code publicly available [here](https://github.com/suno-ai/bark). \
|
33 |
+
Bark can generate highly realistic, multilingual speech as well as other audio - including music, background noise and simple sound effects. \
|
34 |
+
This demo should be used for research purposes only. Commercial use is strictly prohibited. \
|
35 |
+
The model output is not censored and the authors do not endorse the opinions in the generated content. \
|
36 |
+
Use at your own risk.
|
37 |
+
"""
|
38 |
+
|
39 |
+
article = """
|
40 |
+
|
41 |
+
## 🌎 Foreign Language
|
42 |
+
|
43 |
+
Bark supports various languages out-of-the-box and automatically determines language from input text. \
|
44 |
+
When prompted with code-switched text, Bark will even attempt to employ the native accent for the respective languages in the same voice.
|
45 |
+
|
46 |
+
Try the prompt:
|
47 |
+
|
48 |
+
```
|
49 |
+
Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.
|
50 |
+
```
|
51 |
+
|
52 |
+
## 🤭 Non-Speech Sounds
|
53 |
+
|
54 |
+
Below is a list of some known non-speech sounds, but we are finding more every day. \
|
55 |
+
Please let us know if you find patterns that work particularly well on Discord!
|
56 |
+
|
57 |
+
* [laughter]
|
58 |
+
* [laughs]
|
59 |
+
* [sighs]
|
60 |
+
* [music]
|
61 |
+
* [gasps]
|
62 |
+
* [clears throat]
|
63 |
+
* — or ... for hesitations
|
64 |
+
* ♪ for song lyrics
|
65 |
+
* capitalization for emphasis of a word
|
66 |
+
* MAN/WOMAN: for bias towards speaker
|
67 |
+
|
68 |
+
Try the prompt:
|
69 |
+
|
70 |
+
```
|
71 |
+
" [clears throat] Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as... ♪ singing ♪."
|
72 |
+
```
|
73 |
+
|
74 |
+
## 🎶 Music
|
75 |
+
Bark can generate all types of audio, and, in principle, doesn't see a difference between speech and music. \
|
76 |
+
Sometimes Bark chooses to generate text as music, but you can help it out by adding music notes around your lyrics.
|
77 |
+
|
78 |
+
Try the prompt:
|
79 |
+
|
80 |
+
```
|
81 |
+
♪ In the jungle, the mighty jungle, the lion barks tonight ♪
|
82 |
+
```
|
83 |
+
|
84 |
+
## 🧬 Voice Cloning
|
85 |
+
|
86 |
+
Bark has the capability to fully clone voices - including tone, pitch, emotion and prosody. \
|
87 |
+
The model also attempts to preserve music, ambient noise, etc. from input audio. \
|
88 |
+
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.
|
89 |
+
|
90 |
+
## 👥 Speaker Prompts
|
91 |
+
|
92 |
+
You can provide certain speaker prompts such as NARRATOR, MAN, WOMAN, etc. \
|
93 |
+
Please note that these are not always respected, especially if a conflicting audio history prompt is given.
|
94 |
+
|
95 |
+
Try the prompt:
|
96 |
+
|
97 |
+
```
|
98 |
+
WOMAN: I would like an oatmilk latte please.
|
99 |
+
MAN: Wow, that's expensive!
|
100 |
+
```
|
101 |
+
|
102 |
+
## Details
|
103 |
+
|
104 |
+
Bark model by [Suno](https://suno.ai/), including official [code](https://github.com/suno-ai/bark) and model weights. \
|
105 |
+
Gradio demo supported by 🤗 Hugging Face. Bark is licensed under a non-commercial license: CC-BY 4.0 NC, see details on [GitHub](https://github.com/suno-ai/bark).
|
106 |
+
|
107 |
+
|
108 |
+
"""
|
109 |
+
|
110 |
+
examples = [
|
111 |
+
["Please surprise me and speak in whatever voice you enjoy. Vielen Dank und Gesundheit!",
|
112 |
+
"Unconditional"], # , 0.7, 0.7],
|
113 |
+
["Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as playing tic tac toe.",
|
114 |
+
"Speaker 1 (en)"], # , 0.7, 0.7],
|
115 |
+
["Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.",
|
116 |
+
"Speaker 0 (es)"], # , 0.7, 0.7],
|
117 |
+
]
|
118 |
+
|
119 |
+
|
120 |
+
def gen_tts(text, history_prompt): # , temp_semantic, temp_waveform):
|
121 |
+
history_prompt = PROMPT_LOOKUP[history_prompt]
|
122 |
+
if DEBUG_MODE:
|
123 |
+
audio_arr = np.zeros(SAMPLE_RATE)
|
124 |
+
else:
|
125 |
+
# , text_temp=temp_semantic, waveform_temp=temp_waveform)
|
126 |
+
audio_arr = generate_audio(text, history_prompt=history_prompt)
|
127 |
+
audio_arr = (audio_arr * 32767).astype(np.int16)
|
128 |
+
return (SAMPLE_RATE, audio_arr)
|
129 |
+
|
130 |
+
|
131 |
+
css = """
|
132 |
+
#share-btn-container {
|
133 |
+
display: flex;
|
134 |
+
padding-left: 0.5rem !important;
|
135 |
+
padding-right: 0.5rem !important;
|
136 |
+
background-color: #000000;
|
137 |
+
justify-content: center;
|
138 |
+
align-items: center;
|
139 |
+
border-radius: 9999px !important;
|
140 |
+
width: 13rem;
|
141 |
+
margin-top: 10px;
|
142 |
+
margin-left: auto;
|
143 |
+
flex: unset !important;
|
144 |
+
}
|
145 |
+
#share-btn {
|
146 |
+
all: initial;
|
147 |
+
color: #ffffff;
|
148 |
+
font-weight: 600;
|
149 |
+
cursor: pointer;
|
150 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
151 |
+
margin-left: 0.5rem !important;
|
152 |
+
padding-top: 0.25rem !important;
|
153 |
+
padding-bottom: 0.25rem !important;
|
154 |
+
right:0;
|
155 |
+
}
|
156 |
+
#share-btn * {
|
157 |
+
all: unset !important;
|
158 |
+
}
|
159 |
+
#share-btn-container div:nth-child(-n+2){
|
160 |
+
width: auto !important;
|
161 |
+
min-height: 0px !important;
|
162 |
+
}
|
163 |
+
#share-btn-container .wrap {
|
164 |
+
display: none !important;
|
165 |
+
}
|
166 |
+
"""
|
167 |
+
with gr.Blocks(css=css) as block:
|
168 |
+
gr.Markdown(title)
|
169 |
+
gr.Markdown(description)
|
170 |
+
with gr.Row():
|
171 |
+
with gr.Column():
|
172 |
+
input_text = gr.Textbox(
|
173 |
+
label="Input Text", lines=2, value=default_text, elem_id="input_text")
|
174 |
+
options = gr.Dropdown(
|
175 |
+
AVAILABLE_PROMPTS, value="Speaker 1 (en)", label="Acoustic Prompt", elem_id="speaker_option")
|
176 |
+
run_button = gr.Button(text="Generate Audio", type="button")
|
177 |
+
with gr.Column():
|
178 |
+
audio_out = gr.Audio(label="Generated Audio",
|
179 |
+
type="numpy", elem_id="audio_out")
|
180 |
+
with gr.Row(visible=False) as share_row:
|
181 |
+
with gr.Group(elem_id="share-btn-container"):
|
182 |
+
community_icon = gr.HTML(community_icon_html)
|
183 |
+
loading_icon = gr.HTML(loading_icon_html)
|
184 |
+
share_button = gr.Button(
|
185 |
+
"Share to community", elem_id="share-btn")
|
186 |
+
share_button.click(None, [], [], _js=share_js)
|
187 |
+
inputs = [input_text, options]
|
188 |
+
outputs = [audio_out]
|
189 |
+
gr.Examples(examples=examples, fn=gen_tts, inputs=inputs,
|
190 |
+
outputs=outputs, cache_examples=True)
|
191 |
+
gr.Markdown(article)
|
192 |
+
run_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=share_row, queue=False).then(
|
193 |
+
fn=gen_tts, inputs=inputs, outputs=outputs, queue=True).then(
|
194 |
+
fn=lambda: gr.update(visible=True), inputs=None, outputs=share_row, queue=False)
|
195 |
+
|
196 |
+
block.queue()
|
197 |
+
block.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/suno-ai/bark.git
|
2 |
+
https://download.pytorch.org/whl/nightly/pytorch_triton-2.1.0%2B46672772b4-cp38-cp38-linux_x86_64.whl
|
3 |
+
https://download.pytorch.org/whl/nightly/cu117/torch-2.1.0.dev20230413%2Bcu117-cp38-cp38-linux_x86_64.whl
|
4 |
+
https://download.pytorch.org/whl/nightly/cu117/torchvision-0.16.0.dev20230413%2Bcu117-cp38-cp38-linux_x86_64.whl
|
5 |
+
https://download.pytorch.org/whl/nightly/cu117/torchaudio-2.1.0.dev20230413%2Bcu117-cp38-cp38-linux_x86_64.whl
|
share_btn.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
community_icon_html = """<svg id="share-btn-share-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32">
|
2 |
+
<path d="M20.6081 3C21.7684 3 22.8053 3.49196 23.5284 4.38415C23.9756 4.93678 24.4428 5.82749 24.4808 7.16133C24.9674 7.01707 25.4353 6.93643 25.8725 6.93643C26.9833 6.93643 27.9865 7.37587 28.696 8.17411C29.6075 9.19872 30.0124 10.4579 29.8361 11.7177C29.7523 12.3177 29.5581 12.8555 29.2678 13.3534C29.8798 13.8646 30.3306 14.5763 30.5485 15.4322C30.719 16.1032 30.8939 17.5006 29.9808 18.9403C30.0389 19.0342 30.0934 19.1319 30.1442 19.2318C30.6932 20.3074 30.7283 21.5229 30.2439 22.6548C29.5093 24.3704 27.6841 25.7219 24.1397 27.1727C21.9347 28.0753 19.9174 28.6523 19.8994 28.6575C16.9842 29.4379 14.3477 29.8345 12.0653 29.8345C7.87017 29.8345 4.8668 28.508 3.13831 25.8921C0.356375 21.6797 0.754104 17.8269 4.35369 14.1131C6.34591 12.058 7.67023 9.02782 7.94613 8.36275C8.50224 6.39343 9.97271 4.20438 12.4172 4.20438H12.4179C12.6236 4.20438 12.8314 4.2214 13.0364 4.25468C14.107 4.42854 15.0428 5.06476 15.7115 6.02205C16.4331 5.09583 17.134 4.359 17.7682 3.94323C18.7242 3.31737 19.6794 3 20.6081 3ZM20.6081 5.95917C20.2427 5.95917 19.7963 6.1197 19.3039 6.44225C17.7754 7.44319 14.8258 12.6772 13.7458 14.7131C13.3839 15.3952 12.7655 15.6837 12.2086 15.6837C11.1036 15.6837 10.2408 14.5497 12.1076 13.1085C14.9146 10.9402 13.9299 7.39584 12.5898 7.1776C12.5311 7.16799 12.4731 7.16355 12.4172 7.16355C11.1989 7.16355 10.6615 9.33114 10.6615 9.33114C10.6615 9.33114 9.0863 13.4148 6.38031 16.206C3.67434 18.998 3.5346 21.2388 5.50675 24.2246C6.85185 26.2606 9.42666 26.8753 12.0653 26.8753C14.8021 26.8753 17.6077 26.2139 19.1799 25.793C19.2574 25.7723 28.8193 22.984 27.6081 20.6107C27.4046 20.212 27.0693 20.0522 26.6471 20.0522C24.9416 20.0522 21.8393 22.6726 20.5057 22.6726C20.2076 22.6726 19.9976 22.5416 19.9116 22.222C19.3433 20.1173 28.552 19.2325 27.7758 16.1839C27.639 15.6445 27.2677 15.4256 26.746 15.4263C24.4923 15.4263 19.4358 19.5181 18.3759 19.5181C18.2949 19.5181 18.2368 19.4937 18.2053 19.4419C17.6743 18.557 17.9653 17.9394 21.7082 15.6009C25.4511 13.2617 28.0783 11.8545 26.5841 10.1752C26.4121 9.98141 26.1684 9.8956 25.8725 9.8956C23.6001 9.89634 18.2311 14.9403 18.2311 14.9403C18.2311 14.9403 16.7821 16.496 15.9057 16.496C15.7043 16.496 15.533 16.4139 15.4169 16.2112C14.7956 15.1296 21.1879 10.1286 21.5484 8.06535C21.7928 6.66715 21.3771 5.95917 20.6081 5.95917Z" fill="#FF9D00"></path>
|
3 |
+
<path d="M5.50686 24.2246C3.53472 21.2387 3.67446 18.9979 6.38043 16.206C9.08641 13.4147 10.6615 9.33111 10.6615 9.33111C10.6615 9.33111 11.2499 6.95933 12.59 7.17757C13.93 7.39581 14.9139 10.9401 12.1069 13.1084C9.29997 15.276 12.6659 16.7489 13.7459 14.713C14.8258 12.6772 17.7747 7.44316 19.304 6.44221C20.8326 5.44128 21.9089 6.00204 21.5484 8.06532C21.188 10.1286 14.795 15.1295 15.4171 16.2118C16.0391 17.2934 18.2312 14.9402 18.2312 14.9402C18.2312 14.9402 25.0907 8.49588 26.5842 10.1752C28.0776 11.8545 25.4512 13.2616 21.7082 15.6008C17.9646 17.9393 17.6744 18.557 18.2054 19.4418C18.7372 20.3266 26.9998 13.1351 27.7759 16.1838C28.5513 19.2324 19.3434 20.1173 19.9117 22.2219C20.48 24.3274 26.3979 18.2382 27.6082 20.6107C28.8193 22.9839 19.2574 25.7722 19.18 25.7929C16.0914 26.62 8.24723 28.3726 5.50686 24.2246Z" fill="#FFD21E"></path>
|
4 |
+
</svg>"""
|
5 |
+
|
6 |
+
loading_icon_html = """<svg id="share-btn-loading-icon" style="display:none;" class="animate-spin" style="color: #ffffff;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" fill="none" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>"""
|
7 |
+
|
8 |
+
share_js = """async () => {
|
9 |
+
async function uploadFile(file){
|
10 |
+
const UPLOAD_URL = 'https://huggingface.co/uploads';
|
11 |
+
const response = await fetch(UPLOAD_URL, {
|
12 |
+
method: 'POST',
|
13 |
+
headers: {
|
14 |
+
'Content-Type': file.type,
|
15 |
+
'X-Requested-With': 'XMLHttpRequest',
|
16 |
+
},
|
17 |
+
body: file, /// <- File inherits from Blob
|
18 |
+
});
|
19 |
+
const url = await response.text();
|
20 |
+
return url;
|
21 |
+
}
|
22 |
+
async function getInputAudioFile(audioEl){
|
23 |
+
const res = await fetch(audioEl.src);
|
24 |
+
const blob = await res.blob();
|
25 |
+
const audioId = Date.now();
|
26 |
+
const fileName = `bark-audio-${{audioId}}.wav`;
|
27 |
+
return new File([blob], fileName, { type: 'audio/wav' });
|
28 |
+
}
|
29 |
+
async function audioToBase64(audioFile) {
|
30 |
+
return new Promise((resolve, reject) => {
|
31 |
+
let reader = new FileReader();
|
32 |
+
reader.readAsDataURL(audioFile);
|
33 |
+
reader.onload = () => resolve(reader.result);
|
34 |
+
reader.onerror = error => reject(error);
|
35 |
+
|
36 |
+
});
|
37 |
+
}
|
38 |
+
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
|
39 |
+
const inputText = gradioEl.querySelector('#input_text textarea').value;
|
40 |
+
const speakerOption = gradioEl.querySelector('#speaker_option .single-select').innerText;
|
41 |
+
const audioElement = gradioEl.querySelector('#audio_out audio');
|
42 |
+
|
43 |
+
const titleTxt = `Bark: ${inputText.slice(0, 50)}...`;
|
44 |
+
const shareBtnEl = gradioEl.querySelector('#share-btn');
|
45 |
+
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
|
46 |
+
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
|
47 |
+
if(!audioElement){
|
48 |
+
return;
|
49 |
+
};
|
50 |
+
shareBtnEl.style.pointerEvents = 'none';
|
51 |
+
shareIconEl.style.display = 'none';
|
52 |
+
loadingIconEl.style.removeProperty('display');
|
53 |
+
const outputAudioFile = await getInputAudioFile(audioElement);
|
54 |
+
const urlOutputAudio = await uploadFile(outputAudioFile);
|
55 |
+
|
56 |
+
const descriptionMd = `
|
57 |
+
### Text
|
58 |
+
${inputText}
|
59 |
+
|
60 |
+
### Acoustic Prompt
|
61 |
+
${speakerOption}
|
62 |
+
|
63 |
+
### Audio
|
64 |
+
<audio controls><source src="${urlOutputAudio}" type="audio/wav"></audio>
|
65 |
+
`;
|
66 |
+
const params = new URLSearchParams({
|
67 |
+
title: titleTxt,
|
68 |
+
description: descriptionMd,
|
69 |
+
});
|
70 |
+
const paramsStr = params.toString();
|
71 |
+
window.open(`https://huggingface.co/spaces/suno/bark/discussions/new?${paramsStr}`, '_blank');
|
72 |
+
shareBtnEl.style.removeProperty('pointer-events');
|
73 |
+
shareIconEl.style.removeProperty('display');
|
74 |
+
loadingIconEl.style.display = 'none';
|
75 |
+
}"""
|