Spaces:
Sleeping
Sleeping
update
Browse files- .gitignore +1 -0
- main.py +25 -7
- project_settings.py +5 -0
.gitignore
CHANGED
@@ -6,6 +6,7 @@
|
|
6 |
/dotenv/
|
7 |
/logs/
|
8 |
/trained_models
|
|
|
9 |
|
10 |
**/__pycache__/
|
11 |
|
|
|
6 |
/dotenv/
|
7 |
/logs/
|
8 |
/trained_models
|
9 |
+
/temp/
|
10 |
|
11 |
**/__pycache__/
|
12 |
|
main.py
CHANGED
@@ -3,18 +3,21 @@
|
|
3 |
import argparse
|
4 |
import asyncio
|
5 |
from functools import partial
|
|
|
6 |
import logging
|
7 |
from pathlib import Path
|
8 |
import platform
|
9 |
import re
|
10 |
import tempfile
|
11 |
from typing import List
|
|
|
12 |
|
13 |
-
from project_settings import project_path, log_directory
|
14 |
import log
|
15 |
|
16 |
log.setup(log_directory=log_directory)
|
17 |
|
|
|
18 |
import anyio
|
19 |
import edge_tts
|
20 |
import gradio as gr
|
@@ -47,11 +50,17 @@ async def edge_tts_get_speakers() -> List[str]:
|
|
47 |
|
48 |
async def edge_tts_text_to_speech(text: str, speaker: str):
|
49 |
communicate = edge_tts.Communicate(text, speaker)
|
50 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
51 |
-
tmp_path = tmp_file.name
|
52 |
-
await communicate.save(tmp_path)
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
|
57 |
def shell(cmd: str):
|
@@ -71,11 +80,20 @@ def main():
|
|
71 |
gr.Markdown(value=title)
|
72 |
|
73 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
with gr.TabItem("Edge TTS"):
|
75 |
edge_tts_text = gr.Textbox(value="学而时习之,不亦悦乎。", lines=4, max_lines=50, label="text")
|
76 |
-
edge_tts_speaker = gr.Dropdown(choices=edge_tts_speakers_choices, value=
|
77 |
|
78 |
-
edge_tts_audio = gr.Audio(type="filepath", label="audio")
|
79 |
|
80 |
edge_tts_button = gr.Button(value="edge_tts", variant="primary")
|
81 |
edge_tts_button.click(
|
|
|
3 |
import argparse
|
4 |
import asyncio
|
5 |
from functools import partial
|
6 |
+
import json
|
7 |
import logging
|
8 |
from pathlib import Path
|
9 |
import platform
|
10 |
import re
|
11 |
import tempfile
|
12 |
from typing import List
|
13 |
+
import uuid
|
14 |
|
15 |
+
from project_settings import project_path, log_directory, edge_tts_record_file, edge_tts_temp_directory
|
16 |
import log
|
17 |
|
18 |
log.setup(log_directory=log_directory)
|
19 |
|
20 |
+
import aiofiles
|
21 |
import anyio
|
22 |
import edge_tts
|
23 |
import gradio as gr
|
|
|
50 |
|
51 |
async def edge_tts_text_to_speech(text: str, speaker: str):
|
52 |
communicate = edge_tts.Communicate(text, speaker)
|
|
|
|
|
|
|
53 |
|
54 |
+
filename = edge_tts_temp_directory / "{}.wav".format(uuid.uuid4())
|
55 |
+
async with aiofiles.open(edge_tts_record_file.as_posix(), "a+", encoding="utf-8") as f:
|
56 |
+
await f.write(json.dumps({
|
57 |
+
"text": text,
|
58 |
+
"speaker": speaker,
|
59 |
+
"filename": filename.as_posix(),
|
60 |
+
}, ensure_ascii=False))
|
61 |
+
|
62 |
+
await communicate.save(filename)
|
63 |
+
return filename
|
64 |
|
65 |
|
66 |
def shell(cmd: str):
|
|
|
80 |
gr.Markdown(value=title)
|
81 |
|
82 |
with gr.Tabs():
|
83 |
+
with gr.TabItem("Ebook Reading"):
|
84 |
+
e_book_reading_file = gr.File(
|
85 |
+
value=(project_path / "data/e_book/confucianism/the_analects.txt").as_posix(),
|
86 |
+
label="txt"
|
87 |
+
)
|
88 |
+
e_book_reading_tts_engine = gr.Dropdown(
|
89 |
+
choices=["Edge TTS"], value="Edge TTS", label="tts_engine"
|
90 |
+
)
|
91 |
+
e_book_reading_button = gr.Button(value="e_book_reading", variant="primary")
|
92 |
with gr.TabItem("Edge TTS"):
|
93 |
edge_tts_text = gr.Textbox(value="学而时习之,不亦悦乎。", lines=4, max_lines=50, label="text")
|
94 |
+
edge_tts_speaker = gr.Dropdown(choices=edge_tts_speakers_choices, value="zh-CN-XiaoxiaoNeural", label="speakers")
|
95 |
|
96 |
+
edge_tts_audio = gr.Audio(type="filepath", label="audio", autoplay=True)
|
97 |
|
98 |
edge_tts_button = gr.Button(value="edge_tts", variant="primary")
|
99 |
edge_tts_button.click(
|
project_settings.py
CHANGED
@@ -15,6 +15,11 @@ log_directory.mkdir(parents=True, exist_ok=True)
|
|
15 |
temp_directory = project_path / "temp"
|
16 |
temp_directory.mkdir(parents=True, exist_ok=True)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
environment = EnvironmentManager(
|
19 |
path=os.path.join(project_path, "dotenv"),
|
20 |
env=os.environ.get("environment", "dev"),
|
|
|
15 |
temp_directory = project_path / "temp"
|
16 |
temp_directory.mkdir(parents=True, exist_ok=True)
|
17 |
|
18 |
+
edge_tts_temp_directory = temp_directory / "edge_tts"
|
19 |
+
edge_tts_temp_directory.mkdir(parents=True, exist_ok=True)
|
20 |
+
|
21 |
+
edge_tts_record_file = edge_tts_temp_directory / "edge_tts.jsonl"
|
22 |
+
|
23 |
environment = EnvironmentManager(
|
24 |
path=os.path.join(project_path, "dotenv"),
|
25 |
env=os.environ.get("environment", "dev"),
|