[Userscript] KaniWani audio

Can you get the audio from jisho.org instead of wanikani?

On OSX/macOS, there is a hacky alternative I use (I have UK keyboard layout but you can modify to your own shortcuts below).

First enable Japanese Text-to-Speech:

  1. System Preferences > Accessibility > Speech > System Voice > Japanese Otoya (Male) or Kyoko (Female)
    • (You may need to go to “Customize…” first if you don’t see the Japanese voices in the list)
  2. Then enable the option to “Speak selected text when the key is pressed” and my current key is set to:
    Option+Esc

Once you have that setup, you can use Option+Esc on any highlighted text and the OS will read it out in a semi-decent robot voice. N.B. The reading/pitch accent isn’t always correct so it shouldn’t be considered native audio.

So in a KaniWani review session, when you enter your answer correctly and the kanji is displayed you can:

  1. Cmd+A (to select your answer’s kanji) then
  2. Option+Esc (to read out your selection)

You can automate the last part a little bit by using a macro recorder like a BetterTouchTool keyboard trigger:

  1. BetterTouchTool > Preferences > Advanced > Gestures > Keyboard
  2. Click “+ Add New Shortcut or Key Sequence”
  3. Click to record shortcut and hit “Cmd+§” (for example)
  4. Select “Trigger Other Keyboard Shortcut” and hit Cmd+A
  5. Click “Attach Additional Action”
  6. Select “Trigger Other Keyboard Shortcut” and hit Option+§

If you do all of the above, after correctly entering a KaniWani answer you can just hit “Cmd+§” and get audio.

That’s what I do anyway after trying this script and it not working… but I also use the system voice to read out kanji/kana in plenty of other places so it’s quite handy to have setup. Along with the Japanese/English Apple Dictionary for word lookups.

Edit:
I found I needed to add a short delay between the BetterTouchTool actions to make this more reliable. If you attach an additional action and use “Trigger Predefined Action > Auxiliary Actions > Delay Next Action” then drag it in to be ordered like in the image below it seems to work well:

56

I played around with the non-working script that @irrelephant posted, and I was able to get it working by scraping the WaniKani vocab page for the audio tag. You can try it out here: KaniWani audio

Note that because KaniWani is a single-page app, the current @match tags won’t work unless you do a refresh once you’re on the study or review page (but it’s not too cumbersome for me). It might be possible to avoid this by changing the @match to be on all of KaniWani, and adding special code that detects page navigations, but I haven’t done that yet.

2 Likes

It turns out that remembering to do a page refresh before starting reviews is too hard for me… haha. So I decided to just fix the script. It should work pretty much out of the box now, I think. Updated version is available here: KaniWani audio

6 Likes

Hi, thanks for sharing this!

When I go to KaniWani, Tampermonkey says that “No script is running”, even though I double checked to make sure the script is both installed and enabled. The same thing happened with the previous version you posted a while ago (even after going to review page and doing a page refresh).

I’m using Tampermonkey v4.8.41, Chromium Version 67.0.3396.99 (Official Build) and Ubuntu 17.10 (64-bit).

Oh interesting - I’m not completely sure why that would be the case. I use ViolentMonkey, but I tried it with TamperMonkey v4.8.41, and it seems to work for me.

By chance, do you use www.kaniwani.com instead of kaniwani.com? (I actually don’t know the difference between them, but I use the latter; I also can’t seem to log in to the former at all)

I modified the script’s @match to use a simpler form. Maybe try the newest script version and see if that works? KaniWani audio

2 Likes

It works now! :smiley:

I do use www.kaniwani.com! Actually, I just type k on the address bar and the browser just takes me there.

Thanks once again!

Thank you so much for doing this. I was on the verge of giving up and deleting kaniwani from my study routine when I decided to check one last time to see if the script had been fixed.

I added a J-key shortcut with the following:

// @require http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js

shortcut.add(“J”,function() {
playAudio();
},{
‘type’:‘keydown’,
‘disable_in_input’:true,
‘target’:document
});

You can add code blocks with triple backticks ```

Awesome, so happy this is working again! Was this written using API v1? Would it be possible to add a variable for changing the voice to male? Not sure if API v2 would need to be used. Thanks!

Got it, thanks.

This is a quick hack for the male voice:

Change:

var audioNode = domRoot.querySelector('audio');

To:

var audioNode = domRoot.querySelectorAll('audio')[1];

Is there anybody out there who can help me to get this to work on Safari on a Mac please?
I get as far as seeing the ‘PLAY AUDIO’ button but only with a continuously spinning dial.

1 Like

Finally noticed your reply haha that totally works, thank you!

1 Like

This script only produces audio for the very last review in a session and none of the prior reviews.
Is anyone else seeing this or able to get audio for their other reviews?

Hi @Kumirei, as I’ve seen you in this thread and you have been so helpful recently I was just hoping you might be able to shed some light on why this is happening … or point me to the man who can (it’s my guess that is you anyway).

I haven’t used KW for years so sadly I am of no help. Maybe @crumpet could help you

2 Likes

Without realising I had the auto-advance delay set to zero within settings which wasn’t giving the audio a chance to play. Setting to 1s appears to be ideal (if wishing to continue using auto-advance).
All is well again.

2 Likes

Glad you got it sorted

2 Likes

Looks like there has just been an update to this script that allows you to set auto-advance delay back to zero and have this script working perfectly again without the need for a delay at all.

Certainly speeds things up.

Thanks to whoever did this, whoever you are?

1 Like