Update video2.py
Browse files
video2.py
CHANGED
|
@@ -3,6 +3,7 @@ from PIL import Image
|
|
| 3 |
import pytesseract
|
| 4 |
import numpy as np
|
| 5 |
from gtts import gTTS
|
|
|
|
| 6 |
from mutagen.mp3 import MP3
|
| 7 |
import uuid
|
| 8 |
import os
|
|
@@ -21,18 +22,23 @@ CLIPS_DIR = os.path.join(BASE_DIR, "video")
|
|
| 21 |
# Create directories (no chmod needed)
|
| 22 |
for path in [BASE_DIR, AUDIO_DIR, CLIPS_DIR]:
|
| 23 |
Path(path).mkdir(parents=True, exist_ok=True)
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# --- CONFIGURATION ---
|
| 38 |
def video_func(id, lines):
|
|
|
|
| 3 |
import pytesseract
|
| 4 |
import numpy as np
|
| 5 |
from gtts import gTTS
|
| 6 |
+
import edge_tts
|
| 7 |
from mutagen.mp3 import MP3
|
| 8 |
import uuid
|
| 9 |
import os
|
|
|
|
| 22 |
# Create directories (no chmod needed)
|
| 23 |
for path in [BASE_DIR, AUDIO_DIR, CLIPS_DIR]:
|
| 24 |
Path(path).mkdir(parents=True, exist_ok=True)
|
|
|
|
| 25 |
|
| 26 |
+
async def generate_tts(id,lines):
|
| 27 |
+
voice = "en-US-GuyNeural"
|
| 28 |
+
audio_name = f"audio{id}.mp3"
|
| 29 |
+
audio_path = os.path.join(AUDIO_DIR, audio_name)
|
| 30 |
+
|
| 31 |
+
communicate = edge_tts.Communicate(text=lines[id], voice=voice, rate="+0%")
|
| 32 |
+
await communicate.save(audio_path)
|
| 33 |
+
|
| 34 |
+
if os.path.exists(audio_path):
|
| 35 |
+
audio = MP3(audio_path)
|
| 36 |
+
duration = audio.info.length
|
| 37 |
+
return duration, audio_path
|
| 38 |
+
return None, None
|
| 39 |
+
|
| 40 |
+
def audio_func(id, lines):
|
| 41 |
+
return asyncio.run(generate_tts(id,lines))
|
| 42 |
|
| 43 |
# --- CONFIGURATION ---
|
| 44 |
def video_func(id, lines):
|