@readium/speech 0.19.0 → 0.20.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.
Files changed (45) hide show
  1. package/README.md +18 -3
  2. package/build/Fallback/fallbackEngineProvider.d.ts +1 -0
  3. package/build/Fallback/fallbackSpeechEngine.d.ts +7 -1
  4. package/build/Fallback/recoverableFailure.d.ts +2 -1
  5. package/build/SpeechServer/index.d.ts +7 -7
  6. package/build/SpeechServer/speechServerEngine.d.ts +1 -1
  7. package/build/SpeechServer/speechServerEngineProvider.d.ts +1 -0
  8. package/build/WebSpeech/WebSpeechVoiceManager.d.ts +1 -1
  9. package/build/WebSpeech/webSpeechEngine.d.ts +3 -2
  10. package/build/WebSpeech/webSpeechEngineProvider.d.ts +1 -0
  11. package/build/engine.d.ts +1 -1
  12. package/build/index.js +2773 -2053
  13. package/build/navigator.d.ts +59 -4
  14. package/build/preferences/index.d.ts +1 -1
  15. package/build/provider.d.ts +1 -0
  16. package/build/speechNavigator.d.ts +3 -19
  17. package/build/utils/patches.d.ts +1 -0
  18. package/build/utils/text.d.ts +2 -1
  19. package/build/utterances/abbreviationAlias.d.ts +28 -0
  20. package/build/utterances/blocks.d.ts +5 -0
  21. package/build/utterances/boundaryLocate.d.ts +2 -1
  22. package/build/utterances/contextualization.d.ts +4 -4
  23. package/build/utterances/index.d.ts +3 -1
  24. package/build/utterances/language.d.ts +5 -5
  25. package/build/utterances/locate.d.ts +3 -2
  26. package/build/utterances/mergeUtterances.d.ts +9 -12
  27. package/build/utterances/nodeFields.d.ts +2 -1
  28. package/build/utterances/piece.d.ts +50 -0
  29. package/build/utterances/plainText.d.ts +31 -0
  30. package/build/utterances/sentenceBoundaryMerge.d.ts +1 -0
  31. package/build/utterances/sentenceReconstruction.d.ts +3 -6
  32. package/build/utterances/sentenceSegmenter.d.ts +2 -0
  33. package/build/utterances/sourceSpans.d.ts +45 -0
  34. package/build/utterances/splitSsmlAtSentences.d.ts +2 -1
  35. package/build/utterances/ssml.d.ts +49 -0
  36. package/build/utterances/tableStructure.d.ts +2 -0
  37. package/build/utterances/text.d.ts +17 -21
  38. package/build/utterances/utteranceOutput.d.ts +7 -6
  39. package/build/utterances/walk.d.ts +3 -3
  40. package/build/utterances/walkContext.d.ts +1 -16
  41. package/build/voices/languageCode.d.ts +1 -0
  42. package/build/voices/reachability.d.ts +2 -0
  43. package/build/voices/voiceSelection.d.ts +35 -0
  44. package/package.json +9 -6
  45. package/build/voices/voiceForLanguage.d.ts +0 -6
@@ -1,8 +1,9 @@
1
- import { ReadiumSpeechUtterance } from '../utterance.js';
2
1
  import { GuidedNavigationObject } from '@readium/shared';
3
2
  import { SourceTrace, WalkContext } from './walkContext.js';
