Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find token seed! Did https://translate.google.com change ? #236

Closed
Morojs opened this issue Nov 7, 2020 · 2 comments
Closed

Comments

@Morojs
Copy link

Morojs commented Nov 7, 2020

I want to convert text to speech with gTTs in python3 ,my script has stopped working with the following Traceback .

SPEECH CLASS

# Import the required module for text  
# to speech conversion 
from gtts import gTTS 
# This module is imported so that we can  
# play the converted audio 
from subprocess import call
import IPython.display as ipd
import time
class Speech(object):
  
# Passing the text and language to the constructor,  

    def __init__(self,arg1=None,arg2=None):
        if arg1:
            self.filename=arg1
            self.cmd = '''
            curl -XPOST 'https://api.wit.ai/speech?v=20200513' \
            -i -L -H "Authorization: Bearer  \
            -H "Content-Type: audio/wave" --data-binary "@'''+self.filename+'.wav"'
        if arg2 :
            self.language=arg2['language']
            self.text=arg2['text']
            self.name=arg2['name']
# Passing the text and language to the engine,  
# here we have marked slow=False. Which tells  
# the module that the converted audio should  
# have a high speed 
            self.obj = gTTS(text=self.text, lang=self.language, slow=False) 
    
    
    def save(self):
        self.obj.save('audio_box/'+self.name+'.mp3')
        

    def apiSpeechToText(self) : 
        call(self.cmd,shell=True)
    
    def play(self):
        ipd.Audio(filename='audio_box/'+self.name+'.mp3')
        call('mpg321  audio_box/'+self.name+'.mp3',shell=True) 

MAIN "server.py"

def textToSpeech():
    with open('json/bot_voice.json') as f:
        data = json.load(f)
    for i in range(0,3):
        speech=Speech(None,
            {
            'language':"en",
            'text':data[0]['informations'][0][str(i)],
            'name':"bot-voice"+str(i)
            })
        speech.save()
        speech.play()

TRACEBACK

Traceback (most recent call last):
  File "server.py", line 55, in <module>
    textToSpeech()
  File "server.py", line 51, in textToSpeech
    speech.save()
  File "/home/hicham/hicham/workspace/python/sending_emails/python_smtp_server/Models/speech.py", line 32, in save
    self.obj.save('audio_box/'+self.name+'.mp3')
  File "/usr/local/lib/python3.6/dist-packages/gtts/tts.py", line 295, in save
    self.write_to_fp(f)
  File "/usr/local/lib/python3.6/dist-packages/gtts/tts.py", line 251, in write_to_fp
    prepared_requests = self._prepare_requests()
  File "/usr/local/lib/python3.6/dist-packages/gtts/tts.py", line 194, in _prepare_requests
    part_tk = self.token.calculate_token(part)
  File "/usr/local/lib/python3.6/dist-packages/gtts_token/gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "/usr/local/lib/python3.6/dist-packages/gtts_token/gtts_token.py", line 59, in _get_token_key
    "Unable to find token seed! Did https://translate.google.com change?"
ValueError: Unable to find token seed! Did https://translate.google.com change?
@deltaflyer4747
Copy link

looks like lang page changed. My script gets stuck on this:

Traceback (most recent call last):
File "/usr/local/sbin/talk", line 40, in
else: tts = gTTS(lang="en", text=tosay)
File "/usr/local/lib/python3.5/dist-packages/gtts/tts.py", line 129, in init
langs = tts_langs(self.tld)
File "/usr/local/lib/python3.5/dist-packages/gtts/lang.py", line 40, in tts_langs
langs.update(_fetch_langs(tld))
File "/usr/local/lib/python3.5/dist-packages/gtts/lang.py", line 76, in _fetch_langs
soup = BeautifulSoup(page.content, 'html.parser')
File "/usr/local/lib/python3.5/dist-packages/bs4/init.py", line 279, in init
markup, from_encoding, exclude_encodings=exclude_encodings)):
File "/usr/local/lib/python3.5/dist-packages/bs4/builder/_htmlparser.py", line 237, in prepare_markup
exclude_encodings=exclude_encodings)
File "/usr/local/lib/python3.5/dist-packages/bs4/dammit.py", line 366, in init
for encoding in self.detector.encodings:
File "/usr/local/lib/python3.5/dist-packages/bs4/dammit.py", line 264, in encodings
self.chardet_encoding = chardet_dammit(self.markup)
File "/usr/local/lib/python3.5/dist-packages/bs4/dammit.py", line 34, in chardet_dammit
return chardet.detect(s)['encoding']
File "/usr/local/lib/python3.5/dist-packages/chardet/init.py", line 38, in detect
detector.feed(byte_str)
File "/usr/local/lib/python3.5/dist-packages/chardet/universaldetector.py", line 211, in feed
if prober.feed(byte_str) == ProbingState.FOUND_IT:
File "/usr/local/lib/python3.5/dist-packages/chardet/charsetgroupprober.py", line 71, in feed
state = prober.feed(byte_str)
File "/usr/local/lib/python3.5/dist-packages/chardet/utf8prober.py", line 67, in feed
if self.coding_sm.get_current_charlen() >= 2:

@pndurette
Copy link
Owner

Duplicate of #232. A new version of gtts-token has been released. Until it's in the requirements (soon), you can explicitly update it to the latest with pip install -U gtts-token

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants