In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use python to convert pdf into audiobooks related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this article on how to use python to convert pdf into audiobooks will have a harvest, let's take a look at it.
The pyttsx3 module in python can realize voice broadcast, while the pdfplumber or PyPDF2 module converts pdf to text. I use the pdfplumber module. First of all, let's download the module. You can pip install the module name yourself.
Then we add the required pdf files to the same folder of the code (easy to call, you can also use the absolute path)
Code
# @ Time:2022/2/120:29# @ Author: favorite book # @ File: audiobooks .py # @ ps:tutu qqnum:2117472285import pyttsx3import pdfplumberpdf=pdfplumber.open (input ('Please enter the title:') pg_no=int (input ("Please enter the page you want to read:)) # Total pages numpages=len (pdf.pages) for num in range ((pg_no-1)) Numpages): # get the content of the specified number of pages of the article first_page= pdf.pages [num] # get the text content text=first_page.extract_text () # initialize speaker=pyttsx3.init () # remove the newline character text=text.replace ('\ nfeeds)) # adjust the type of human voice Voice [0] is a Chinese female voice, so you can switch to others by yourself, but note that the English female voice cannot read Chinese voices=speaker.getProperty ('voices') speaker.setProperty (' voice',voices [0] .id) # adjust the speed rate=speaker.getProperty ('rate') speaker.setProperty (' rate',150) # adjust the volume, in 0-1 volume=speaker.getProperty ('volume') speaker.setProperty (' volume',1) # Hey I did not tune # read speaker.say (text) # save audio # speaker.save_to_file (text, 'T1.mp3') speaker.runAndWait ()
Running result:
This is the end of the article on "how to convert pdf into audiobooks with python". Thank you for reading! I believe everyone has a certain understanding of "how to use python to convert pdf into audiobooks". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.