Untitled

mail@pastecode.io avatar
unknown
python
a year ago
901 B
3
Indexable
Never
import pyttsx3


def save_generated_audio(text: str, file_name: str):
    """Function/Method Description
        This function will reproduce a text through a vocal synthesiser. It also prints the text

            Parameters
            ----------
            text : str
                The text you want to be reproduced by vocal synthesiser
            file_name: str
                The path and the name of the file

            Raises
            ------
            exception_type
                Exception Description

    """
    engine = pyttsx3.init('sapi5')
    voices = engine.getProperty('voices')

    rate = engine.getProperty('rate')  # getting details of current speaking rate
    engine.setProperty('rate', 170)  # setting up new voice rate
    engine.setProperty('voice', voices[0].id)

    engine.save_to_file(text,  file_name)
    engine.runAndWait()