Play audio without mouse

In new version Anki 2.1.46, if the card contents several audio files in the “question” and “answer” fields how can i play all the files without using the mouse?

1 Like

By default, Anki automatically plays audio on the front and back of cards. If you uncheck ‘automatically play audio’, Anki will not play audio until you press the replay audio key, r or F5.

Deck options are accessed by:

  • Clicking the gear icon on the Decks screen.
  • Selecting a deck on the Decks screen, and then clicking Options at the bottom of the screen.
  • Clicking on More > Options while in review mode.
  • Pressing o while in review mode.

https://docs.ankiweb.net/deck-options.html

2 Likes

Sorry it didn’t help. The program plays only the first file in each field (“answer” and “question”). Before the update, all files in the card were played, no matter how many of them, and now, 2.1.46, only the first one. I can play the rest of the audio files by clicking on the triangular icons. How can I do this without using a mouse?
(Version ⁨2.1.46 (94913ec2)⁩
Python 3.8.11 Qt 5.15.2 PyQt 5.15.4)

This is very strange. There’s no option in Anki to play only the first file. It’s either all or nothing depending on ‘automatically play audio’ in the deck options. Maybe try,

  1. Delete mpv.conf (if it exists) in the Anki2 folder.

    https://docs.ankiweb.net/files.html#file-locations

  2. Run Anki without add-ons by holding down the shift key.

    https://faqs.ankiweb.net/when-problems-occur.html

If it doesn’t help, try to turn on and off ‘automatically play audio’, just to make sure it works as expected.

If it doesn’t help, maybe upload a test deck with media included (just one card should be enough) somewhere (e.g. https://gofile.io/).

1.There is no file mpv.conf; 2. launching without add-ons did not solve the problem; 3. an attempt to turn on and off “automatically play audio” did not help; I post a test deck: Gofile - Free file sharing and storage platform

And I’m wondering how to play an audio file without using a mouse? I can select a triangular icon (play button) with the tab key, but neither “Space” nor “Enter” plays a sound

There’s nothing wrong with the test deck and it works fine for me. Anki automatically plays all the audio files and if I press R or F5 all the audio will be repeated.

Maybe try to create a new profile (File > Switch Profile) and import the same test deck there, to see if it works as expected or not.

And I’m wondering how to play an audio file without using a mouse? I can select a triangular icon (play button) with the tab key, but neither “Space” nor “Enter” plays a sound

It’s possible with a bit of code added to the front/back template by using a key that is not used by Anki to emulate a click action, e.g. z.

<script>
if (typeof myKeyListener === 'undefined') {
  var myKeyListener = true;
  document.addEventListener('keydown', function(event) {
    if (event.key == 'z') {
      document.activeElement.click();
    }
  });
}
</script>
1 Like

If the issue won’t go away with a new profile, maybe it’s related to mpv video player that is used by Anki to play audio files.

Something similar might happen if mpv pauses the audio file at the end of the playback but with default settings it shouldn’t do it and it could be a bug in mpv.

I’m not sure if the log file will show anything, but to check it, start Anki, open the Debug Console, copy-paste the following lines and press Ctrl+Return to create mpv.conf and tell mpv to show mpv window and create mpv.debug.log.txt in the Anki2 folder.

https://docs.ankiweb.net/misc.html#debug-console

import os
from aqt import mw
from aqt.sound import mpvManager
logfile = os.path.join(mw.pm.base, 'mpv.debug.log.txt')
path = os.path.expanduser(logfile)
with open(os.path.join(mw.pm.base, 'mpv.conf'), 'a') as f:
    f.write('log-file={}\n'.format(path))
print('log-file:', mpvManager.get_property('log-file'))
# restarting mpv to apply new settings
mpvManager.shutdown()
print('log-file:', mpvManager.get_property('log-file'))
mpvManager.set_property('force-window', 'yes');
mpvManager.set_property('ontop', 'yes');

Then review a card or two, you’ll see a mpv window, audio files will be played one by one and if everything is fine the title will say “No file - mpv” by the end of the audio playback.

изображение

In your case, the playback probably will be paused, the second file won’t be played and the window title will have some filename in it instead of “No file”.

If this is the case, it’s clear that mpv is a culprit, maybe upload mpv.debug.log.txt somewhere or try to install No Sound Fix (libmpv) - AnkiWeb to see if it helps. If it doesn’t, close Anki, download the latest mpv version from mpv player (Windows) - Browse /64bit at SourceForge.net and copy everything to C:\Program Files\Anki, then start Anki and review a few cards. If it doesn’t help, try again by downloading the oldest mpv version (mpv-x86_64-20180317-git-fbcf2bf.7z).

4 Likes

That’s work fine! I thank you!
Switching profile does not effect.
I will try to rebuild Anki with mplayer (i am using Freebsd)/
Can I add some keyboard shortcut to your code in (event.key == ‘z’) instead of “z”? For example Ctrl+Space?

For example Ctrl+Space?

(event.code === 'Space' && event.ctrlKey)

I will try to rebuild Anki with mplayer

As a possible alternative, here’s a simple add-on to tell Anki to use mplayer instead of mpv.

__init__.py
from aqt import mw
from aqt.sound import av_player, SimpleMplayerSlaveModePlayer
from aqt.utils import showWarning

from distutils.spawn import find_executable

if find_executable('mplayer') is not None:
    mplayer = SimpleMplayerSlaveModePlayer(mw.taskman)
    mplayer.default_rank = 1
    av_player.players.append(mplayer)
else:
    showWarning("mplayer not found, reverting back to mpv")
2 Likes

Thank you for that:

— now all files are playing. And thanks for the link: KeyboardEvent.code - Web APIs | MDN

1 Like