Spaces:
Running
Running
fix
Browse files- __pycache__/main.cpython-39.pyc +0 -0
- __pycache__/model.cpython-39.pyc +0 -0
- __pycache__/test_.cpython-39.pyc +0 -0
- demo.py +0 -44
- main.py +50 -5
__pycache__/main.cpython-39.pyc
DELETED
Binary file (2.12 kB)
|
|
__pycache__/model.cpython-39.pyc
DELETED
Binary file (21 kB)
|
|
__pycache__/test_.cpython-39.pyc
DELETED
Binary file (436 Bytes)
|
|
demo.py
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from enum import Enum
|
3 |
-
from model import text_to_speech
|
4 |
-
|
5 |
-
description = """
|
6 |
-
## [接口文档](/docs)
|
7 |
-
## 功能:
|
8 |
-
- 零样本文本到语音(TTS): 输入 5 秒的声音样本,即刻体验文本到语音转换。
|
9 |
-
|
10 |
-
- 少样本 TTS: 仅需 1 分钟的训练数据即可微调模型,提升声音相似度和真实感。
|
11 |
-
|
12 |
-
- 跨语言支持: 支持与训练数据集不同语言的推理,目前支持英语、日语和中文。
|
13 |
-
|
14 |
-
"""
|
15 |
-
|
16 |
-
|
17 |
-
class Demo:
|
18 |
-
title = "text to speech"
|
19 |
-
description = description
|
20 |
-
|
21 |
-
@property
|
22 |
-
def app(self):
|
23 |
-
with gr.Blocks() as demo:
|
24 |
-
self.layout()
|
25 |
-
return demo
|
26 |
-
|
27 |
-
def layout(self):
|
28 |
-
with gr.Row():
|
29 |
-
gr.Markdown()
|
30 |
-
with gr.Row():
|
31 |
-
with gr.Column(scale=2):
|
32 |
-
with gr.Row():
|
33 |
-
self.text = gr.Textbox(label="请输入需要转换的文本")
|
34 |
-
with gr.Row():
|
35 |
-
self.voice = gr.Dropdown(
|
36 |
-
["新闻小说主播-女士", "温柔女士"], value="新闻小说主播-女士", label="选择音色")
|
37 |
-
with gr.Column(scale=2):
|
38 |
-
self.audio = gr.Audio(label="转换后的音频", type="filepath", scale=3)
|
39 |
-
with gr.Row():
|
40 |
-
self.button = gr.Button()
|
41 |
-
|
42 |
-
|
43 |
-
if __name__ == "__main__":
|
44 |
-
Demo().app.launch(share=True, server_port=40000, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
@@ -1,14 +1,23 @@
|
|
1 |
from fastapi import FastAPI, Body, File, Form, UploadFile, Response, Request
|
2 |
from fastapi.responses import FileResponse, StreamingResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
-
import gradio as
|
5 |
import os
|
6 |
from enum import Enum
|
7 |
import uvicorn
|
8 |
import time
|
9 |
from model import Language, DefaultVoice, text_to_speech
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
@app.middleware("http")
|
@@ -22,7 +31,6 @@ async def add_process_time_header(request: Request, call_next):
|
|
22 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
23 |
|
24 |
|
25 |
-
|
26 |
@app.post("/tts")
|
27 |
async def tts(
|
28 |
voice: DefaultVoice = Form("新闻女士"),
|
@@ -38,8 +46,45 @@ async def tts(
|
|
38 |
audio_content = audio_file.read()
|
39 |
return Response(audio_content, headers=headers)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
gr.mount_gradio_app(app, Demo().app, path="/")
|
42 |
|
43 |
if __name__ == '__main__':
|
44 |
-
|
45 |
uvicorn.run(app="main:app", port=int(7860), host="0.0.0.0")
|
|
|
1 |
from fastapi import FastAPI, Body, File, Form, UploadFile, Response, Request
|
2 |
from fastapi.responses import FileResponse, StreamingResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
+
import gradio as gr
|
5 |
import os
|
6 |
from enum import Enum
|
7 |
import uvicorn
|
8 |
import time
|
9 |
from model import Language, DefaultVoice, text_to_speech
|
10 |
+
description = """
|
11 |
+
## [接口文档](/docs)
|
12 |
+
## 功能:
|
13 |
+
- 零样本文本到语音(TTS): 输入 5 秒的声音样本,即刻体验文本到语音转换。
|
14 |
+
|
15 |
+
- 少样本 TTS: 仅需 1 分钟的训练数据即可微调模型,提升声音相似度和真实感。
|
16 |
+
|
17 |
+
- 跨语言支持: 支持与训练数据集不同语言的推理,目前支持英语、日语和中文。
|
18 |
+
|
19 |
+
"""
|
20 |
+
app = FastAPI(title="text to speech", description=description)
|
21 |
|
22 |
|
23 |
@app.middleware("http")
|
|
|
31 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
32 |
|
33 |
|
|
|
34 |
@app.post("/tts")
|
35 |
async def tts(
|
36 |
voice: DefaultVoice = Form("新闻女士"),
|
|
|
46 |
audio_content = audio_file.read()
|
47 |
return Response(audio_content, headers=headers)
|
48 |
|
49 |
+
|
50 |
+
class Demo:
|
51 |
+
title = "text to speech"
|
52 |
+
description = description
|
53 |
+
|
54 |
+
@property
|
55 |
+
def app(self):
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
self.layout()
|
58 |
+
self.event()
|
59 |
+
return demo
|
60 |
+
|
61 |
+
def click_run_button(self, voice, text):
|
62 |
+
wav_path = text_to_speech(voice=voice, text=text)
|
63 |
+
return wav_path
|
64 |
+
|
65 |
+
def event(self):
|
66 |
+
self.button.click(self.click_run_button, inputs=[
|
67 |
+
self.voice, self.text], outputs=[self.audio])
|
68 |
+
|
69 |
+
def layout(self):
|
70 |
+
with gr.Row():
|
71 |
+
gr.Markdown(value=self.description)
|
72 |
+
with gr.Row():
|
73 |
+
with gr.Column(scale=2):
|
74 |
+
with gr.Row():
|
75 |
+
self.text = gr.Textbox(label="请输入需要转换的文本")
|
76 |
+
with gr.Row():
|
77 |
+
self.voice = gr.Dropdown(
|
78 |
+
["新闻小说主播-女士", "温柔女士"],
|
79 |
+
label="选择音色")
|
80 |
+
with gr.Column(scale=2):
|
81 |
+
self.audio = gr.Audio(label="转换后的音频", type="filepath", scale=3)
|
82 |
+
with gr.Row():
|
83 |
+
self.button = gr.Button()
|
84 |
+
|
85 |
+
|
86 |
gr.mount_gradio_app(app, Demo().app, path="/")
|
87 |
|
88 |
if __name__ == '__main__':
|
89 |
+
|
90 |
uvicorn.run(app="main:app", port=int(7860), host="0.0.0.0")
|