vedxyz / kana

Possibly the best kana training page there is, with various practice modes
https://vedxyz.github.io/kana/
MIT License
5 stars 0 forks source link

New option to always play kana sounds #5

Open vedxyz opened 1 year ago

vedxyz commented 1 year ago

Moving this comment here since it's now unrelated to the bug issue it was initially under.


I'd like to have the option to let the kana sound always play before each reply/answer. Or to have the stroke order always show. But perhaps we can have both.

Currently, as a workaround, I use a userscript just for the strokes. And its far from perfect, it's the first time I created one. And at the time, I use it for https://djtguide.neocities.org/kana/ which is pretty similar.

(function() {
    'use strict';

 document.getElementById('input_box').addEventListener('input', function() {
        document.getElementById('tool_stroke').click();
 });
})();

I propose to add two CheckBox in "FreePracticeOptions.tsx" and "BruteForcePracticeOptions.tsx" or all other relevant mode options toggleState is at that moment just a placeholder.

          checked={toggleState}
          onChange={() => setToggleState(!toggleState)}
          label="Always play sound"
        />
           <Checkbox
          checked={toggleState}
          onChange={() => setToggleState(!toggleState)}
          label="Always show stroke order"
        />
      </Container>

Originally posted by @zDEFz in https://github.com/vedxyz/kana/issues/4#issuecomment-1502086390

vedxyz commented 1 year ago

Replying to @zDEFz:

Ah, now I understand. Yeah, playing sounds automatically for each kana had been suggested before elsewhere as well. I wouldn't mind adding another "General" option along the lines of "Play the sound for each kana automatically" (edit: as you've proposed), though I personally wouldn't get much use out of it since I prefer to keep rotating through the kana as fast as I can. And by that I mean 2-3 seconds per kana during the first ever attempts, then 0.5-1 seconds after that.

Consequently, I'm also not sure what the best time to play the kana would be. In your user script you have hooked to the input event, but kana romaji are only 1-3 characters long so there's not really much time (if at all) before you move onto to the next kana. Playing the sound immediately upon getting a new kana might also be weird since you're just spoiling the answer then? I couldn't really find an optimal solution last I thought about this, so the idea had gone into the backlog.

I suppose that's part of the answer to your question as to why there is a middle-ground. Having the sound play on request avoids the timing issues. What do you think is the ideal time to play the sound then? Immediately when a kana is shown? When the user begins to answer? Or some other instant?


On the other hand, stroke order is a different topic. I've opened a new issue to track that over at

which includes my current thoughts on it.

zDEFz commented 1 year ago

What do you think is the ideal time to play the sound then? Immediately when a kana is shown? When the user begins to answer? Or some other instant?

It depends. If I understand the situation properly, then the audio samples have varying lengths. To avoid overlapping those samples, we at least need the longest time a audio sample is and then add half a second as buffer. Or we get the length of the audio file before playing it to estimate the delay.

function getDuration(src: string, cb: (length: number) => void) {
  const audio = new Audio();
  audio.onloadedmetadata = () => {
    cb(audio.duration);
  };
  audio.src = src;
}

getDuration("https://www.example.com/sample.mp3", (length) => {
  console.log(`The length of the mp3 sample is ${length} seconds.`);
});

Ideally, audio samples are as short as possible to get through as efficient as possible, while staying helpful enough to improve learning as well. I am new to the japanese sounds, so I want it in the beginning to memorize it better.

Playing the sound immediately upon getting a new kana might also be weird since you're just spoiling the answer then?

Pronouncing the solution is not automatically leading the user to enter the correct answer. There are some slight differences, but it is of utmost importance to learn those as well. They may not be required when in muscle memory, though.

Pronouncing itself would be something interesting. Perhaps there is already a japanese voice input engine that we could add as a tip for practicing that. We wouldn't need to do any work for that, as long as such solutions exist.