Skip to content

Instantly share code, notes, and snippets.

@codedeep79
Created November 5, 2022 05:15
Show Gist options
  • Select an option

  • Save codedeep79/023a6f2dabb53850085416fa9dfab1d4 to your computer and use it in GitHub Desktop.

Select an option

Save codedeep79/023a6f2dabb53850085416fa9dfab1d4 to your computer and use it in GitHub Desktop.
Tạo Sách nói bằng Python
import PyPDF2
import pyttsx3

engine = pyttsx3.init()
pdfReader = PyPDF2.PdfFileReader(open('journey_to_the_west.pdf', 'rb'))
speaker = pyttsx3.init() 
for page_num in range(pdfReader.numPages):
    text =  pdfReader.getPage(page_num).extractText()
    speaker.say(text)  
    speaker.runAndWait() 
speaker.stop()
engine.save_to_file(text, 'E:\audio.mp3')

engine.runAndWait() 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment