Spaces:
Runtime error
Runtime error
| import numpy as np | |
| import gradio as gr | |
| from bark import SAMPLE_RATE, generate_audio, preload_models | |
| from bark.generation import SUPPORTED_LANGS | |
| from share_btn import community_icon_html, loading_icon_html, share_js | |
| DEBUG_MODE = False | |
| if not DEBUG_MODE: | |
| _ = preload_models() | |
| AVAILABLE_PROMPTS = ["Unconditional", "Announcer"] | |
| PROMPT_LOOKUP = {} | |
| for _, lang in SUPPORTED_LANGS: | |
| for n in range(10): | |
| label = f"Speaker {n} ({lang})" | |
| AVAILABLE_PROMPTS.append(label) | |
| PROMPT_LOOKUP[label] = f"{lang}_speaker_{n}" | |
| PROMPT_LOOKUP["Unconditional"] = None | |
| PROMPT_LOOKUP["Announcer"] = "announcer" | |
| 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." | |
| title = "# 🐶 Bark</div>" | |
| description = """ | |
| """ | |
| article = """ | |
| """ | |
| examples = [ | |
| ["Please surprise me and speak in whatever voice you enjoy. Vielen Dank und Gesundheit!", | |
| "Unconditional"], # , 0.7, 0.7], | |
| ["Hello, my name is Suno. And, uh — and I like pizza. [laughs] But I also have other interests such as playing tic tac toe.", | |
| "Speaker 1 (en)"], # , 0.7, 0.7], | |
| ["Buenos días Miguel. Tu colega piensa que tu alemán es extremadamente malo. But I suppose your english isn't terrible.", | |
| "Speaker 0 (es)"], # , 0.7, 0.7], | |
| ] | |
| def gen_tts(text, history_prompt): # , temp_semantic, temp_waveform): | |
| history_prompt = PROMPT_LOOKUP[history_prompt] | |
| if DEBUG_MODE: | |
| audio_arr = np.zeros(SAMPLE_RATE) | |
| else: | |
| # , text_temp=temp_semantic, waveform_temp=temp_waveform) | |
| audio_arr = generate_audio(text, history_prompt=history_prompt) | |
| audio_arr = (audio_arr * 32767).astype(np.int16) | |
| return (SAMPLE_RATE, audio_arr) | |
| css = """ | |
| """ | |
| with gr.Blocks(css=css) as block: | |
| gr.Markdown(title) | |
| gr.Markdown(description) | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_text = gr.Textbox( | |
| label="Input Text", lines=2, value=default_text, elem_id="input_text") | |
| options = gr.Dropdown( | |
| AVAILABLE_PROMPTS, value="Speaker 1 (en)", label="Acoustic Prompt", elem_id="speaker_option") | |
| run_button = gr.Button(text="Generate Audio", type="button") | |
| with gr.Column(): | |
| audio_out = gr.Audio(label="Generated Audio", | |
| type="numpy", elem_id="audio_out") | |
| with gr.Row(visible=False) as share_row: | |
| with gr.Group(elem_id="share-btn-container"): | |
| community_icon = gr.HTML(community_icon_html) | |
| loading_icon = gr.HTML(loading_icon_html) | |
| share_button = gr.Button( | |
| "Share to community", elem_id="share-btn") | |
| share_button.click(None, [], [], _js=share_js) | |
| inputs = [input_text, options] | |
| outputs = [audio_out] | |
| gr.Examples(examples=examples, fn=gen_tts, inputs=inputs, | |
| outputs=outputs, cache_examples=True) | |
| gr.Markdown(article) | |
| run_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=share_row, queue=False).then( | |
| fn=gen_tts, inputs=inputs, outputs=outputs, queue=True).then( | |
| fn=lambda: gr.update(visible=True), inputs=None, outputs=share_row, queue=False) | |
| block.queue() | |
| block.launch() |