@readium/speech 0.7.1 → 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.
@@ -6,7 +6,7 @@ import { ReadiumSpeechVoice } from './voices/types';
6
6
  import { ReadiumSpeechUtterance } from './utterance';
7
7
  export type ReadiumSpeechPlaybackState = "playing" | "paused" | "idle" | "loading" | "ready";
8
8
  export interface ReadiumSpeechPlaybackEvent {
9
- type: "start" | "pause" | "resume" | "end" | "stop" | "skip" | "error" | "boundary" | "mark" | "idle" | "loading" | "ready" | "voiceschanged" | "languagefallback";
9
+ type: "start" | "pause" | "resume" | "end" | "stop" | "skip" | "error" | "boundary" | "mark" | "idle" | "loading" | "ready" | "voiceschanged" | "languagefallback" | "enginefallback" | "enginerecovered";
10
10
  detail?: any;
11
11
  }
12
12
  export interface ReadiumSpeechNavigatorContract extends Configurable<SpeechSettings, SpeechPreferences> {
@@ -3,7 +3,7 @@ import { ReadiumSpeechVoice } from './voices/types';
3
3
  export interface ReadiumSpeechEngineProvider {
4
4
  readonly id: string;
5
5
  readonly name: string;
6
- getVoices(): Promise<ReadiumSpeechVoice[]>;
6
+ getVoices(forceRefresh?: boolean): Promise<ReadiumSpeechVoice[]>;
7
7
  createEngine(voice?: ReadiumSpeechVoice | string): Promise<ReadiumSpeechPlaybackEngine>;
8
8
  destroy(): Promise<void>;
9
9
  }
@@ -14,7 +14,7 @@ export interface ReadiumSpeechNavigatorConfiguration {
14
14
  export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorContract {
15
15
  private engine;
16
16
  private contentQueue;
17
- private eventListeners;
17
+ private readonly events;
18
18
  private navigatorState;
19
19
  private pendingAdvanceTimeout;
20
20
  private _defaults;
@@ -0,0 +1 @@
1
+ export declare const clampIndex: (index: number, length: number) => number;
@@ -0,0 +1,6 @@
1
+ export declare class EventEmitter<K, E> {
2
+ private listeners;
3
+ on(type: K, callback: (event: E) => void): () => void;
4
+ emit(type: K, event: E): void;
5
+ clear(): void;
6
+ }
@@ -23,6 +23,12 @@ export declare const getVoices: (lang: string) => Promise<ReadiumSpeechJSONVoice
23
23
  * @returns {string[]} Array of available language codes
24
24
  */
25
25
  export declare const getAvailableLanguages: () => string[];
26
+ /**
27
+ * Get a display name for a language code (e.g. "fr" -> "French")
28
+ * @param code - Language code
29
+ * @param localization - Optional BCP 47 locale to display the name in
30
+ */
31
+ export declare const getLanguageDisplayName: (code: string, localization?: string) => string;
26
32
  /**
27
33
  * Get the test utterance for a language
28
34
  * @param {string} lang - Language code (e.g., "en", "fr", "zh-CN")
@@ -1,7 +1,56 @@
1
1
  import { ReadiumSpeechVoice } from './types';
2
+ import { LanguageWithRegions } from './languages';
2
3
  /**
3
4
  * Create a map of language codes to their respective voice order maps
4
5
  * @param voices Array of voices to analyze
5
6
  * @returns Map where key is language code and value is a map of voice names to their original JSON indices
6
7
  */
7
- export declare function createJsonOrderMap(voices: ReadiumSpeechVoice[]): Promise<Map<string, Map<string, number>>>;
8
+ export declare const createJsonOrderMap: (voices: ReadiumSpeechVoice[]) => Promise<Map<string, Map<string, number>>>;
9
+ export declare const getQualityValue: (quality: string | null | undefined) => number;
10
+ /**
11
+ * Compares two voices by quality, using JSON name order as a tiebreaker for same-quality
12
+ * JSON-sourced voices, then falling back to alphabetical.
13
+ */
14
+ export declare const sortByQuality: (a: ReadiumSpeechVoice, b: ReadiumSpeechVoice, jsonOrderMaps?: Map<string, Map<string, number>>, baseLang?: string) => number;
15
+ /**
16
+ * Splits voices into those whose base language matches one of the processed preferred
17
+ * languages (grouped by base language) and everything else.
18
+ */
19
+ export declare const groupVoicesByLanguage: (voices: ReadiumSpeechVoice[], processedLangs: LanguageWithRegions[]) => {
20
+ voicesByLang: Map<string, ReadiumSpeechVoice[]>;
21
+ otherLangVoices: ReadiumSpeechVoice[];
22
+ };
23
+ /**
24
+ * Compares two voices by region match against a preferred language: regions matching the
25
+ * preferred language's region list first (in preference order), then the default region, then
26
+ * everything else alphabetically by region — quality breaks ties at every level.
27
+ */
28
+ export declare const compareByPreferredRegion: (a: ReadiumSpeechVoice, b: ReadiumSpeechVoice, processedLang: LanguageWithRegions, jsonOrderMaps: Map<string, Map<string, number>>) => number;
29
+ /**
30
+ * Sorts voices in place: regions matching the preferred language's region list first (in
31
+ * preference order), then the default region, then everything else alphabetically by region —
32
+ * quality breaks ties at every level.
33
+ */
34
+ export declare const sortByPreferredRegion: (voices: ReadiumSpeechVoice[], processedLang: LanguageWithRegions, jsonOrderMaps?: Map<string, Map<string, number>>) => Promise<void>;
35
+ /**
36
+ * Compares two voices by language display name, then default region, then region
37
+ * alphabetically, then quality — used for voices outside the preferred-language groups.
38
+ */
39
+ export declare const compareAlphabetically: (a: ReadiumSpeechVoice, b: ReadiumSpeechVoice, jsonOrderMaps: Map<string, Map<string, number>>) => number;
40
+ /**
41
+ * Sorts voices in place by language display name, then default region, then region
42
+ * alphabetically, then quality — used for voices outside the preferred-language groups.
43
+ */
44
+ export declare const sortAlphabetically: (voices: ReadiumSpeechVoice[], jsonOrderMaps?: Map<string, Map<string, number>>) => Promise<void>;
45
+ /**
46
+ * Sorts voices by region preference within each preferred language (default region, then
47
+ * quality), with unmatched-language voices appended afterward, sorted alphabetically.
48
+ */
49
+ export declare const sortVoicesByRegions: (preferredLanguages: string[], voices: ReadiumSpeechVoice[]) => Promise<ReadiumSpeechVoice[]>;
50
+ /**
51
+ * Picks the single best-ranked voice for one language, without sorting the full candidate list.
52
+ * Mirrors sortVoicesByRegions' fallback tier for a single preferred language: prefers a voice
53
+ * whose base language matches, ranked by region/quality; if none match, falls back to the same
54
+ * ranking sortAlphabetically would produce over the rest.
55
+ */
56
+ export declare const pickBestVoiceByRegion: (language: string, voices: ReadiumSpeechVoice[]) => Promise<ReadiumSpeechVoice | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.7.1",
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": [