jdlorimer / chinese-support-redux

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1128979221
GNU General Public License v3.0
101 stars 50 forks source link

Outdated gTTS and poor gTTS error handling #169

Open ghost opened 3 years ago

ghost commented 3 years ago

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 https://github.com/luoliyan/chinese-support-redux/issues/161#issuecomment-727697730

ghost commented 3 years ago

image

This is what pops up when I did that

benjewmin commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

benjewmin commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

gtts

bmasta101 commented 3 years ago

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

joeminicucci commented 3 years ago

This is in pull request #171 , awaiting approval.

moukabar commented 3 years ago

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 commented 3 years ago

Workaround worked for me like a charm. Thank you

JulienVincenot commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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:

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 commented 3 years ago

If the commit etc doesn’t work, when programs crash like this my first thought is permissions or missing folders. Let us know how it goes!

On Fri, Jan 29, 2021 at 8:59 AM psii notifications@github.com wrote:

I fixed it with this commit https://github.com/psii/chinese-support-redux/commit/dfebedeaba4d7b923bc9a9e550eb8ddfef3b3171. 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 https://github.com/luoliyan/chinese-support-redux/issues/161#issuecomment-727697730 and here https://github.com/luoliyan/chinese-support-redux/issues/169#issuecomment-741342038 .

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 https://github.com/psii/chinese-support-redux/commit/dfebedeaba4d7b923bc9a9e550eb8ddfef3b3171 to get an idea.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/luoliyan/chinese-support-redux/issues/169#issuecomment-769820916, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACIDRTDX3AYHP56S5LZTOKTS4K5LXANCNFSM4ULHA5MQ .

-- Benjamin Avery Ehrlich, BSME Electromechanical Engineer M: 267-721-9146 LinkedIn Github Portfolio (Coming Soon!)


E-Mail: behrlich2008@gmail.com Philadelphia, PA 19104 Drexel University, 2018

gpshearn commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 https://github.com/luoliyan/chinese-support-redux/issues/174

joeminicucci commented 3 years ago

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

jdlorimer commented 3 years ago

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.