aqt.sound#
Attributes#
Classes#
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
A player that invokes a new process for each tag to play. |
|
A player that invokes a new process for each tag to play. |
|
A player that invokes a new process for each tag to play. |
|
Class for communication with the mpv media player via unix socket |
|
A player that invokes a new process for each tag to play. |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Functions#
|
|
|
|
|
Encode the provided wav file to .mp3, and call on_done() with the path. |
|
|
|
|
|
|
|
|
|
Add play icons into the HTML. |
|
eg. if pycmd is 'play:q:0', play the first audio on the question side. |
|
|
|
Module Contents#
- aqt.sound.OnDoneCallback#
- class aqt.sound.Player#
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstractmethod play(tag: anki.sound.AVTag, on_done: OnDoneCallback) None#
Play a file.
When reimplementing, make sure to call gui_hooks.av_player_did_begin_playing(self, tag) on the main thread after playback begins.
- abstractmethod rank_for_tag(tag: anki.sound.AVTag) int | None#
How suited this player is to playing tag.
AVPlayer will choose the player that returns the highest rank for a given tag.
If None, this player can not play the tag.
- stop() None#
Optional.
If implemented, the player must not call on_done() when the audio is stopped.
- seek_relative(secs: int) None#
Jump forward or back by secs. Optional.
- toggle_pause() None#
Optional.
- shutdown() None#
Do any cleanup required at program termination. Optional.
- aqt.sound.AUDIO_EXTENSIONS#
- aqt.sound.is_audio_file(fname: str) bool#
- class aqt.sound.SoundOrVideoPlayer#
Bases:
PlayerHelper class that provides a standard way to create an ABC using inheritance.
- default_rank = 0#
- rank_for_tag(tag: anki.sound.AVTag) int | None#
How suited this player is to playing tag.
AVPlayer will choose the player that returns the highest rank for a given tag.
If None, this player can not play the tag.
- class aqt.sound.SoundPlayer#
Bases:
PlayerHelper class that provides a standard way to create an ABC using inheritance.
- default_rank = 0#
- rank_for_tag(tag: anki.sound.AVTag) int | None#
How suited this player is to playing tag.
AVPlayer will choose the player that returns the highest rank for a given tag.
If None, this player can not play the tag.
- class aqt.sound.VideoPlayer#
Bases:
PlayerHelper class that provides a standard way to create an ABC using inheritance.
- default_rank = 0#
- rank_for_tag(tag: anki.sound.AVTag) int | None#
How suited this player is to playing tag.
AVPlayer will choose the player that returns the highest rank for a given tag.
If None, this player can not play the tag.
- class aqt.sound.AVPlayer#
-
- interrupt_current_audio = True#
- current_caller: Any = None#
- current_caller_interrupted = False#
- play_tags(tags: list[anki.sound.AVTag]) None#
Clear the existing queue, then start playing provided tags.
- append_tags(tags: list[anki.sound.AVTag]) None#
Append provided tags to the queue, then start playing them if the current player is idle.
- queue_is_empty() bool#
- stop_and_clear_queue() None#
- stop_and_clear_queue_if_caller(caller: Any) None#
- clear_queue_and_maybe_interrupt() None#
- play_file(filename: str) None#
Play the provided path.
SECURITY: Filename may be an arbitrary path. For filenames coming from a collection, you should only ever use the os.path.basename(filename) as the filename.
- play_file_with_caller(filename: str, caller: Any) None#
Play the provided path, noting down the caller.
SECURITY: Filename may be an arbitrary path. For filenames coming from a collection, you should only ever use the os.path.basename(filename) as the filename.
- insert_file(filename: str) None#
Place the provided path at the top of the playlist.
SECURITY: Filename may be an arbitrary path. For filenames coming from a collection, you should only ever use the os.path.basename(filename) as the filename.
- toggle_pause() None#
- seek_relative(secs: int) None#
- shutdown() None#
- aqt.sound.av_player#
- aqt.sound.si = None#
- aqt.sound.retryWait(proc: subprocess.Popen) int#
- class aqt.sound.SimpleProcessPlayer(taskman: aqt.taskman.TaskManager, media_folder: str | None = None)#
Bases:
PlayerA player that invokes a new process for each tag to play.
- args: list[str] = []#
- env: dict[str, str] | None = None#
- play(tag: anki.sound.AVTag, on_done: OnDoneCallback) None#
Play a file.
When reimplementing, make sure to call gui_hooks.av_player_did_begin_playing(self, tag) on the main thread after playback begins.
- stop() None#
Optional.
If implemented, the player must not call on_done() when the audio is stopped.
- class aqt.sound.SimpleMpvPlayer(taskman: aqt.taskman.TaskManager, base_folder: str, media_folder: str)#
Bases:
SimpleProcessPlayer,VideoPlayerA player that invokes a new process for each tag to play.
- default_rank = 1#
- class aqt.sound.SimpleMplayerPlayer(taskman: aqt.taskman.TaskManager, media_folder: str | None = None)#
Bases:
SimpleProcessPlayer,SoundOrVideoPlayerA player that invokes a new process for each tag to play.
- class aqt.sound.MpvManager(base_path: str, media_folder: str)#
Bases:
aqt.mpv.MPV,SoundOrVideoPlayerClass for communication with the mpv media player via unix socket based JSON IPC. It adds a few usable methods and a callback API.
To automatically register methods as event callbacks, subclass this class and define specially named methods as follows:
- def on_file_loaded(self):
# This is called for every ‘file-loaded’ event. …
- def on_property_time_pos(self, position):
# This is called whenever the ‘time-pos’ property is updated. …
Please note that callbacks are executed inside a separate thread. The MPV class itself is completely thread-safe. Requests from different threads to the same MPV instance are synchronized.
- default_argv = ['--idle', '--no-terminal', '--force-window=no', '--ontop', '--audio-display=no',...#
- media_folder#
- executable#
- on_init() None#
- play(tag: anki.sound.AVTag, on_done: OnDoneCallback) None#
Play a file.
When reimplementing, make sure to call gui_hooks.av_player_did_begin_playing(self, tag) on the main thread after playback begins.
- stop() None#
Optional.
If implemented, the player must not call on_done() when the audio is stopped.
- toggle_pause() None#
Optional.
- seek_relative(secs: int) None#
Jump forward or back by secs. Optional.
- on_property_idle_active(value: bool) None#
- shutdown() None#
Do any cleanup required at program termination. Optional.
- togglePause#
- seekRelative#
- queueFile(file: str) None#
- clearQueue() None#
- class aqt.sound.SimpleMplayerSlaveModePlayer(taskman: aqt.taskman.TaskManager, media_folder: str)#
Bases:
SimpleMplayerPlayerA player that invokes a new process for each tag to play.
- media_folder#
- command(*args: Any) None#
Send a command over the slave interface.
The trailing newline is automatically added.
- seek_relative(secs: int) None#
Jump forward or back by secs. Optional.
- toggle_pause() None#
Optional.
- aqt.sound.encode_mp3(mw: aqt.AnkiQt, src_wav: str, on_done: collections.abc.Callable[[str], None]) None#
Encode the provided wav file to .mp3, and call on_done() with the path.
- class aqt.sound.Recorder(output_path: str)#
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- STARTUP_DELAY = 0.3#
- output_path#
- start(on_done: collections.abc.Callable[[], None]) None#
Start recording, then call on_done() when started.
- stop(on_done: collections.abc.Callable[[str], None]) None#
Stop recording, then call on_done() when finished.
- duration() float#
Seconds since recording started.
- on_timer() None#
Will be called periodically.
- class aqt.sound.QtAudioInputRecorder(output_path: str, mw: aqt.AnkiQt, parent: QWidget)#
Bases:
RecorderHelper class that provides a standard way to create an ABC using inheritance.
- mw#
- start(on_done: collections.abc.Callable[[], None]) None#
Start recording, then call on_done() when started.
- stop(on_done: collections.abc.Callable[[str], None]) None#
Stop recording, then call on_done() when finished.
- class aqt.sound.NativeMacRecorder(output_path: str)#
Bases:
RecorderHelper class that provides a standard way to create an ABC using inheritance.
- start(on_done: collections.abc.Callable[[], None]) None#
Start recording, then call on_done() when started.
- stop(on_done: collections.abc.Callable[[str], None]) None#
Stop recording, then call on_done() when finished.
- class aqt.sound.RecordDialog(parent: QWidget, mw: aqt.AnkiQt, on_success: collections.abc.Callable[[str], None])#
Bases:
QDialog- mw#
- accept() None#
- reject() None#
- aqt.sound.record_audio(parent: QWidget, mw: aqt.AnkiQt, encode: bool, on_done: collections.abc.Callable[[str], None]) None#
- aqt.sound.clearAudioQueue() None#
- aqt.sound.play(filename: str) None#
- aqt.sound.playFromText(text: Any) None#
- aqt.sound.mpvManager: MpvManager | None = None#
- aqt.sound.av_refs_to_play_icons(text: str) str#
Add play icons into the HTML.
When clicked, the icon will call eg pycmd(‘play:q:1’).
- aqt.sound.play_clicked_audio(pycmd: str, card: anki.cards.Card) None#
eg. if pycmd is ‘play:q:0’, play the first audio on the question side.
- aqt.sound.setup_audio(taskman: aqt.taskman.TaskManager, base_folder: str, media_folder: str) None#
- aqt.sound.cleanup_audio() None#