Python GTTS/连接失败。可能原因:未知

2024-05-28 22:33:17 发布

您现在位置:Python中文网/ 问答频道 /正文

from playsound import playsound
from gtts import gTTS,gTTSError

 def playaudio(audio):
    playsound(audio)

def convert_to_audio(text):
    audio =gTTS(text)
    >- audio.save("textaud.mp3") -<
    playaudio("textaud.mp3")

convert_to_audio("my name is joe")

我用的是Python环境。 我在突出显示的行中得到一个错误

这个错误是:Failed to connect. Probable cause: Unknownhttps://i.stack.imgur.com/wZMVI.png

我尝试的解决方案是:

  1. 更新的窗口
  2. 已卸载和重新安装的gTTS

Tags: totextfromimportconvertdef错误mp3
1条回答
网友
1楼 · 发布于 2024-05-28 22:33:17

试着这样做

from playsound
from gtts import gTTS

def playaudio(audio):
    playsound(audio)

def convert_to_audio(text):
    audio =gTTS(text=text, lang='en', tld='com')
    audio.save("textaud.mp3")
    playaudio("textaud.mp3")

convert_to_audio("my name is joe")

相关问题 更多 >

    热门问题