File size: 471 Bytes
139ec19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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