CoolFace
Apppublic

RabbitRUI/ruispace

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
text2speech.py21 linesDownload Raw Back to utils
1import os2import tempfile3from TTS.api import TTS4 5 6 7class TTSTalker():8    def __init__(self) -> None:9        model_name = TTS.list_models()[0]10        self.tts = TTS(model_name)11 12    def test(self, text, language='en'):13 14        tempf  = tempfile.NamedTemporaryFile(15                delete = False,16                suffix = ('.'+'wav'),17            )18 19        self.tts.tts_to_file(text, speaker=self.tts.speakers[0], language=language, file_path=tempf.name)20 21        return tempf.name