#talk_hello_world.py #convert text to MP3 file from gtts import gTTS # pip install gtts language = 'en' output = gTTS(text="hello world. How are you?",lang=language) #,slow=False) output.save("talk_hello_world_test.mp3") # convert a text file to a MP3 file: ''' with open("alice2.txt") as inf: alice = inf.read().replace("\n",' ') output = gTTS(alice, slow=False) output.save("alice2.mp3") ''' ''' #read from a PDF file, convert a page to text import PyPDF2 # pip install PyPDF2 book = open("the-great-gatsby.pdf","rb") pdf_reader = PyPDF2.PdfFileReader(book) num_pages = pdf_reader.numPages print(num_pages) page = pdf_reader.getPage(7) text = page.extractText() print(text) #several junk chars in it... ''' ''' # use pyttsx3 pip install pyttsx3 import pyttsx3 speaker = pyttsx3.init('sapi5') # ERROR. forget this pyttsx3 speaker.say("hello world") speaker.runAndWait() '''