File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import pdfplumber
2+ import pyttsx3
3+
4+
5+ def read_from_pdf ():
6+ with pdfplumber .open ("欺骗的艺术.pdf" ) as pdf :
7+ print ('总页数 = ' + str (len (pdf .pages )))
8+ print ('#' * 30 )
9+ page = pdf .pages [3 ]
10+ text = page .extract_text ()
11+ print ('第四页内容如下:' )
12+ print ('#' * 30 )
13+ print (text )
14+ read_by_mp3 (text )
15+
16+
17+ def read_by_mp3 (text ):
18+ engine = pyttsx3 .init () # 初始化语音引擎
19+ text = text .replace ('\n ' , '' ) # 去掉换行符
20+ engine .say (text ) # 读文本
21+ engine .runAndWait ()
22+
23+ # 保存文件
24+ # engine.save_to_file(text, 'test.mp3')
25+ # engine.runAndWait()
26+
27+
28+ if __name__ == '__main__' :
29+ read_from_pdf ()
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ Python技术 公众号文章代码库
88
99## 实例代码
1010
11+ [ 付费?不存在的,20 行代码将电子书转换为有声小说] ( https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-09-29-pdf-to-mp3 )
12+
1113[ 神器 | 一键下载海量高清壁纸] ( https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-09-28-wallpaper )
1214
1315[ 吊炸天!十行代码我把情书藏进了小姐姐的微信头像里] ( https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-09-08-text-img )
You can’t perform that action at this time.
0 commit comments