[Python] gTTS Doesn't Save MP3 Files

Discussão em 'Python' iniciado por Stack, Julho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create an artificial intelligence program using Python. I found out that I need gTTS but it doesn't save mp3 files. Help me, please.

    #gtts is imported
    def talkToMe(audio, lgg = 'en'):
    #print(audio)
    tts = gTTS(text = audio, lang = lgg)
    #tts.save('audio.mp3') #doesn't work
    with open("audio.mp3") as fp: #doesn't work
    tts.write_to_fp(fp)
    os.system('mpg123\mpg123.exe audio.mp3')


    Traceback (most recent call last):
    File "C:\Users\zigzag\Desktop\gtts_test1\main.py", line 9, in <module>
    talkToMe("hello")
    File "C:\Users\zigzag\Desktop\gtts_test1\main.py", line 7, in talkToMe
    tts.write_to_fp(fp)
    File "B:\Python36\lib\site-packages\gtts\tts.py", line 187, in write_to_fp
    part_tk = self.token.calculate_token(part)
    File "B:\Python36\lib\site-packages\gtts_token\gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
    File "B:\Python36\lib\site-packages\gtts_token\gtts_token.py", line 62, in _get_token_key
    a = re.search("a\\\\x3d(-?\d+);", tkk_expr).group(1)
    AttributeError: 'NoneType' object has no attribute 'group'

    Continue reading...

Compartilhe esta Página