Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

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

Closed
FaVorith opened this issue Nov 4, 2020 · 36 comments
Closed
Assignees
Milestone

Comments

@FaVorith
Copy link

FaVorith commented Nov 4, 2020

Hi,

The gTTS library used for this addon crashes with the following error message: "Unable to find token seed! Did https://translate.google.com change?"

Caught exception:
Traceback (most recent call last):
  File "aqt\webview.py", line 37, in cmd
  File "aqt\webview.py", line 123, in _onCmd
  File "aqt\webview.py", line 547, in _onBridgeCmd
  File "aqt\editor.py", line 403, in onBridgeCmd
  File "aqt\gui_hooks.py", line 1487, in __call__
  File "anki\hooks.py", line 594, in runFilter
  File "[redacted]Anki2\addons21\1128979221\edit.py", line 74, in onFocusLost
    if update_fields(note, field, allFields):
  File "[redacted]Anki2\addons21\1128979221\behavior.py", line 270, in update_fields
    fill_sound(hanzi, copy)
  File "[redacted]Anki2\addons21\1128979221\behavior.py", line 169, in fill_sound
    s = sound(hanzi, config['speech'])
  File "[redacted]Anki2\addons21\1128979221\sound.py", line 51, in sound
    return '[sound:%s]' % AudioDownloader(hanzi, source).download()
  File "[redacted]Anki2\addons21\1128979221\tts.py", line 50, in download
    self.func()
  File "[redacted]Anki2\addons21\1128979221\tts.py", line 56, in get_google
    tts.save(self.path)
  File "[redacted]Anki2\addons21\1128979221\lib\gtts\tts.py", line 243, in save
    self.write_to_fp(f)
  File "[redacted]Anki2\addons21\1128979221\lib\gtts\tts.py", line 183, in write_to_fp
    part_tk = self.token.calculate_token(part)
  File "[redacted]Anki2\addons21\1128979221\lib\gtts_token\gtts_token.py", line 28, in calculate_token
    seed = self._get_token_key()
  File "[redacted]Anki2\addons21\1128979221\lib\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?

This is a known issue in gTTS: pndurette/gTTS#232
There are some workarounds mention in the issue - would it be possible to work with one of these in the addon? Otherwise the addon will crash on almost every card...

Thanks and regards,
Fabian

@mvrloc
Copy link

mvrloc commented Nov 4, 2020

This is also happening to me and some other people on Anki forums. Pls update when possible

@fidelhuang1
Copy link

I also encountered the same problem, and the response was very slow

@3ter
Copy link
Contributor

3ter commented Nov 4, 2020

@FaVorith Thanks for getting all the resources ready.

If you change the file .local/share/Anki2/addons21/1128979221/tts.py from line 54 to

    def get_google(self):
        tts = gTTS(self.text, lang=self.lang)
        # Code inserted from https://github.com/pndurette/gTTS/issues/232
        count=1
        while True:
            try:
                tts.save(self.path)
                break
            except:
                print('got the issue '+str(count))
                count+=1
        # The following line was there before
        # tts.save(self.path)

