1

Im trying to create a virtual assistant but I cant get the gTTS working (google text to speech) working and I cant seem to fix it

import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS

def speak(text):
    tts = gTTS(text = text, lang="en")
    filename = "voice.mp3"
    tts.save(filename)
    playsound.playsound(filename)

speak("hello i am bob")

This is the error im getting

File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 13, in <module>
    speak("hello i am bob")
  File "/Users/danielcaminero/Library/Mobile Documents/com~apple~CloudDocs/SJ-000/pyda/script.py", line 10, in speak
    tts.save(filename)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 295, in save
    self.write_to_fp(f)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 251, in write_to_fp
    prepared_requests = self._prepare_requests()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts/tts.py", line 194, in _prepare_requests
    part_tk = self.token.calculate_token(part)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/gtts_token/gtts_token.py", line 58, in _get_token_key
    raise ValueError(
ValueError: Unable to find token seed! Did https://translate.google.com change?

3 Answers3

0

I had the same error, until I upgrade gTTS-token

pip install gTTS-token --upgrade

And let me tell you as well that I have a Windows machine in which I run a Linux terminal. In that case I couldn't make it work (Nevertheless try it if this is your case). Hope it works!

0

There was an ISSUE with gtts depending on the version you were using that returned this token seed error.

The ISSUE has been closed and it seems updating go gtts version 2.1.2 and newest resolved the problem.

Obs: I personally used 2.2.1 today and everything worked as expected.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
0

I had the same problem on Windows. I've just uninstalled the module gtts and installed it again(now having the last version of it)

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 12 '22 at 06:03