@readium/speech 0.3.0 → 0.4.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.
@@ -14,6 +14,8 @@ export declare class WebSpeechReadAloudNavigator implements ReadiumSpeechNavigat
14
14
  getVoices(): Promise<ReadiumSpeechVoice[]>;
15
15
  setVoice(voice: ReadiumSpeechVoice | string): void;
16
16
  getCurrentVoice(): ReadiumSpeechVoice | null;
17
+ setSpeakInContentLanguage(enabled: boolean): void;
18
+ getSpeakInContentLanguage(): boolean;
17
19
  loadContent(content: ReadiumSpeechUtterance | ReadiumSpeechUtterance[]): void;
18
20
  getCurrentContent(): ReadiumSpeechUtterance | null;
19
21
  getContentQueue(): ReadiumSpeechUtterance[];
@@ -41,13 +41,19 @@ export declare class WebSpeechVoiceManager {
41
41
  private voices;
42
42
  private browserVoices;
43
43
  private isInitialized;
44
+ private scopedLanguages;
45
+ private broadenPromises;
44
46
  private constructor();
45
47
  /**
46
- * Initialize voice manager
48
+ * Initialize voice manager, or broaden an already-initialized singleton to
49
+ * also cover new languages. `languages` scope voice parsing to reduce
50
+ * per-language JSON loading; omitting it on the first call loads everything,
51
+ * but omitting it on a later call to an already-scoped instance is a no-op,
52
+ * not a retroactive broaden-to-everything.
47
53
  * @param options Configuration options for voice loading
48
- * @param options.languages Optional array of preferred language codes to filter voices during initialization
49
- * @param options.maxTimeout Maximum time in milliseconds to wait for voices to load (passed to getBrowserVoices)
50
- * @param options.interval Interval in milliseconds between voice loading checks (passed to getBrowserVoices)
54
+ * @param options.languages Optional array of preferred language codes to filter (or broaden to) voices
55
+ * @param options.maxTimeout Maximum time in milliseconds to wait for voices to load (passed to getBrowserVoices, first call only)
56
+ * @param options.interval Interval in milliseconds between voice loading checks (passed to getBrowserVoices, first call only)
51
57
  * @returns Promise that resolves with the WebSpeechVoiceManager instance
52
58
  */
53
59
  static initialize(options?: {
@@ -60,6 +66,18 @@ export declare class WebSpeechVoiceManager {
60
66
  * @private
61
67
  */
62
68
  private filterBrowserVoicesByLanguages;
69
+ /**
70
+ * Extract base language codes (e.g. "en", "fr") from a list of BCP47 tags
71
+ * @private
72
+ */
73
+ private static toBaseLangSet;
74
+ /**
75
+ * Broaden an already-initialized instance to also cover the given languages,
76
+ * reusing the already-fetched `browserVoices` (no new speechSynthesis fetch).
77
+ * No-op if the instance is already unscoped or already covers these languages.
78
+ * @private
79
+ */
80
+ private broadenLanguages;
63
81
  /**
64
82
  * Extract language and region from BCP47 language tag
65
83
  * @param lang - The BCP47 language tag (e.g., "en-US", "zh-CN")
@@ -13,6 +13,10 @@ export declare class WebSpeechEngine implements ReadiumSpeechPlaybackEngine {
13
13
  private voiceManager;
14
14
  private voices;
15
15
  private defaultVoice;
16
+ private speakInContentLanguage;
17
+ private languageVoiceCache;
18
+ private warmingLanguages;
19
+ private speakGeneration;
16
20
  private resumeInfinityTimer?;
17
21
  private isSpeakingInternal;
18
22
  private isPausedInternal;
@@ -37,7 +41,13 @@ export declare class WebSpeechEngine implements ReadiumSpeechPlaybackEngine {
37
41
  }): Promise<boolean>;
38
42
  private validateText;
39
43
  private getCurrentVoiceForUtterance;
44
+ private voiceMatchesLanguage;
45
+ private voiceForUtteranceSync;
46
+ private voiceForUtterance;
47
+ private warmLanguageVoiceCache;
40
48
  getCurrentVoice(): ReadiumSpeechVoice | null;
49
+ setSpeakInContentLanguage(enabled: boolean): void;
50
+ getSpeakInContentLanguage(): boolean;
41
51
  private toPlainText;
42
52
  loadUtterances(contents: ReadiumSpeechUtterance[]): void;
43
53
  setVoice(voice: ReadiumSpeechVoice | string): Promise<void>;
package/build/engine.d.ts CHANGED
@@ -6,6 +6,8 @@ export interface ReadiumSpeechPlaybackEngine {
6
6
  setVoice(voice: ReadiumSpeechVoice | string): void;
7
7
  getCurrentVoice(): ReadiumSpeechVoice | null;
8
8
  getAvailableVoices(): Promise<ReadiumSpeechVoice[]>;
9
+ setSpeakInContentLanguage(enabled: boolean): void;
10
+ getSpeakInContentLanguage(): boolean;
9
11
  speak(utteranceIndex?: number): void;
10
12
  pause(): void;
11
13
  resume(): void;