@readium/speech 0.18.0 → 0.19.0

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.
@@ -3,7 +3,6 @@ import { ConfigurableSettings } from './Configurable.js';
3
3
  import { SpeechDefaults } from './SpeechDefaults.js';
4
4
  import { AutoPauseScope, SpeechPreferences, VerbosityPreset, VoicePreference } from './SpeechPreferences.js';
5
5
  import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
6
- import { ReadiumSpeechVoice } from '../voices/types.js';
7
6
  export declare class SpeechSettings implements ConfigurableSettings {
8
7
  [key: string]: unknown;
9
8
  readonly format: ExtractionFormat;
@@ -21,8 +20,5 @@ export declare class SpeechSettings implements ConfigurableSettings {
21
20
  readonly rate: number;
22
21
  readonly pitch: number;
23
22
  readonly volume: number;
24
- /**
25
- * @param engineVoice The engine's voice, which `voice` falls back to: when unset, or for its language in a record without it.
26
- */
27
- constructor(preferences: SpeechPreferences, defaults: SpeechDefaults, engineVoice?: ReadiumSpeechVoice | null);
23
+ constructor(preferences: SpeechPreferences, defaults: SpeechDefaults);
28
24
  }
@@ -24,11 +24,14 @@ export interface ReadiumSpeechNavigatorConfiguration {
24
24
  defaults?: ISpeechDefaults;
25
25
  contextualizationOverrides?: ContextualizationOverrides;
26
26
  segmentationOverrides?: SegmentationOverrides;
27
+ languages?: string[];
27
28
  }
28
29
  export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorContract {
29
30
  private engine;
31
+ private readonly languages;
30
32
  private contentQueue;
31
33
  private loadedQueue;
34
+ private loadedLanguages;
32
35
  private readonly events;
33
36
  private navigatorState;
34
37
  private pendingAdvanceTimeout;
@@ -36,7 +39,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
36
39
  private _preferences;
37
40
  private _settings;
38
41
  private _preferencesEditor;
39
- private preferencesEditorEngineVoice;
42
+ private preferencesEditorVoice;
40
43
  private readonly contextualizationOverrides?;
41
44
  private readonly segmentationOverrides?;
42
45
  private source;
@@ -46,15 +49,41 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
46
49
  private pendingResumeIndex;
47
50
  private pendingResumeState;
48
51
  private pendingAutoPauseIndex;
52
+ private voices;
53
+ private voiceIds;
54
+ private pickedVoices;
55
+ private pickingVoices;
56
+ private voiceListing;
57
+ private reportedLanguageFallbacks;
58
+ private notifiedVoice;
59
+ private loadGeneration;
49
60
  constructor(engine: ReadiumSpeechPlaybackEngine, configuration?: ReadiumSpeechNavigatorConfiguration);
50
61
  private applyEngineParameters;
51
62
  private initializeEngine;
63
+ private spokenLanguages;
64
+ private voiceIdFor;
65
+ private needsBoundary;
66
+ private pickKey;
67
+ private pickedVoice;
68
+ private pickVoice;
69
+ private pickVoices;
70
+ private refreshVoices;
71
+ private refreshVoicesForEngine;
72
+ private notifyVoicesChanged;
73
+ private spokenVoice;
74
+ private availableVoice;
75
+ private preferredVoiceIds;
76
+ private listedVoiceId;
77
+ private pickedVoiceRecord;
78
+ private pickedVoiceKey;
52
79
  private setupEngineListeners;
53
80
  private setNavigatorState;
54
81
  getVoices(): Promise<ReadiumSpeechVoice[]>;
55
82
  loadContent(content: ReadiumSpeechUtterance | ReadiumSpeechUtterance[], options?: ReadiumSpeechContentOptions): void;
56
83
  loadGndContent(nodes: GuidedNavigationObject[], options?: ReadiumSpeechContentOptions): Promise<void>;
57
84
  private setContentQueue;
85
+ private stamped;
86
+ private reportLanguageFallbacks;
58
87
  private withLanguage;
59
88
  private withVoice;
60
89
  private reextract;
@@ -78,6 +107,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
78
107
  private emitUtteranceBoundary;
79
108
  private emitContentChangeEvent;
80
109
  get settings(): SpeechSettings;
110
+ private settingsWith;
81
111
  get preferencesEditor(): SpeechPreferencesEditor;
82
112
  submitPreferences(preferences: SpeechPreferences): Promise<void>;
83
113
  private applyPreferences;
@@ -0,0 +1,13 @@
1
+ import { ReadiumSpeechVoice } from './types.js';
2
+ /**
3
+ * Picks the voice content in `language` is spoken with: among its base language's voices, whatever the region,
4
+ * without novelty or very low quality ones, preferring those whose boundary support is `needsBoundary`,
5
+ * ranked by pickBestVoiceByRegion. `null` when the language has no voice.
6
+ */
7
+ export declare const pickLanguageVoice: (language: string, voices: ReadiumSpeechVoice[], needsBoundary?: boolean) => Promise<ReadiumSpeechVoice | null>;
8
+ /**
9
+ * Picks an engine's default voice: the pickLanguageVoice() of the first of `languages` with one,
10
+ * else the best of all `voices` by `languages`.
11
+ * Without `languages`, the user's preferred languages (navigator.languages) are used.
12
+ */
13
+ export declare const pickDefaultVoice: (languages: string[] | undefined, voices: ReadiumSpeechVoice[]) => Promise<ReadiumSpeechVoice | null>;
@@ -0,0 +1,9 @@
1
+ export declare const chineseVariantMap: {
2
+ [key: string]: string;
3
+ };
4
+ /**
5
+ * Normalizes language code with special handling for Chinese variants
6
+ * @param lang - Input language code
7
+ * @returns Normalized language code
8
+ */
9
+ export declare const normalizeLanguageCode: (lang: string) => string;
@@ -1,17 +1,10 @@
1
+ import { chineseVariantMap, normalizeLanguageCode } from './languageCode.js';
1
2
  import { ReadiumSpeechJSONVoice } from './types.js';
2
3
  export interface LanguageWithRegions {
3
4
  baseLang: string;
4
5
  regions: string[];
5
6
  }
6
- export declare const chineseVariantMap: {
7
- [key: string]: string;
8
- };
9
- /**
10
- * Normalizes language code with special handling for Chinese variants
11
- * @param lang - Input language code
12
- * @returns Normalized language code
13
- */
14
- export declare const normalizeLanguageCode: (lang: string) => string;
7
+ export { chineseVariantMap, normalizeLanguageCode };
15
8
  /**
16
9
  * Get all voices for a specific language
17
10
  * @param {string} lang - Language code (e.g., "en", "fr", "zh-CN")
@@ -0,0 +1,6 @@
1
+ export declare const voiceBaseLanguage: (language: string) => string;
2
+ /**
3
+ * Looks up the voice of a language-keyed voice record for content in `language`: the exact tag's,
4
+ * else its base language's, tags matched as voice languages are, e.g. a `zh-HK` key for `yue-HK` content.
5
+ */
6
+ export declare const voiceForLanguage: (voices: Record<string, string>, language: string) => string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
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": [
@@ -61,9 +61,9 @@
61
61
  "vite-plugin-dts": "^4.5.4"
62
62
  },
63
63
  "dependencies": {
64
- "@readium/decorator": "^1.2.5",
64
+ "@readium/decorator": "^1.4.0",
65
65
  "@readium/guided-navigation": "^1.2.2",
66
- "@readium/helpers": "^1.2.0",
66
+ "@readium/helpers": "^1.2.1",
67
67
  "@readium/shared": "^2.8.0",
68
68
  "i18next": "^26.4.0"
69
69
  }
@@ -1,3 +0,0 @@
1
- import { ReadiumSpeechVoice } from './types.js';
2
- export declare const voiceMatchesLanguage: (voice: ReadiumSpeechVoice, language: string) => boolean;
3
- export declare const keepsSelectedVoice: (voice: ReadiumSpeechVoice | null, language: string) => boolean;