📅  最后修改于: 2023-12-03 15:01:05.295000             🧑  作者: Mango
gTTS (Google Text-to-Speech) is a Python library and CLI tool to interface with Google Translate's text-to-speech API. This API converts written text into spoken words and returns an audio file as a result.
gTTS can be installed using pip. Open a command prompt or terminal and run the following command:
pip install gTTS
from gtts import gTTS
tts = gTTS('Hello, World!')
tts.save('hello.mp3')
gtts-cli 'Hello, World!' | mpg123 -
from gtts import gTTS
tts = gTTS('Hello, World!')
# Save the speech as an mp3 file
tts.save('hello.mp3')
# Play the speech directly from the command line
!gtts-cli 'Hello, World!' | mpg123 -
gTTS is a simple and effective tool to convert text to speech using Python. It offers great functionality in an easy-to-use package. With gTTS, you can save speech as an mp3 file or play it directly from the command line.