@readium/speech 0.14.0 → 0.15.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.
package/README.md CHANGED
@@ -90,6 +90,8 @@ import {
90
90
  WebSpeechVoiceManager,
91
91
  WebSpeechEngine,
92
92
  ReadiumSpeechNavigator,
93
+ SpeechPreferences,
94
+ getVoiceId,
93
95
  setupDecorations,
94
96
  DecorationStyleType,
95
97
  } from "@readium/speech";
@@ -104,7 +106,7 @@ const voice = await voiceManager.getDefaultVoice("en-US");
104
106
 
105
107
  // Create a navigator instance
106
108
  const navigator = new ReadiumSpeechNavigator(new WebSpeechEngine());
107
- await navigator.setVoice(voice);
109
+ await navigator.submitPreferences(new SpeechPreferences({ voice: getVoiceId(voice) }));
108
110
 
109
111
  const content = document.getElementById("content");
110
112
  if (!content) throw new Error("Missing #content element");
@@ -35,8 +35,6 @@ export declare class FallbackSpeechEngine implements ReadiumSpeechPlaybackEngine
35
35
  setVoice(voice: ReadiumSpeechVoice | string): void;
36
36
  getCurrentVoice(): ReadiumSpeechVoice | null;
37
37
  getAvailableVoices(): Promise<ReadiumSpeechVoice[]>;
38
- setSpeakInContentLanguage(enabled: boolean): void;
39
- getSpeakInContentLanguage(): boolean;
40
38
  speak(utteranceIndex?: number): void;
41
39
  pause(): void;
42
40
  resume(): void;
@@ -21,14 +21,17 @@ export declare class SpeechServerEngine implements ReadiumSpeechPlaybackEngine {
21
21
  private endpoints;
22
22
  private fetchImpl;
23
23
  private currentVoice;
24
+ private defaultVoice;
24
25
  private voices;
26
+ private voicesRequest;
27
+ private initializing;
28
+ private languageVoiceCache;
25
29
  private serviceInfo;
26
30
  private serviceInfoPromise;
27
31
  private currentUtterances;
28
32
  private currentUtteranceIndex;
29
33
  private playbackState;
30
34
  private readonly events;
31
- private speakInContentLanguage;
32
35
  private speakGeneration;
33
36
  private loadGeneration;
34
37
  private readonly prefetchWindow;
@@ -53,17 +56,19 @@ export declare class SpeechServerEngine implements ReadiumSpeechPlaybackEngine {
53
56
  private volume;
54
57
  constructor(options: SpeechServerEngineOptions);
55
58
  setAvailableVoices(voices: ReadiumSpeechVoice[]): void;
59
+ initialize(): Promise<boolean>;
56
60
  private fetchNetwork;
57
61
  loadUtterances(contents: ReadiumSpeechUtterance[], startIndex?: number): void;
58
62
  private bufferUntilReady;
59
63
  private indexCoveringChars;
64
+ private voiceFor;
65
+ private pickLanguageVoice;
60
66
  setVoice(voice: ReadiumSpeechVoice | string): void;
61
67
  getCurrentVoice(): ReadiumSpeechVoice | null;
62
68
  getAvailableVoices(): Promise<ReadiumSpeechVoice[]>;
69
+ private fetchVoices;
63
70
  private getServiceInfo;
64
71
  private fetchServiceInfo;
65
- setSpeakInContentLanguage(enabled: boolean): void;
66
- getSpeakInContentLanguage(): boolean;
67
72
  speak(utteranceIndex?: number): void;
68
73
  private synthesizeAndPlay;
69
74
  private resolveSynthesisStream;
@@ -38,6 +38,7 @@ export declare class WebSpeechVoiceManager {
38
38
  private static instance;
39
39
  private static initializationPromise;
40
40
  private systemLocale;
41
+ private isAndroid;
41
42
  private voices;
42
43
  private browserVoices;
43
44
  private isInitialized;
@@ -143,6 +144,13 @@ export declare class WebSpeechVoiceManager {
143
144
  * @param voices Optional array of voices to count (defaults to this.voices)
144
145
  */
145
146
  getLanguages(localization?: string, filterOptions?: VoiceFilterOptions, voices?: ReadiumSpeechVoice[]): LanguageInfo[];
147
+ /**
148
+ * Get the languages of every voice the browser has, with voice counts, sorted by name
149
+ * Unlike getLanguages(), it covers languages initialize() wasn't called with, without loading their voice data
150
+ * @param localization Optional BCP 47 language tag to use for language names
151
+ */
152
+ getBrowserLanguages(localization?: string): LanguageInfo[];
153
+ private countLanguages;
146
154
  /**
147
155
  * Get available regions with voice counts
148
156
  * @param localization Optional BCP 47 language tag to use for region names
@@ -6,15 +6,15 @@ export declare class WebSpeechEngine implements ReadiumSpeechPlaybackEngine {
6
6
  private speechSynthesis;
7
7
  private speechSynthesisUtterance;
8
8
  private currentVoice;
9
+ private speakingVoice;
9
10
  private currentUtterances;
10
11
  private currentUtteranceIndex;
11
12
  private playbackState;
12
13
  private readonly events;
13
14
  private voiceManager;
14
- private voices;
15
15
  private defaultVoice;
16
- private speakInContentLanguage;
17
16
  private languageVoiceCache;
17
+ private loadedOwnVoiceLanguages;
18
18
  private warmingLanguages;
19
19
  private speakGeneration;
20
20
  private resumeInfinityTimer?;
@@ -43,17 +43,17 @@ export declare class WebSpeechEngine implements ReadiumSpeechPlaybackEngine {
43
43
  }): Promise<boolean>;
44
44
  private validateText;
45
45
  private getCurrentVoiceForUtterance;
46
- private voiceMatchesLanguage;
47
46
  private languageCacheKey;
47
+ private ownVoice;
48
+ private unloadedOwnVoiceLanguage;
48
49
  private voiceForUtteranceSync;
49
50
  private voiceForUtterance;
50
51
  private warmLanguageVoiceCache;
51
52
  getCurrentVoice(): ReadiumSpeechVoice | null;
52
- setSpeakInContentLanguage(enabled: boolean): void;
53
- getSpeakInContentLanguage(): boolean;
54
53
  private toPlainText;
55
54
  loadUtterances(contents: ReadiumSpeechUtterance[], startIndex?: number): void;
56
55
  setVoice(voice: ReadiumSpeechVoice | string): Promise<void>;
56
+ private get voices();
57
57
  getAvailableVoices(): Promise<ReadiumSpeechVoice[]>;
58
58
  speak(utteranceIndex?: number): void;
59
59
  private cancelCurrentSpeech;
package/build/engine.d.ts CHANGED
@@ -7,8 +7,6 @@ export interface ReadiumSpeechPlaybackEngine {
7
7
  setVoice(voice: ReadiumSpeechVoice | string): void;
8
8
  getCurrentVoice(): ReadiumSpeechVoice | null;
9
9
  getAvailableVoices(): Promise<ReadiumSpeechVoice[]>;
10
- setSpeakInContentLanguage(enabled: boolean): void;
11
- getSpeakInContentLanguage(): boolean;
12
10
  speak(utteranceIndex?: number): void;
13
11
  pause(): void;
14
12
  resume(): void;
package/build/index.d.ts CHANGED
@@ -4,10 +4,12 @@ export * from './Fallback/index.js';
4
4
  export * from '@readium/decorator';
5
5
  export * from './decorator/index.js';
6
6
  export { Locator, LocatorLocations, LocatorText } from '@readium/shared';
7
- export { chineseVariantMap } from './voices/languages.js';
7
+ export { chineseVariantMap, getLanguageDisplayName } from './voices/languages.js';
8
+ export { extractLangRegionFromBCP47, valueForLanguage } from './utils/language.js';
8
9
  export * from './voices/types.js';
9
10
  export * from './voices/filters.js';
10
11
  export * from './voices/sorting.js';
12
+ export * from './voices/voiceId.js';
11
13
  export * from './engine.js';
12
14
  export * from './navigator.js';
13
15
  export * from './provider.js';