@readium/speech 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -3549,7 +3549,8 @@ class Go {
3549
3549
  await this.performSwap(
3550
3550
  async () => {
3551
3551
  const i = this.activeEngine.getCurrentVoice() ?? (typeof this.lastVoiceRequest == "object" ? this.lastVoiceRequest : null), s = i?.language || this.currentUtterances[this.desiredIndex]?.language || (typeof navigator < "u" ? navigator.language : "en");
3552
- return n = await this.pickBestFallbackVoice(s, i?.gender), this.fallbackProvider.createEngine(n ?? void 0);
3552
+ if (n = await this.pickBestFallbackVoice(s, i?.gender), !n) throw new Error("no offline-available fallback voice found");
3553
+ return this.fallbackProvider.createEngine(n);
3553
3554
  },
3554
3555
  () => (this.hasFallenBack = !0, this.onFailure === "fallbackAndRecover" && this.startHealthCheck(), { type: "enginefallback", detail: { reason: e.detail, voice: n } }),
3555
3556
  () => {
@@ -3586,13 +3587,18 @@ class Go {
3586
3587
  }
3587
3588
  this.copyPlaybackParameters(s, o), this.unbindActiveEngine?.(), this.activeEngine = o, this.engineStarted = !1, this.swapInFlight = !1, this.bindActiveEngine(), this.emitEvent(n(o)), this.startEngineWhenReady(o), o.loadUtterances(this.currentUtterances, this.desiredIndex), await s.destroy();
3588
3589
  }
3590
+ // Only skip the offlineAvailability filter when navigator.onLine is confirmed true — unknown
3591
+ // (unimplemented navigator.onLine) defaults to restricting, not to allowing online voices.
3592
+ //
3589
3593
  // Language narrows first, gender second: a same-language wrong-gender voice beats a
3590
3594
  // different-language right-gender one. Falls back to any language if none matches, then to
3591
3595
  // any gender within that if none matches. Region/quality ranking within the final candidate
3592
3596
  // set is delegated to pickBestVoiceByRegion, the same ranking logic sortVoicesByRegions uses.
3593
3597
  async pickBestFallbackVoice(e, n) {
3594
- const r = await this.fallbackProvider.getVoices(), [i] = lt([e]), { voicesByLang: s } = ct(r, [i]), o = s.get(i.baseLang) ?? [], a = o.length > 0 ? o : r, c = n ? a.filter((d) => d.gender === n) : [], l = c.length > 0 ? c : a;
3595
- return ki(e, l);
3598
+ const r = await this.fallbackProvider.getVoices(), s = typeof navigator < "u" && navigator.onLine === !0 ? r : r.filter((g) => g.offlineAvailability === !0);
3599
+ if (s.length === 0) return null;
3600
+ const [o] = lt([e]), { voicesByLang: a } = ct(s, [o]), c = a.get(o.baseLang) ?? [], l = c.length > 0 ? c : s, d = n ? l.filter((g) => g.gender === n) : [], u = d.length > 0 ? d : l;
3601
+ return ki(e, u);
3596
3602
  }
3597
3603
  async destroy() {
3598
3604
  this.teardownEpoch++, this.healthCheckTimer !== null && (clearTimeout(this.healthCheckTimer), this.healthCheckTimer = null), this.unbindActiveEngine?.(), this.events.clear(), await this.activeEngine.destroy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "A TypeScript library for implementing read aloud features with Web technologies, following best practices for digital publishing.",
5
5
  "author": "Readium Foundation",
6
6
  "keywords": [