it is going to work again (although it's going to take a few seconds when it would otherwise run in the error).

@FaVorith
Copy link
Author

FaVorith commented Nov 5, 2020

Hi @3ter ,

Thanks for your quick support. This indeed works, although it does take quite a long time to eventually fill out the fields (but much better than having to restart Anki all the time).
How does the add-on update mechanism work? Will the next add-on update simply overwrite my changes or will I have to deal with a conflicting file and not get future bug fixes?

Thanks and regards,
Fabian

@mvrloc
Copy link

mvrloc commented Nov 5, 2020

Could someone explain the fix in layman's terms? Tried to do the above but it didn't work for me so I'm guessing I didn't do it correctly

3ter added a commit to 3ter/chinese-support-redux that referenced this issue Nov 5, 2020
@3ter
Copy link
Contributor

3ter commented Nov 5, 2020

@mvrloc The code fails on tts.save(self.path) as discovered in the source mentioned by @FaVorith . This fix merely repeatedly calls this save function until it works (that's why it takes a few seconds more, but doesn't crash).

I recommend to replace the file contents of .local/share/Anki2/addons21/1128979221/tts.py with the changes I've made in my forked repo which you can find here.

@FaVorith Afaik all files are replaced when an addon is updated.

@mvrloc
Copy link

mvrloc commented Nov 5, 2020

@mvrloc The code fails on tts.save(self.path) as discovered in the source mentioned by @FaVorith . This fix merely repeatedly calls this save function until it works (that's why it takes a few seconds more, but doesn't crash).

@3ter Thanks it seems to be working as you describe now. Slow but no crashes. Thanks so much!

@CatherineKatia
Copy link

Hello! I sincerely apologise for asking but could one of you guide me step by step on how to do the above steps? I don't understand where to locate the file that I am supposed to amend to fix the current crash. I have no coding experience whatsoever I am afraid. I have been unable to study for the past few days before of the crash issue and would really need to fix it to be able to proceed. Thank you so much in advance to all of you!

@mvrloc
Copy link

mvrloc commented Nov 6, 2020

@CatherineKatia Hi! Are you using Windows? If so this is how I did it. Each step is a click through on explorer.
This PC > Local Disk (C) > Users > yourname > AppData > Roaming > Anki2 > addons21 > 1128979221 > tts.py
AppData is a hidden folder that doesn't always show up. I forgot how to make it show but you can Google that bit quickly.
Open tts.py with Notepad. I used Notepad ++ which you can download online, it's just so you can see the line numbers.
Once that's open, scroll down to line 54. It's the one that starts after the block that begins with "def download" so Ctrl+F to search for that, it ends with "return basename(self.path)" and under that is line 54.
image
This picture isn't line 54, it starts after where I drew the arrow. I realise it looks a bit vague in standard notepad.
Then copy @3ter 's code as above from there until the line "def get_baidu(self):".
Save, restart Anki, should work.
Also anyone else feel free to make these instructions simpler, this is how I did it and it took me a while because I don't code and couldn't find the file for ages lol

@CatherineKatia
Copy link

@mvrloc Oh wow!! Thank you so much for such a clear step by step explanation, it worked like a charm! I am beyond grateful!!! Thank you again for taking the time and so kindly explaining everything . Have a lovely day!

@psii
Copy link

psii commented Nov 16, 2020

2021-01-30: Updated instructions because Google changed their TTS service again

2021-02-15: Make sure to use gTTS version 2.2.2

The gTTS project just released a new version 2.2.2 that fixes the google translation. Copying the new gTTS code over the one shipped in this Anki extension solved it for me. Here are the steps (animated version):

  1. Download the gTTS code at https://github.com/pndurette/gTTS
  2. Go into the Anki extension folder where the old gTTS is located. For me, this is /home/psii/.local/share/Anki2/addons21/1128979221/lib/
  3. Remove (or backup) gtts and gtts_token (gtts_token is no longer needed for 2.2.2)
  4. Copy the gtts folder from (1) to this lib folder.

Old Instructions

2021-02-15: With the recent release of gTTS 2.2.2 the following instructions are outdated and are just listed here for reference.

For some reason, Google removed the zh-cn, zh-CN, and zh-tw language codes but after giving it a try, zh works. Adapting to this change is a bit tricker as it requires editing a few files the plugin folder. The following files need to be changed:

  • config.json
  • config_saved.json
  • meta.json
  • gui.py
  • lib/gtts/lang.py
  • tts.py

The changes are always the same: Via the search&replace function of your text editor, change all occurences of zh-cn to zh. Optionally, remove all lines containing zh-tw. You can look at this commit to get an idea.

If you don't feel comfortable manually editing the files in your Anki plugin folder, you can download them from the chinese subfolder of my repository, which exactly contains the changes described in this comment.

(Original idea by @gpshearn, thank you!)

@mvrloc
Copy link

mvrloc commented Nov 16, 2020

@psii thanks for letting us know
It finally doesn't lag for 30 seconds for each card!!!!

@CatherineKatia
Copy link

@psii Great, thank you so much for letting us know!

3ter added a commit to 3ter/chinese-support-redux that referenced this issue Nov 17, 2020
Fix jdlorimer#161.
Thanks to @psii for mentioning that the update fixes the
issue.
@yukoba
Copy link

yukoba commented Nov 22, 2020

There is no problem with using gTTS 2.2.1! Also, there is no problem deleting sleep(5).
https://github.com/luoliyan/chinese-support-redux/blob/2085a80923461b274cf23ba52970ceebe394e23c/chinese/fill.py#L158

@dgeranton
Copy link

The gTTS project just released a new version 2.2.1 that fixes the google translation. Copying the new gTTS code over the one shipped in this Anki extension solved it for me. Here are the steps:

1. Download the gTTS code at https://github.com/pndurette/gTTS

2. Go into the Anki extension folder where the old gTTS is located. For me, this is `/home/psii/.local/share/Anki2/addons21/1128979221/lib/`

3. Remove (or backup) `gtts` and `gtts_token` (`gtts_token` is no longer needed for `2.2.1`)

4. Copy the `gtts` folder from (1) to this `lib` folder.

It should now work without problems. It's even faster than before.

You right I fixe it but simply updating gtts and gtts-token depends. I have proposed a pull request hoping it accelerate the public update which is not simple for common people.

@frixo3190
Copy link

The gTTS project just released a new version 2.2.1 that fixes the google translation. Copying the new gTTS code over the one shipped in this Anki extension solved it for me. Here are the steps:

  1. Download the gTTS code at https://github.com/pndurette/gTTS
  2. Go into the Anki extension folder where the old gTTS is located. For me, this is /home/psii/.local/share/Anki2/addons21/1128979221/lib/
  3. Remove (or backup) gtts and gtts_token (gtts_token is no longer needed for 2.2.1)
  4. Copy the gtts folder from (1) to this lib folder.

It should now work without problems. It's even faster than before.

Thanks !!!!!!!

@nina-katharina
Copy link

Hello,
I think I have experienced the same problem but using Ankin on Mac (macOS big sur)!
Can someone maybe help me I'm out, I really rely on this program...

Debuginformationen:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.16
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-12-14 13:04:45
Möglicherweise beteiligte Erweiterungen: ⁨Chinese Support Redux v0140⁩

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 37, in cmd
File "aqt/webview.py", line 123, in _onCmd
File "aqt/webview.py", line 547, in _onBridgeCmd
File "aqt/editor.py", line 403, in onBridgeCmd
File "aqt/gui_hooks.py", line 1487, in call
File "anki/hooks.py", line 594, in runFilter
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/edit.py", line 74, in onFocusLost
if update_fields(note, field, allFields):
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/behavior.py", line 270, in update_fields
fill_sound(hanzi, copy)
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/behavior.py", line 169, in fill_sound
s = sound(hanzi, config['speech'])
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/sound.py", line 51, in sound
return '[sound:%s]' % AudioDownloader(hanzi, source).download()
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/tts.py", line 50, in download
self.func()
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/tts.py", line 56, in get_google
tts.save(self.path)
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib/gtts/tts.py", line 243, in save
self.write_to_fp(f)
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib/gtts/tts.py", line 183, in write_to_fp
part_tk = self.token.calculate_token(part)
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib/gtts_token/gtts_token.py", line 28, in calculate_token
seed = self._get_token_key()
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib/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?

@zacbennett
Copy link

@nina-katharina
You should be able to follow the instructions that psii posted above. The only difference will be where the anki folder is located.

Based on the error message, it looks like the folder you need to replace is located /Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib/gtts_token.

Let me know if you need help

@nina-katharina
Copy link

@zacbennett
thank you for your quick answer!! I did what you said but maybe I didn't do it right...
Now when I open Anki it shows me this:

Beim Laden von '⁨Chinese Support Redux v0140⁩':
⁨Traceback (most recent call last):
File "aqt/addons.py", line 211, in loadAddons
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/init.py", line 23, in
from . import main
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/main.py", line 30, in
from .edit import append_tone_styling, EditManager
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/edit.py", line 23, in
from .behavior import update_fields
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/behavior.py", line 19, in
from .color import colorize, colorize_dict, colorize_fuse
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/color.py", line 32, in
from .sound import extract_tags
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/sound.py", line 24, in
from .tts import AudioDownloader
File "/Users/nina/Library/Application Support/Anki2/addons21/1128979221/tts.py", line 18, in
from gtts import gTTS
ImportError: cannot import name 'gTTS' from 'gtts' (unknown location)

Do you know what I got wrong?

@zacbennett
Copy link

Sorry, my original instructions might not have been accurate. In /Users/nina/Library/Application Support/Anki2/addons21/1128979221/lib, there should be a folder called gtts. You should replace that folder with the gtts folder obtained from downloading the code here

Here's a gif that I copied from @psii in another thread that was helpful to me.
101559044-8141a880-39c0-11eb-98d5-a537211a3928

@nina-katharina
Copy link

@zacbennett
Thank you so much for your help, it works now!
Actually I thought I did the same yesterday but apparently I did not. But anyways, this helped a lot!!

@CharlesJ10
Copy link

I have been trying to use the solutions listed above to make gTTS work with a virtual assistant that I am developing but haven't had any progress.

I still receive the same errors even after implementing this solution below

@FaVorith Thanks for getting all the resources ready.

If you change the file .local/share/Anki2/addons21/1128979221/tts.py from line 54 to

    def get_google(self):
        tts = gTTS(self.text, lang=self.lang)
        # Code inserted from https://github.com/pndurette/gTTS/issues/232
        count=1
        while True:
            try:
                tts.save(self.path)
                break
            except:
                print('got the issue '+str(count))
                count+=1
        # The following line was there before
        # tts.save(self.path)

it is going to work again (although it's going to take a few seconds when it would otherwise run in the error).

The loop just keeps on running until I stop the program by myself. Is there any other thing I can do to resolve the issue?

@3ter
Copy link
Contributor

3ter commented Dec 17, 2020

@CharlesJ10 Yes, you can update the gTTs lib accordingly to this post.
The solution you've mentioned is now superseded by this one.

@CharlesJ10
Copy link

CharlesJ10 commented Dec 17, 2020

Okay, thank you.
I updated it but it still didn't work on my Python Debug Console for VsCode and on my command line.

psii added a commit to psii/chinese-support-redux that referenced this issue Jan 29, 2021
@CatherineKatia
Copy link

@psii Thank you so much for adding the solution for the recent issue (dated 30 Jan 2021, following Google latest TTS fix) so quickly !! I am very grateful to people like you who take the time to fix issues that affect us, and then patiently explain to us all how to apply the fix so we can all get on with our lives with Anki! :)

@CatherineKatia
Copy link

CatherineKatia commented Feb 1, 2021

Oh no, the fix stopped working after 2 new cards... It keeps crashing again. I completed all the steps though. Anyone would know how to diagnose why it is still not working for me? Many thanks!

This is the error I am getting when creating a new card :

Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Windows 10
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2021-02-01 11:01:39

Caught exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\lib\gtts\tts.py", line 271, in write_to_fp
r.raise_for_status()
File "requests\models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://www.google.com/sorry/index?continue=https://translate.google.com/_/TranslateWebserverUi/data/batchexecute&q=EgRn96C2GNXI3oAGIhkA8aeDS_6oe2dn_SNdgo8S-1ERF6X49-9TMgFy

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "aqt\webview.py", line 37, in cmd
File "aqt\webview.py", line 123, in _onCmd
File "aqt\webview.py", line 547, in _onBridgeCmd
File "aqt\editor.py", line 403, in onBridgeCmd
File "aqt\gui_hooks.py", line 1487, in call
File "anki\hooks.py", line 594, in runFilter
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\edit.py", line 74, in onFocusLost
if update_fields(note, field, allFields):
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\behavior.py", line 270, in update_fields
fill_sound(hanzi, copy)
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\behavior.py", line 169, in fill_sound
s = sound(hanzi, config['speech'])
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\sound.py", line 51, in sound
return '[sound:%s]' % AudioDownloader(hanzi, source).download()
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\tts.py", line 50, in download
self.func()
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\tts.py", line 56, in get_google
tts.save(self.path)
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\lib\gtts\tts.py", line 312, in save
self.write_to_fp(f)
File "C:\Users\User\AppData\Roaming\Anki2\addons21\1128979221\lib\gtts\tts.py", line 275, in write_to_fp
raise gTTSError(tts=self, response=r)
gtts.tts.gTTSError: 429 (Too Many Requests) from TTS API. Probable cause: Unknown

@psii
Copy link

psii commented Feb 2, 2021

@CatherineKatia, thank you for your kind words.

I think your problem may just be a temporary one. The error message hints at this (too many requests). Have you tried it again at a later time? I just created around 20 cards without any issues. So it is difficult to say why there is a problem at your end. Maybe you were just unlucky because Google restricted their service in your area to push back against some fraudulent behaviour.

@CatherineKatia
Copy link

@psii Yes, thank you! It started working again!

@sikulas21
Copy link

Hey there,
does anyone know if there is a solution for Windows aswell? I can't find the folders described on my Laptop. I hope that's not a stupid questions, I am not really into coding but am really desperate to fix this problem.
Thanks a lot :)

