Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
from fastapi.responses import StreamingResponse
|
| 3 |
-
from pydantic import BaseModel
|
| 4 |
from gtts import gTTS
|
| 5 |
-
import
|
| 6 |
|
| 7 |
-
app = FastAPI()
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
|
|
|
|
| 14 |
|
| 15 |
-
@app.post("/tts")
|
| 16 |
-
def tts(request: TTSRequest):
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
tts.write_to_fp(mp3_buffer)
|
| 22 |
-
|
| 23 |
-
mp3_buffer.seek(0)
|
| 24 |
-
|
| 25 |
-
return StreamingResponse(
|
| 26 |
-
mp3_buffer,
|
| 27 |
-
media_type="audio/mpeg",
|
| 28 |
-
headers={"Content-Disposition": "inline; filename=output.mp3"}
|
| 29 |
-
)
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from gtts import gTTS
|
| 3 |
+
import tempfile
|
| 4 |
|
|
|
|
| 5 |
|
| 6 |
+
def tts(text):
|
| 7 |
|
| 8 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
| 9 |
|
| 10 |
+
gTTS(text=text, lang="ja").save(f.name)
|
| 11 |
|
| 12 |
+
return f.name
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=tts,
|
| 17 |
+
inputs=gr.Textbox(label="Text"),
|
| 18 |
+
outputs=gr.Audio(type="filepath", label="MP3 Output")
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|