Update video2.py
Browse files
video2.py
CHANGED
|
@@ -27,13 +27,16 @@ CLIPS_DIR = os.path.join(BASE_DIR, "video")
|
|
| 27 |
# Create directories (no chmod needed)
|
| 28 |
for path in [BASE_DIR, AUDIO_DIR, CLIPS_DIR]:
|
| 29 |
Path(path).mkdir(parents=True, exist_ok=True)
|
| 30 |
-
async def generate_tts(id,
|
| 31 |
voice = "en-US-JennyNeural"
|
| 32 |
audio_name = f"audio{id}.mp3"
|
| 33 |
audio_path = os.path.join(AUDIO_DIR, audio_name)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
communicate = edge_tts.Communicate(text=text, voice=voice, rate="+0%")
|
| 38 |
await communicate.save(audio_path)
|
| 39 |
if os.path.exists(audio_path):
|
|
@@ -41,10 +44,10 @@ async def generate_tts(id, lang):
|
|
| 41 |
duration = audio.info.length
|
| 42 |
return duration, audio_path
|
| 43 |
return None, None
|
| 44 |
-
def audio_func(id,
|
| 45 |
-
return asyncio.run(generate_tts(id,
|
| 46 |
def video_func(id, lines,lang):
|
| 47 |
-
duration, audio_path = audio_func(id,
|
| 48 |
if not duration or not audio_path:
|
| 49 |
print("Failed to generate audio.")
|
| 50 |
return None
|
|
|
|
| 27 |
# Create directories (no chmod needed)
|
| 28 |
for path in [BASE_DIR, AUDIO_DIR, CLIPS_DIR]:
|
| 29 |
Path(path).mkdir(parents=True, exist_ok=True)
|
| 30 |
+
async def generate_tts(id,lines,lang):
|
| 31 |
voice = "en-US-JennyNeural"
|
| 32 |
audio_name = f"audio{id}.mp3"
|
| 33 |
audio_path = os.path.join(AUDIO_DIR, audio_name)
|
| 34 |
+
if len(lang)>1:
|
| 35 |
+
listf = lang.split("&&&")
|
| 36 |
+
text = listf[0].strip()
|
| 37 |
+
langvoice = listf[1].strip()
|
| 38 |
+
else:
|
| 39 |
+
text=lines[id]
|
| 40 |
communicate = edge_tts.Communicate(text=text, voice=voice, rate="+0%")
|
| 41 |
await communicate.save(audio_path)
|
| 42 |
if os.path.exists(audio_path):
|
|
|
|
| 44 |
duration = audio.info.length
|
| 45 |
return duration, audio_path
|
| 46 |
return None, None
|
| 47 |
+
def audio_func(id,lines,lang):
|
| 48 |
+
return asyncio.run(generate_tts(id,lines,lang))
|
| 49 |
def video_func(id, lines,lang):
|
| 50 |
+
duration, audio_path = audio_func(id,lines,lang)
|
| 51 |
if not duration or not audio_path:
|
| 52 |
print("Failed to generate audio.")
|
| 53 |
return None
|