4
- export declare function formatPlain(text: string, ctx: WalkContext): ReadiumSpeechUtterance;
5
- export declare function formatEntryText(text: string, ctx: WalkContext): ReadiumSpeechUtterance;
6
- export declare function formatDescription(text: string, node: GuidedNavigationObject, ctx: WalkContext): ReadiumSpeechUtterance;
7
- export declare function push(out: ReadiumSpeechUtterance[], sources: SourceTrace, node: SourceTrace[number], items: ReadiumSpeechUtterance[]): void;
8
- export declare function pushPiecesOrMerged(out: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext, node: GuidedNavigationObject, pieces: ReadiumSpeechUtterance[], pieceSources: SourceTrace, merged: ReadiumSpeechUtterance | undefined): void;
3
+ import { Piece } from './piece.js';
4
+ export declare function formatPlain(text: string, ctx: WalkContext): Piece;
5
+ export declare function formatEntryText(text: string, ctx: WalkContext): Piece;
6
+ export declare function formatDescription(text: string, node: GuidedNavigationObject, ctx: WalkContext): Piece;
7
+ export declare function push(out: Piece[], node: SourceTrace[number], items: Piece[]): void;
8
+ export declare function pushPiecesOrMerged(out: Piece[], node: GuidedNavigationObject, pieces: Piece[], merged: Piece | undefined): void;
9
+ export declare function pushMergedRuns(out: Piece[], ctx: WalkContext, node: GuidedNavigationObject, pieces: Piece[]): void;
@@ -1,4 +1,4 @@
1
1
  import { GuidedNavigationObject } from '@readium/shared';
2
- import { ReadiumSpeechUtterance } from '../utterance.js';
3
- import { SourceTrace, WalkContext } from './walkContext.js';
4
- export declare function walk(nodes: GuidedNavigationObject[], out: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext, suppress: boolean): void;
2
+ import { Piece } from './piece.js';
3
+ import { WalkContext } from './walkContext.js';
4
+ export declare function walk(nodes: GuidedNavigationObject[], out: Piece[], ctx: WalkContext, suppress: boolean): void;
@@ -2,7 +2,6 @@ import { i18n } from 'i18next';
2
2
  import { GuidedNavigationObject } from '@readium/shared';
3
3
  import { GndRole } from '@readium/guided-navigation';
4
4
  import { LocatorOptions } from '../decorator/createLocator.js';
5
- import { ReadiumSpeechUtterance } from '../utterance.js';
6
5
  import { SentenceSegmenter } from './sentenceSegmenter.js';
7
6
  import { ExtractionFormat, ExtractUtterancesOptions, Interruption, LanguageMode, Segmentation, SubstitutionTable } from './types.js';
8
7
  export interface WalkContext {
@@ -22,27 +21,13 @@ export interface WalkContext {
22
21
  segmentationSuppressions: Record<string, string[]>;
23
22
  segmenter: SentenceSegmenter;
24
23
  substitutions: SubstitutionTable;
25
- blockStarts: Set<ReadiumSpeechUtterance>;
26
24
  tableRowNumbers: Map<GuidedNavigationObject, number>;
27
25
  tableCellHeaders: Map<GuidedNavigationObject, string>;
28
- synthetic: Set<ReadiumSpeechUtterance>;
29
26
  ancestorChains: Map<GuidedNavigationObject, GuidedNavigationObject[]>;
30
- pendingRange: Map<ReadiumSpeechUtterance, {
31
- start: number;
32
- end: number;
33
- }>;
34
- edgeSubstitutedLocate: WeakMap<ReadiumSpeechUtterance, {
35
- leading?: LocatorOptions;
36
- trailing?: LocatorOptions;
37
- }>;
38
27
  aliasLocates: WeakSet<LocatorOptions>;
39
- placeholderPieces: Map<ReadiumSpeechUtterance, {
40
- node: GuidedNavigationObject;
41
- placement?: "inline" | "after" | "alias";
42
- }>;
28
+ blockTerms: WeakSet<GuidedNavigationObject>;
43
29
  }
44
30
  export type SourceTrace = (GuidedNavigationObject | [GuidedNavigationObject, GuidedNavigationObject] | undefined)[];
45
- export declare const blockLevelRoleSet: ReadonlySet<GndRole>;
46
31
  export declare const interruptionRoleSet: ReadonlySet<GndRole>;
47
32
  export declare const descriptionFoldingRoleSet: ReadonlySet<GndRole>;
48
33
  export declare const valueFoldingRoleSet: ReadonlySet<GndRole>;
@@ -7,3 +7,4 @@ export declare const chineseVariantMap: {
7
7
  * @returns Normalized language code
8
8
  */
9
9
  export declare const normalizeLanguageCode: (lang: string) => string;
10
+ export declare const voiceBaseLanguage: (language: string) => string;
@@ -0,0 +1,2 @@
1
+ import { ReadiumSpeechVoice } from './types.js';
2
+ export declare function isVoiceReachable(voice: ReadiumSpeechVoice): boolean;
@@ -0,0 +1,35 @@
1
+ import { ReadiumSpeechPlaybackEngine } from '../engine.js';
2
+ import { VoicePreference } from '../preferences/SpeechPreferences.js';
3
+ import { ReadiumSpeechVoice } from './types.js';
4
+ export declare class VoiceSelection {
5
+ private engine;
6
+ private preference;
7
+ private mainLanguages;
8
+ voices: ReadiumSpeechVoice[];
9
+ private contentLanguages;
10
+ private voiceIds;
11
+ private picked;
12
+ private picking;
13
+ private listing;
14
+ constructor(engine: ReadiumSpeechPlaybackEngine, preference: () => VoicePreference | null, mainLanguages: () => string[]);
15
+ /**
16
+ * The voice content in `language` is read with: the preferred one for its tag; for `en-US`, the one preferred for
17
+ * `en` if it's an `en-US` voice; for `en` that isn't a main language, that of the content's first `en-*`;
18
+ * else the picked one for its tag, then the preferred and picked ones for its base language.
19
+ */
20
+ voiceFor(language: string | undefined, picked?: Record<string, string>): string | undefined;
21
+ pickedRecord(): Record<string, string> | null;
22
+ private picks;
23
+ availablePreference(): VoicePreference | null;
24
+ setContentLanguages(languages: string[]): void;
25
+ unpicked(): string[];
26
+ pick(): Promise<void>;
27
+ private regionalOf;
28
+ private needsBoundary;
29
+ private pickKey;
30
+ private pickedVoice;
31
+ private pickVoice;
32
+ private preferredVoiceIds;
33
+ private listedVoiceId;
34
+ private pickedVoiceKey;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.19.0",
3
+ "version": "0.20.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": [
@@ -37,11 +37,14 @@
37
37
  }
38
38
  },
39
39
  "scripts": {
40
- "test": "npm run build && NODE_NO_WARNINGS=1 ava test/**/*.test.ts",
40
+ "test": "npm run build && npm run typecheck && NODE_NO_WARNINGS=1 ava test/**/*.test.ts",
41
+ "typecheck": "tsc",
41
42
  "test:voices": "npm run build && NODE_NO_WARNINGS=1 ava test/WebSpeechVoiceManager/*.test.ts",
42
43
  "test:utterances": "NODE_NO_WARNINGS=1 ava test/utterances/*.test.ts",
43
44
  "generate-metadata": "node scripts/generate-metadata.js",
44
45
  "generate-utterances": "npm run build && node scripts/generate-utterances.js",
46
+ "generate-verbosity-tables": "npm run build && node scripts/generate-verbosity-tables.js",
47
+ "generate-role-sets": "npm run build && node scripts/generate-role-sets.js",
45
48
  "clean": "rimraf ./build ./build-demo",
46
49
  "build": "vite build",
47
50
  "build:demo": "vite build --mode demo",
@@ -61,10 +64,10 @@
61
64
  "vite-plugin-dts": "^4.5.4"
62
65
  },
63
66
  "dependencies": {
64
- "@readium/decorator": "^1.4.0",
65
- "@readium/guided-navigation": "^1.2.2",
66
- "@readium/helpers": "^1.2.1",
67
- "@readium/shared": "^2.8.0",
67
+ "@readium/decorator": "^1.4.3",
68
+ "@readium/guided-navigation": "^1.4.0",
69
+ "@readium/helpers": "^1.3.0",
70
+ "@readium/shared": "^2.9.0",
68
71
  "i18next": "^26.4.0"
69
72
  }
70
73
  }
@@ -1,6 +0,0 @@
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;