alrab222 commited on
Commit
e350c04
·
verified ·
1 Parent(s): 609d8b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -20
app.py CHANGED
@@ -1,29 +1,21 @@
1
- from fastapi import FastAPI
2
- from fastapi.responses import StreamingResponse
3
- from pydantic import BaseModel
4
  from gtts import gTTS
5
- import io
6
 
7
- app = FastAPI()
8
 
 
9
 
10
- class TTSRequest(BaseModel):
11
 
12
- text: str
13
 
 
14
 
15
- @app.post("/tts")
16
- def tts(request: TTSRequest):
17
 
18
- mp3_buffer = io.BytesIO()
 
 
 
 
19
 
20
- tts = gTTS(text=request.text, lang="ja")
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()