@3ter
Copy link
Contributor

3ter commented Feb 3, 2021

@sikulas21 You only need to find the addons folder location. The layout inside is platform independent.
Start Anki and open Addons (e.g. with ctrl + shift + A or from the menu "Tools").
image
Then select "View Files". Your explorer opens and you'll find a folder named "1128979221". That's where you'll find the structure to make the necessary changes.

@sikulas21
Copy link

sikulas21 commented Feb 3, 2021 via email

@BdKellogg
Copy link

Hi,
I rely on this add-on, and I don't have skills in fixing code like this myself, so I really hope somebody can help me with this.
At first I had the same error message, "unable to find token seed". But now, after doing everything here, I have a different one, and it's also preventing me from using the add-on. It reads:

Anki 2.1.29 (bbff62bf) Python 3.8.0 Qt 5.14.1 PyQt 5.14.1
Platform: Windows 10
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2021-02-13 14:01:24

Caught exception:
Traceback (most recent call last):
File "aqt\webview.py", line 37, in cmd
File "aqt\webview.py", line 123, in _onCmd
File "aqt\webview.py", line 544, in _onBridgeCmd
File "aqt\editor.py", line 397, in onBridgeCmd
File "aqt\gui_hooks.py", line 1467, in call
File "lib\site-packages\anki\hooks.py", line 594, in runFilter
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\edit.py", line 74, in onFocusLost
if update_fields(note, field, allFields):
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\behavior.py", line 270, in update_fields
fill_sound(hanzi, copy)
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\behavior.py", line 169, in fill_sound
s = sound(hanzi, config['speech'])
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\sound.py", line 51, in sound
return '[sound:%s]' % AudioDownloader(hanzi, source).download()
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\tts.py", line 50, in download
self.func()
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\tts.py", line 55, in get_google
tts = gTTS(self.text, lang=self.lang)
File "C:\Users\kello\AppData\Roaming\Anki2\addons21\1128979221\lib\gtts\tts.py", line 147, in init
raise ValueError("Language not supported: %s" % lang)
ValueError: Language not supported: zh-cn

