aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/audio.js
diff options
context:
space:
mode:
authorsabs <sabs@sobs.moe>2019-11-09 13:51:53 -0800
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-09 20:58:09 -0500
commitfd17a0fccd54229bf071899be96dbdab3cd12f02 (patch)
tree356d2ec73af08db8d2f53ecde9274413ad3d2bf8 /ext/mixed/js/audio.js
parent3e864c44c379ae3c5f5c046ca2c2cd9155b6b7e0 (diff)
Remove Download check when resolving Audio data
There is a bug (seemingly unreported) in Yomichan where an Anki card will not contain any audio if the JapanesePod101 audio source trumps a secondary audio source (e.g. JapanesePod101-alternate) where the jpod101 source can't find the word requested. For example, そして has an audio entry in the alternate source but not the standard source. (Alternatively, there may be a bug in the jpod101 audioUrlBuilder, because I've only noticed this problem with hiragana-only expressions. JPod101 may not host those on the same url scheme any more. I'm not sure how to fix that, though, and the bug I'm addressing here does still persist). The reason this happens is that audioGetFromUrl uses downloaded audio to effectively check for a 404 (by examining the audio duration), but that check doesn't happen when an Anki card is being created (i.e. "download" is set, which I've changed to "willDownload" here). This change removes that check, but retains the will-download intent information to prevent attempts to download tts data, which AnkiConnect cannot do. I've also added a short explanation as to why the download check happens where it does. I think the unused audio object will get garbage collected since it's not referenced again, but I've explicitly unset it as well.
Diffstat (limited to 'ext/mixed/js/audio.js')
-rw-r--r--ext/mixed/js/audio.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js
index cf8b8d24..8198f5ec 100644
--- a/ext/mixed/js/audio.js
+++ b/ext/mixed/js/audio.js
@@ -88,19 +88,15 @@ class TextToSpeechAudio {
}
-function audioGetFromUrl(url, download) {
+function audioGetFromUrl(url, willDownload) {
const tts = TextToSpeechAudio.createFromUri(url);
if (tts !== null) {
- if (download) {
- throw new Error('Download not supported for text-to-speech');
+ if (willDownload) {
+ throw new Error('AnkiConnect does not support downloading text-to-speech audio.');
}
return Promise.resolve(tts);
}
- if (download) {
- return Promise.resolve(null);
- }
-
return new Promise((resolve, reject) => {
const audio = new Audio(url);
audio.addEventListener('loadeddata', () => {
@@ -115,7 +111,7 @@ function audioGetFromUrl(url, download) {
});
}
-async function audioGetFromSources(expression, sources, optionsContext, download, cache=null) {
+async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) {
const key = `${expression.expression}:${expression.reading}`;
if (cache !== null && cache.hasOwnProperty(expression)) {
return cache[key];
@@ -129,7 +125,11 @@ async function audioGetFromSources(expression, sources, optionsContext, download
}
try {
- const audio = await audioGetFromUrl(url, download);
+ const audio = await audioGetFromUrl(url, willDownload);
+ if (willDownload) {
+ // AnkiConnect handles downloading URLs into cards
+ audio = null
+ }
const result = {audio, url, source};
if (cache !== null) {
cache[key] = result;