Skip to content

Instantly share code, notes, and snippets.

@kshwetabh
Created March 2, 2020 10:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kshwetabh/5b921a450723bc7c3ea4fa04630a3603 to your computer and use it in GitHub Desktop.
Save kshwetabh/5b921a450723bc7c3ea4fa04630a3603 to your computer and use it in GitHub Desktop.
This script speaks and converts text-to-speech (mp3) using python's pyttsx3 library. This code has been tested on Windows 10 system and requires pywin32 and pyttsx3 python packages to be installed.
import pyttsx3
text = "When you invest for five years or above, you can expect gains that comfortably beat the inflation rate and are also higher than fixed income options. But be prepared for ups and downs in your investment value along the way. Aggressive"\
" hybrid funds invest 65-80% of your money in equity shares and the rest in bonds and commodities. Their returns are slightly lower than pure equity funds which"
engine = pyttsx3.init();
engine.setProperty('volume', 1)
engine.setProperty('rate', 160)
engine.say(text)
engine.save_to_file(text, "./test.mp3")
engine.runAndWait()
engine.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment