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

Outdated gTTS and poor gTTS error handling #169

Open
ghost opened this issue Dec 3, 2020 · 24 comments
Open

Outdated gTTS and poor gTTS error handling #169

ghost opened this issue Dec 3, 2020 · 24 comments

Comments

@ghost
Copy link

ghost commented Dec 3, 2020

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.

Originally posted by @psii in #161 (comment)

@ghost
Copy link
Author

ghost commented Dec 3, 2020

image

This is what pops up when I did that

@benjewmin
Copy link

I got this error, then I reread directions. Try copying the gtts folder to lib (opposed to what I did which was copy gtts to its original location). The mp3 it made is still 0 bytes 🙄 . I'm open to ideas.

@benjewmin
Copy link

Re: I fixed my issue. The mp3 was created earlier when gtts didn't work, creating a 0B file. So when I tried making a card with the SAME characters, it checked for the file's existence and stopped at that. So, deleting the old 0B file made gtts fetch a new one which worked! Good luck.

@ghost
Copy link
Author

ghost commented Dec 4, 2020

I got this error, then I reread directions. Try copying the gtts folder to lib (opposed to what I did which was copy gtts to its original location). The mp3 it made is still 0 bytes 🙄 . I'm open to ideas.

Wait, what do you mean? Isn't the gtts folder's original location in the lib folder??? I'm so confused.

@benjewmin
Copy link

benjewmin commented Dec 4, 2020

Sorry for lack of info. I'm on my 2015 Mac Air, the original directories are lib\gTTS\gtts. When you "replace" gtts folder, the final structure should be lib\gtts. Hopefully this is clear!

@ghost
Copy link
Author

ghost commented Dec 4, 2020

I don't understand? my folders look like this, what do
image
image

@benjewmin
Copy link

Like I said, I'm on Mac OS 10.15.7:
The bottom line of your error may be indicative of your issue
"cannot import gTTS from gtts (unknown location)"? Sounds like it can't find gtts... I installed gtts with python-pip as well, not sure if that helped me, my error was ModuleNotFoundError: No module named 'gtts'
Maybe you need to add the lib directory to your search path? See if someone else had a similar issue with Anki or this plugin... Sorry for my lack of solution.

@bmasta101
Copy link

I'm also confused about what exactly to do with which files. I downloaded this folder and nested it under the original gtts folder, but am guessing this is incorrect as the problem still is not fixed. 1. did I download the correct new gtts? 2. Do I delete the old gtts and gtts_token folders or not? 3. Where should I drop the new gtts folder? (I'm on a 2014 Macbook Air, if that's relevant.) Thanks!

Screen Shot 2020-12-08 at 3 55 12 PM

@psii
Copy link

psii commented Dec 9, 2020

I'm sorry that my instructions caused so much confusion. I created a small screencast to hopefully clear things up.

gtts

@bmasta101
Copy link

@psii THANK YOU! It's totally working now.

@joeminicucci
Copy link

This is in pull request #171 , awaiting approval.

@moukabar
Copy link

Re: I fixed my issue. The mp3 was created earlier when gtts didn't work, creating a 0B file. So when I tried making a card with the SAME characters, it checked for the file's existence and stopped at that. So, deleting the old 0B file made gtts fetch a new one which worked! Good luck.

Thank you @psii for your awesome fix and @benjewmin for pointing out the cleanup when changing to the new gtts after previous failed trials. Made the system finally work for me.

@fultonm
Copy link

fultonm commented Jan 18, 2021

Workaround worked for me like a charm. Thank you

@JulienVincenot
Copy link

Hi,
This fixed the issue for me back in November, but now it seems the Google error is back。
I tried replacing gtts with the very last version from github, didn't do the trick. Any idea?
Thanks !

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue on the add-on support site.
Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.1 Qt 5.9.7 PyQt 5.13.2
Platform: Mac 10.12.6
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2021-01-28 16:41:56
Add-ons possibly involved: ⁨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/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/edit.py", line 74, in onFocusLost
if update_fields(note, field, allFields):
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/behavior.py", line 270, in update_fields
fill_sound(hanzi, copy)
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/behavior.py", line 169, in fill_sound
s = sound(hanzi, config['speech'])
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/sound.py", line 51, in sound
return '[sound:%s]' % AudioDownloader(hanzi, source).download()
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/tts.py", line 50, in download
self.func()
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/tts.py", line 56, in get_google
tts.save(self.path)
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/lib/gtts/tts.py", line 321, in save
self.write_to_fp(f)
File "/Users/julienvincenot/Library/Application Support/Anki2/addons21/1128979221/lib/gtts/tts.py", line 303, in write_to_fp
raise gTTSError(tts=self, response=r)
gtts.tts.gTTSError: 200 (OK) from TTS API. Probable cause: Unknown

@gpshearn
Copy link

This error is back now for me? I had already done this fix and it was working like a charm, but as of this evening I can make a single card, then it crashes. Restarting Anki fixes the problem, I can make a single card and then it crashes again when I try to make a second card.

@JulienVincenot
Copy link

as of this evening I can make a single card, then it crashes. Restarting Anki fixes the problem, I can make a single card and then it crashes again when I try to make a second card.

Actually for me it crashes every time. Did you check one thing : creating really a new word every time, i.e. a word that FOR SURE Anki didn't create a mp3 for? I noticed that when the crash happens for a new card/word, it still does create a mp3 but that one is always empty (0kb). So when you try to create it again, it will seem as it works (i.e., it doesn't crash), but there's actually no sound at all -> the card will refer to that previous empty file.

@gpshearn
Copy link

as of this evening I can make a single card, then it crashes. Restarting Anki fixes the problem, I can make a single card and then it crashes again when I try to make a second card.

Actually for me it crashes every time. Did you check one thing : creating really a new word every time, i.e. a word that FOR SURE Anki didn't create a mp3 for? I noticed that when the crash happens for a new card/word, it still does create a mp3 but that one is always empty (0kb). So when you try to create it again, it will seem as it works (i.e., it doesn't crash), but there's actually no sound at all -> the card will refer to that previous empty file.

Well wouldn't you know it, you are absolutely right. I just wasted a bunch of time restarting anki like a fool to add cards with an empty audio file. Nice. I guess I'll just stay posted on if anyone else figures out a workaround? I'm not a programmer so I'm afraid I won't be much help.

@psii
Copy link

psii commented Jan 29, 2021

I fixed it with this commit. For some reason, Google removed the zh-cn, zh-CN, and zh-tw langauge codes but after giving it a try, zh works. So I added it to the gTTS code as a valid language and changed the Anki-Plugin code accordingly.

I'm currently not sure how to make this easy for non-technical people. But I try.

Preliminary step: Make sure that you have applied the gTTS fix as explained here and here.

Then, in your Anki-Plugin folder (.../addons21/1128979221/) the following files need to be edited:

  • 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.

@benjewmin
Copy link

benjewmin commented Jan 29, 2021 via email

@gpshearn
Copy link

@psii thanks a lot for the help on this. I tried changing the files as you described, but I kept getting an error message. Ultimately I uninstalled the add-on and downloaded the commit you had uploaded, and pasted the file "chinese" containing all the json files and whatnot into my addons folder. Now it seems to be working without any issue. Thanks a lot for the help, seriously.

@JulienVincenot
Copy link

@psii amazing thank you so much, the steps you described helped me fix it completely it seems, didn't need to re-install.

@cd-a
Copy link

cd-a commented Jan 31, 2021

@psii Thanks a lot, that fixes it for me.

As much as I appreciate these things, it's getting out of hand. We should consider how we go from here with the repo, as no active maintainer is making it more and more difficult to keep up. See #174

@joeminicucci
Copy link

@liutianruikon In your particular case it looks like you reached your daily Google GTTS request limit

@jdlorimer
Copy link
Owner

Request limit aside, a new version of the add-on will be uploaded today with an up-to-date gTTS.

I'll leave this issue open while I figure out if we can show a better error message when the request limit is hit.

@jdlorimer jdlorimer self-assigned this Mar 25, 2021
@jdlorimer jdlorimer added the bug label Mar 25, 2021
@jdlorimer jdlorimer added this to the v1.0 milestone Mar 25, 2021
@jdlorimer jdlorimer changed the title 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: Outdated gTTS and poor gTTS error handling Mar 30, 2021
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

10 participants