46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
|
import gradio as gr
|
||
|
from gradio.themes.utils import sizes
|
||
|
from bark import SAMPLE_RATE, generate_audio, preload_models
|
||
|
import numpy as np
|
||
|
|
||
|
|
||
|
theme = gr.themes.Default(radius_size=sizes.radius_none).set(
|
||
|
block_label_text_color = '#4D63FF',
|
||
|
block_title_text_color = '#4D63FF',
|
||
|
button_primary_text_color = '#4D63FF',
|
||
|
button_primary_background_fill='#FFFFFF',
|
||
|
button_primary_border_color='#4D63FF',
|
||
|
button_primary_background_fill_hover='#EDEFFF',
|
||
|
)
|
||
|
|
||
|
|
||
|
preload_models()
|
||
|
|
||
|
|
||
|
def text2audio(text):
|
||
|
audio_arr = generate_audio(text)
|
||
|
audio_arr = (audio_arr * 32767).astype(np.int16)
|
||
|
|
||
|
return (SAMPLE_RATE, audio_arr)
|
||
|
|
||
|
|
||
|
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
||
|
gr.Markdown("""
|
||
|
<div align='center' ><font size='60'>语音合成</font></div>
|
||
|
""")
|
||
|
with gr.Row():
|
||
|
with gr.Column():
|
||
|
box1 = gr.Textbox(label="文本")
|
||
|
with gr.Row():
|
||
|
button = gr.Button("提交", variant="primary")
|
||
|
clear = gr.Button("清除", variant="primary")
|
||
|
box2 = gr.Audio(label="音频")
|
||
|
|
||
|
button.click(fn=text2audio, inputs=box1, outputs=box2)
|
||
|
clear.click(lambda x: gr.update(value=''), [], [box1])
|
||
|
examples = gr.Examples(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.'], inputs=[box1], label="例子")
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
demo.queue(concurrency_count=3).launch(server_name = "0.0.0.0")
|