Update video2.py
Browse files
video2.py
CHANGED
|
@@ -27,48 +27,55 @@ 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 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
audio_name = f"audio{id}.mp3"
|
| 51 |
audio_path = os.path.join(AUDIO_DIR, audio_name)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
print(f"Attempt {attempt + 1}: Audio file was not created.")
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f"Attempt {attempt + 1} failed: {str(e)}")
|
| 67 |
-
if attempt < max_retries - 1:
|
| 68 |
-
await asyncio.sleep(1)
|
| 69 |
-
else:
|
| 70 |
-
print("All attempts failed.")
|
| 71 |
-
return None, None
|
| 72 |
return None, None
|
| 73 |
def audio_func(id,lines,lang):
|
| 74 |
return asyncio.run(generate_tts(id,lines,lang))
|
|
|
|
| 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={
|
| 32 |
+
"English": "en-US-JennyNeural",
|
| 33 |
+
"Tamil": "ta-IN-PallaviNeural",
|
| 34 |
+
"Hindi": "hi-IN-SwaraNeural",
|
| 35 |
+
"Malayalam": "ml-IN-SobhanaNeural",
|
| 36 |
+
"Kannada": "kn-IN-SapnaNeural",
|
| 37 |
+
"Telugu": "te-IN-ShrutiNeural",
|
| 38 |
+
"Bengali": "bn-IN-TanishaaNeural",
|
| 39 |
+
"Marathi": "mr-IN-AarohiNeural",
|
| 40 |
+
"Gujarati": "gu-IN-DhwaniNeural",
|
| 41 |
+
"Punjabi": "pa-IN-VaaniNeural",
|
| 42 |
+
"Urdu": "ur-IN-GulNeural",
|
| 43 |
+
"French": "fr-FR-DeniseNeural",
|
| 44 |
+
"German": "de-DE-KatjaNeural",
|
| 45 |
+
"Spanish": "es-ES-ElviraNeural",
|
| 46 |
+
"Italian": "it-IT-IsabellaNeural",
|
| 47 |
+
"Russian": "ru-RU-SvetlanaNeural",
|
| 48 |
+
"Japanese": "ja-JP-NanamiNeural",
|
| 49 |
+
"Korean": "ko-KR-SunHiNeural",
|
| 50 |
+
"Chinese": "zh-CN-XiaoxiaoNeural",
|
| 51 |
+
"Arabic": "ar-SA-ZariyahNeural",
|
| 52 |
+
"Portuguese": "pt-BR-FranciscaNeural",
|
| 53 |
+
"Dutch": "nl-NL-FennaNeural",
|
| 54 |
+
"Greek": "el-GR-AthinaNeural",
|
| 55 |
+
"Hebrew": "he-IL-HilaNeural",
|
| 56 |
+
"Turkish": "tr-TR-EmelNeural",
|
| 57 |
+
"Polish": "pl-PL-AgnieszkaNeural",
|
| 58 |
+
"Thai": "th-TH-AcharaNeural",
|
| 59 |
+
"Vietnamese": "vi-VN-HoaiMyNeural",
|
| 60 |
+
"Swedish": "sv-SE-SofieNeural",
|
| 61 |
+
"Finnish": "fi-FI-NooraNeural",
|
| 62 |
+
"Czech": "cs-CZ-VlastaNeural",
|
| 63 |
+
"Hungarian": "hu-HU-NoemiNeural"
|
| 64 |
+
}
|
| 65 |
audio_name = f"audio{id}.mp3"
|
| 66 |
audio_path = os.path.join(AUDIO_DIR, audio_name)
|
| 67 |
+
if len(lang)>1:
|
| 68 |
+
listf = lang.split("&&&")
|
| 69 |
+
text = listf[0].strip()
|
| 70 |
+
langvoice = voice[listf[1].strip()]
|
| 71 |
+
else:
|
| 72 |
+
text=lines[id]
|
| 73 |
+
communicate = edge_tts.Communicate(text=text, voice=langvoice, rate="+0%")
|
| 74 |
+
await communicate.save(audio_path)
|
| 75 |
+
if os.path.exists(audio_path):
|
| 76 |
+
audio = MP3(audio_path)
|
| 77 |
+
duration = audio.info.length
|
| 78 |
+
return duration, audio_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
return None, None
|
| 80 |
def audio_func(id,lines,lang):
|
| 81 |
return asyncio.run(generate_tts(id,lines,lang))
|