简体   繁体   中英

How to use gTTS in python3 on a Raspberry Pi 3 model B

import gtts
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("test.mp3")

I use above code for gTTs project in raspberry pi and I had already installed gTTs in to my pi by using below code.

pip3 install gTTs

I got below error after running py script

$ python test2.py
Traceback (most recent call last):
  File "test2.py", line 3, in <module>
    tts = gTTS(text=blabla, lang='en')
NameError: name 'gTTS' is not defined

So anyone please help me about this problem.

from gtts import gTTS
blabla = ("Spoken text")
tts = gTTS(text=blabla, lang='en')
tts.save("test.mp3")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM