diff --git a/proto/anki/frontend.proto b/proto/anki/frontend.proto index 1f6b23101..03a9ffec6 100644 --- a/proto/anki/frontend.proto +++ b/proto/anki/frontend.proto @@ -31,6 +31,8 @@ service FrontendService { // Save colour picker's custom colour palette rpc SaveCustomColours(generic.Empty) returns (generic.Empty); + // Plays an audio tag at an index in a specific card + // If the index is blank, plays all audio on that side rpc PlayAudio(PlayAudioRequest) returns (generic.Empty); } @@ -48,6 +50,6 @@ message SetSchedulingStatesRequest { message PlayAudioRequest { bool answer_side = 1; - uint32 index = 2; + optional uint32 index = 2; uint64 cid = 3; } \ No newline at end of file diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index c8e145f1d..3657379d1 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -46,7 +46,7 @@ from aqt.operations import on_op_finished from aqt.operations.deck import update_deck_configs as update_deck_configs_op from aqt.progress import ProgressUpdate from aqt.qt import * -from aqt.sound import play_clicked_audio_with_index +from aqt.sound import play_tags from aqt.theme import ThemeManager from aqt.utils import aqt_data_path, show_warning, tr @@ -688,7 +688,12 @@ def next_card_data() -> bytes: def play_audio(): req = PlayAudioRequest.FromString(request.data) card = aqt.mw.col.get_card(CardId(req.cid)) - play_clicked_audio_with_index(req.index, req.answer_side, card) + # TODO: Pass tags with next_card_data rather than rendering the card here. + tags = card.answer_av_tags() if req.answer_side else card.question_av_tags() + if req.index is None: + play_tags(tags) + else: + play_tags([tags[req.index]]) post_handler_list = [ diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index c7896b34b..2a2169079 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -925,16 +925,11 @@ def play_clicked_audio(pycmd: str, card: Card) -> None: """eg. if pycmd is 'play:q:0', play the first audio on the question side.""" play, context, str_idx = pycmd.split(":") idx = int(str_idx) - play_clicked_audio_with_index(idx, context == "q", card) + tags = card.question_av_tags() if context == "q" else card.answer_av_tags() + play_tags([tags[idx]]) -def play_clicked_audio_with_index(index: int, answer_side: bool, card: Card): - if answer_side: - tags = card.answer_av_tags() - else: - tags = card.question_av_tags() - av_player.play_tags([tags[index]]) - +play_tags = av_player.play_tags # Init defaults ########################################################################## diff --git a/ts/routes/reviewer/reviewer.ts b/ts/routes/reviewer/reviewer.ts index d22f9482d..2c76ba9b9 100644 --- a/ts/routes/reviewer/reviewer.ts +++ b/ts/routes/reviewer/reviewer.ts @@ -41,10 +41,14 @@ export class ReviewerState { addEventListener("message", this.onMessage.bind(this)); } + playAudio(answerSide: boolean, index?: number) { + playAudio({ answerSide, index, cid: this.currentCard!.card!.id }); + } + onMessage(e: MessageEvent) { switch (e.data.type) { case "audio": { - playAudio({ answerSide: e.data.answerSide, index: e.data.index, cid: this.currentCard!.card!.id }); + this.playAudio(e.data.answerSide, e.data.index); break; } } @@ -108,6 +112,7 @@ export class ReviewerState { const question = resp.nextCard?.front || ""; this.updateHtml(question, resp?.nextCard?.css, resp?.nextCard?.bodyClass); + this.playAudio(false) this.beginAnsweringMs = Date.now(); } @@ -118,6 +123,7 @@ export class ReviewerState { public showAnswer() { this.answerShown.set(true); + this.playAudio(true) this.updateHtml(this._cardData?.back || ""); }