replacebg / tts.py
Munaf1987's picture
Upload 7 files
139ec19 verified
raw
history blame
471 Bytes
import os
from bark import generate_audio as bark_tts
def generate_audio(text, idx, language):
out_path = f"assets/audio/scene_{idx}.wav"
try:
audio = bark_tts(text, lang=language.lower())
with open(out_path, "wb") as f:
f.write(audio)
except:
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.save_to_file(text, out_path)
engine.runAndWait()
return out_path