Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio
|
2 |
+
import edge_tts
|
3 |
+
import subprocess
|
4 |
+
|
5 |
+
VOICE = "ml-IN-MidhunNeural"
|
6 |
+
|
7 |
+
async def text2video(text):
|
8 |
+
OUTPUT_FILE = "output.mp4"
|
9 |
+
WEBVTT_FILE = "output.vtt"
|
10 |
+
|
11 |
+
communicate = edge_tts.Communicate(text, VOICE)
|
12 |
+
submaker = edge_tts.SubMaker()
|
13 |
+
|
14 |
+
with open("output.mp3", "wb") as file:
|
15 |
+
async for chunk in communicate.stream():
|
16 |
+
if chunk["type"] == "audio":
|
17 |
+
file.write(chunk["data"])
|
18 |
+
elif chunk["type"] == "WordBoundary":
|
19 |
+
submaker.create_sub((chunk["offset"], chunk["duration"]), chunk["text"])
|
20 |
+
|
21 |
+
with open(WEBVTT_FILE, "w", encoding="utf-8") as file:
|
22 |
+
file.write(submaker.generate_subs())
|
23 |
+
|
24 |
+
ffmpeg_command = [
|
25 |
+
"ffmpeg",
|
26 |
+
"-y",
|
27 |
+
"-loop", "1",
|
28 |
+
"-i", "background.jpg",
|
29 |
+
"-i", "output.mp3",
|
30 |
+
"-vf", "subtitles=output.vtt:force_style='FontSize=24,PrimaryColour=&HFFFFFF'",
|
31 |
+
"-c:v", "libx264",
|
32 |
+
"-c:a", "aac",
|
33 |
+
"-shortest",
|
34 |
+
OUTPUT_FILE
|
35 |
+
]
|
36 |
+
subprocess.run(ffmpeg_command, check=True)
|
37 |
+
|
38 |
+
return OUTPUT_FILE
|
39 |
+
|
40 |
+
interface = gradio.Interface(
|
41 |
+
fn=text2video,
|
42 |
+
inputs="text",
|
43 |
+
outputs=["video"],
|
44 |
+
)
|
45 |
+
|
46 |
+
interface.launch()
|