Last active
June 25, 2023 06:17
-
-
Save monkrus/91726c39bc396b3e8c073879a4cd7849 to your computer and use it in GitHub Desktop.
Text to voice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from gtts import gTTS | |
| import os | |
| def text_to_speech(file_path): | |
| try: | |
| with open(file_path, 'r') as file: | |
| text = file.read().replace('\n', ' ') | |
| speech = gTTS(text=text, lang='en', slow=False) | |
| speech.save("output.mp3") | |
| os.system("start output.mp3") | |
| except FileNotFoundError: | |
| print(f"Sorry, the file {file_path} does not exist.") | |
| except Exception as e: | |
| print(str(e)) | |
| if __name__ == "__main__": | |
| text_file = input("Please enter the path to the text file: ") | |
| text_to_speech(text_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment