本文分享一下利用Python的GTTS 模块将PDF文本转换为音频,从而将PDF书籍转换为有声读物的脚本:
# Create Audiobooks
# pip install gTTS
# pip install PyPDF2
from PyPDF2 import PdfFileReader as reader
from gtts import gTTS
def create_audio(pdf_file):
read_Pdf = reader(open(pdf_file, 'rb'))
for page in range(read_Pdf.numPages):
text = read_Pdf.getPage(page).extractText()
tts = gTTS(text, lang='en')
tts.save('page' + str(page) + '.mp3')
create_audio('book.pdf')
标签:tts,Python,有声,read,gTTS,pdf,Pdf,读物,page
From: https://blog.51cto.com/u_15944471/6052175