I've gone through every file that said "zh-cn" that's been mentioned on this thread, and changed it to "zh". Other than that, I don't know what to get from the error message. What's the issue? Thanks in advance, I appreciate any help I can get.

@psii
Copy link

psii commented Feb 14, 2021

@BdKellogg: It seems that you missed replacing zh-cn with zh in at least one of the files in your Anki directory. Maybe you forgot to also update your private configuration files (e.g. config_saved.json). I recommend using Notepad++, which is a neat text file editor that can search through all files of a directory.

@noinkling
Copy link

noinkling commented Feb 15, 2021

Note that as of gtts v2.2.2 you don't need to replace all the uses of zh-cn or zh-tw anymore as they're coded to fall back automatically.

Actually it looks like the country part just needed to be capitalized (i.e: zh-TW), so with this version the Taiwan voice is working again.

In other words, just replace the gtts folder, no need to do anything else if you downloaded the latest version of gtts.

If you already made the other changes you might want to change them back first (easiest way is probably just to delete the addon and redownload it).

@BdKellogg
Copy link

BdKellogg commented Feb 15, 2021

I see. I had replaced my gtts with 2.2.1. Just did what @noinkling said and it seems to be working so far. Thanks!

Edit: I made this comment shortly after I tried the fix, and it worked for a little bit. But soon after I made this comment it stopped working. BUT I found a way out.
I figured out that since it was a problem with gtts, I just had to switch my add-on settings to use Baidu Translate instead of Google. If you click "Chinese" at the top, "Search Engine", and then Baidu, it works just fine.
I hope this was helpful; I realize maybe this was obvious to other people and went without saying, but I hadn't realized it before and it helped me.

@jdlorimer jdlorimer self-assigned this Mar 25, 2021
@jdlorimer jdlorimer added this to the v1.0 milestone Mar 25, 2021
@jdlorimer
Copy link
Owner

Please reopen this ticket if the latest version does not fully address the issue.

I'll be uploading to AnkiWeb later in the day.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests