Skip to content

Conversation

@suuvvy
Copy link

@suuvvy suuvvy commented Sep 5, 2025

Allows users to configure a custom audio source with sample sentence audio and corresponding text in addition to regular term audio.

Sample sentence audio is served via a separate JSON audio source. In order to allow for this, the schema has been extended by an optional sentence field. One possible implementation for such an audio source can be found here: https://github.com/suuvvy/yomitan-sentence-audio

In the term audio popup, users can select their preferred audio source for sentence audio by clicking the Anki card button while holding Crtl. There are two new markers that can be mapped to Anki fields, {sample-sentence-audio} and {sample-sentence-text}. If the user chooses a source without sentence property as preferred sentence audio source, neither {sample-sentence-audio} nor {sample-sentence-text} are mapped. The {audio} marker remains unaffected by this.

After playing audio from an audio source, that source is marked as either preferred (term) audio source or preferred sentence audio source depending on whether the underlying source has a sentence property. This also means the behavior stays the same for all existing audio sources.

A demonstration of the feature can be seen in the video below (remember to unmute):

yomitan_sentence_audio.mp4

This is my first time working with the yomitan codebase, so any suggestions to improve code quality are highly appreciated.

@suuvvy suuvvy requested a review from a team as a code owner September 5, 2025 19:23
@github-actions
Copy link

github-actions bot commented Sep 6, 2025

@Kuuuube Kuuuube added the kind/enhancement The issue or PR is a new feature or request label Sep 6, 2025
@Kuuuube
Copy link
Member

Kuuuube commented Sep 6, 2025

Tests failing. You can run npm run test to test locally yourself if it helps. You will need an Anki handlebars update, take a look at other prs that change handlebars for how to do this.

@suuvvy
Copy link
Author

suuvvy commented Sep 6, 2025

Thanks for the hint, I forget it doesn't run bundled with npm run build.

@suuvvy
Copy link
Author

suuvvy commented Sep 6, 2025

The test issues should be resolved now. On a separate note, if you want it for review, I can give you access to my custom audio source.

@StefanVukovic99
Copy link
Member

StefanVukovic99 commented Oct 20, 2025

I wouldn't mix fetching sample sentence text from an API with the audio system. I think a more natural approach would be to extend the existing {sentence} capabilities with {sentence-audio}, i.e. TTS audio sources that get audio for the sentence in which a word is scanned. Also exposing a {sentence} token in AudioDownloader._getCustomUrl along {language} etc.

Then a user could, with some finagling, setup a workflow to add sample sentences from e.g. Tatoeba, by scanning the same word in them. This would involve using the overwrite on duplicate behavior and setting up the duplicate behaviors for each field.

@suuvvy
Copy link
Author

suuvvy commented Oct 25, 2025

The entire point of the feature is that there are some people like myself who don't like TTS audio. You can already create an audio source that produces TTS audio and there is already an abundance of tools to create TTS for any given field in Anki, so adding anything like that to Yomitan does not make a lot of sense in my opinion.

The main idea behind this feature is that - once mature - you would save yourself the trouble of "mining" sentence audio altogether. You could just listen to, say, 10 example sentences, get an idea of the breadth of usage and then choose the example that works best for you. After that, you're already left with a complete vocabulary or audio card without a need for any additional tools or trying to find a suitable example on "immersionkit" or anything similar. It would also be helpful in situations where you may technically have audio associated with your sentence, but that audio isn't suitable for Anki cards due to sound effects etc.

@Kuuuube
Copy link
Member

Kuuuube commented Oct 27, 2025

I'm mostly fine with this but having to use ctrl means it doesnt work for mobile users. Not sure how this can be fixed gracefully.

I think I'm okay to merge this as-is if you can fix conflicts and add the new handlebars to the docs on the settings page help modal. It's a very niche feature that I don't expect to see much use out of but it seems fine.

Notably this feature existing would also allow a TTS source just fine and (to some extent) pulling example sentences from a source that is unaware of Yomitan's format (albeit probably lacking the sample sentence text).

@Kuuuube Kuuuube added area/anki The issue or PR is related to Anki integration area/audio The issue or PR is related to audio area/settings This issue or PR is related to settings. labels Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/anki The issue or PR is related to Anki integration area/audio The issue or PR is related to audio area/settings This issue or PR is related to settings. kind/enhancement The issue or PR is a new feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants