Home >Backend Development >Python Tutorial >Text to speech (book to audiobook)
Ever wished you could enjoy your favorite books without sacrificing precious reading time? Many of us face this dilemma. We have books we want to read, but life gets in the way.
Here are a few common challenges:
Fortunately, a simple coding solution exists to convert your existing ebooks into audiobooks for free.
The Solution: gTTS
The Python library gTTS
provides a straightforward way to generate speech from text.
What is gTTS?
gTTS
leverages Google Translate's Text-to-Speech API. It's a versatile tool supporting multiple languages and MP3 output, making it perfect for audiobooks, automated messages, and accessibility applications.
Key gTTS Features:
.com
, .co.uk
, or .co.in
.slow
parameter lets you control the speech rate for improved comprehension.Example: Text-to-Speech Conversion
Here's a simple code snippet:
<code class="language-python">from gtts import gTTS # Text to convert text = "Hello, welcome to the world of text-to-speech!" # Create gTTS object speech = gTTS(text=text, lang='en', tld='com', slow=False) # Save as MP3 speech.save("output.mp3") print("Audio file 'output.mp3' created successfully.")</code>
Simplified Solution: A Ready-Made Repo
For added convenience, I've created a repository to streamline the conversion of .epub
and .fb2
files into MP3 audiobooks using text-to-speech.
Start enjoying your ebooks in audio format today!
The above is the detailed content of Text to speech (book to audiobook). For more information, please follow other related articles on the PHP Chinese website!