@readium/speech 0.18.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 (49) hide show
  1. package/README.md +18 -3
  2. package/build/Fallback/fallbackEngineProvider.d.ts +1 -0
  3. package/build/Fallback/fallbackSpeechEngine.d.ts +9 -2
  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 -3
  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 +8 -9
  10. package/build/WebSpeech/webSpeechEngineProvider.d.ts +1 -0
  11. package/build/engine.d.ts +2 -2
  12. package/build/index.d.ts +1 -0
  13. package/build/index.js +2541 -1727
  14. package/build/navigator.d.ts +59 -4
  15. package/build/preferences/SpeechSettings.d.ts +1 -5
  16. package/build/preferences/index.d.ts +1 -1
  17. package/build/provider.d.ts +1 -0
  18. package/build/speechNavigator.d.ts +17 -3
  19. package/build/utils/patches.d.ts +1 -0
  20. package/build/utils/text.d.ts +2 -1
  21. package/build/utterances/abbreviationAlias.d.ts +28 -0
  22. package/build/utterances/blocks.d.ts +5 -0
  23. package/build/utterances/boundaryLocate.d.ts +2 -1
  24. package/build/utterances/contextualization.d.ts +4 -4
  25. package/build/utterances/index.d.ts +3 -1
  26. package/build/utterances/language.d.ts +5 -5
  27. package/build/utterances/locate.d.ts +3 -2
  28. package/build/utterances/mergeUtterances.d.ts +9 -12
  29. package/build/utterances/nodeFields.d.ts +2 -1
  30. package/build/utterances/piece.d.ts +50 -0
  31. package/build/utterances/plainText.d.ts +31 -0
  32. package/build/utterances/sentenceBoundaryMerge.d.ts +1 -0
  33. package/build/utterances/sentenceReconstruction.d.ts +3 -6
  34. package/build/utterances/sentenceSegmenter.d.ts +2 -0
  35. package/build/utterances/sourceSpans.d.ts +45 -0
  36. package/build/utterances/splitSsmlAtSentences.d.ts +2 -1
  37. package/build/utterances/ssml.d.ts +49 -0
  38. package/build/utterances/tableStructure.d.ts +2 -0
  39. package/build/utterances/text.d.ts +17 -21
  40. package/build/utterances/utteranceOutput.d.ts +7 -6
  41. package/build/utterances/walk.d.ts +3 -3
  42. package/build/utterances/walkContext.d.ts +1 -16
  43. package/build/voices/defaultVoice.d.ts +13 -0
  44. package/build/voices/languageCode.d.ts +10 -0
  45. package/build/voices/languages.d.ts +2 -9
  46. package/build/voices/reachability.d.ts +2 -0
  47. package/build/voices/voiceSelection.d.ts +35 -0
  48. package/package.json +9 -6
  49. package/build/voices/languageMatching.d.ts +0 -3
@@ -1,4 +1,5 @@
1
1
  import { GuidedNavigationObject } from '@readium/shared';
2
+ import { SsmlElement } from './ssml.js';
2
3
  import { SubstitutionTable } from './types.js';
3
4
  export interface ResolvedNodeText {
4
5
  plain?: string;
@@ -17,7 +18,8 @@ export interface ResolvedNodeText {
17
18
  * applied first, since this extractor speaks referenced objects (noterefs,
18
19
  * pagebreaks) separately via the normal children walk rather than inline —
19
20
  * and if stripping a placeholder leaves no actual SSML markup behind, `ssml`
20
- * is dropped entirely rather than reported as a duplicate of `plain`.
21
+ * is dropped rather than reported as a duplicate of `plain`, standing in for
22
+ * `plain` when the source provides none.
21
23
  *
22
24
  * `language` is carried alongside either variant: the GND converter attaches
23
25
  * the nearest ancestor's declared language (e.g. `<html lang="fr">`) to every
@@ -25,27 +27,11 @@ export interface ResolvedNodeText {
25
27
  * language would otherwise be lost.
26
28
  */
27
29
  export declare function resolveNodeText(text: GuidedNavigationObject["text"]): ResolvedNodeText | undefined;
28
- export declare function stripSsmlTags(ssml: string): string;
29
- export declare function stripSsmlTagsWithMap(ssml: string): {
30
- plain: string;
31
- map: number[];
32
- };
33
- export declare function ssmlIndexToPlainIndex(map: number[], ssmlIndex: number): number;
34
30
  export declare function substituteWithMap(text: string, table: SubstitutionTable): {
35
31
  text: string;
36
32
  map: number[];
37
33
  };
38
34
  export declare function substitutedIndexToSourceIndex(map: number[], substitutedIndex: number): number;
39
- export interface SsmlTextAtom {
40
- kind: "paired" | "selfClosing" | "text";
41
- raw: string;
42
- tag?: string;
43
- attrs?: string;
44
- innerText?: string;
45
- text?: string;
46
- }
47
- export declare function unescapeSsmlEntities(text: string): string;
48
- export declare function tokenizeSsmlTextAtoms(ssml: string): SsmlTextAtom[];
49
35
  export interface SsmlSubstitutionResult {
50
36
  ssml: string;
51
37
  plain: string;
@@ -55,28 +41,38 @@ export declare function substituteSsmlText(ssml: string, table: SubstitutionTabl
55
41
  export interface LangSegment {
56
42
  plain: string;
57
43
  language?: string;
58
- start: number;
59
- end: number;
60
44
  }
61
45
  export declare function hasLangTag(ssml: string): boolean;
62
46
  /**
63
47
  * Splits an SSML string into per-language runs of plain text (`format:
64
48
  * "plain"` has no `<lang>` markup, so a language shift mid-string becomes
65
49
  * separate segments instead). Punctuation touching a `<lang>` boundary —
66
- * separated by nothing or only whitespace — joins the tagged run rather
50
+ * separated by nothing or only whitespace — joins the nested run rather
67
51
  * than staying with its lexical run: close-punct after `</lang>` joins the
68
52
  * run that just closed, open-punct before `<lang>` joins the run about to
69
- * start.
53
+ * start. Text in nested elements declaring a language (`<lang>`, or `xml:lang` on `<p>`, `<s>`...) takes the innermost one's.
70
54
  */
71
55
  export declare function splitOnLangTags(ssml: string, baseLanguage: string | undefined): LangSegment[];
72
56
  export interface SsmlSegment {
73
57
  ssml?: string;
58
+ open?: SsmlElement[];
59
+ close?: SsmlElement[];
74
60
  placeholderId?: string;
61
+ textBefore?: string;
62
+ textAfter?: string;
63
+ language?: string;
75
64
  abbreviation?: "text" | "alias";
76
65
  abbreviationText?: string;
77
66
  parenthesizedSsml?: string;
67
+ touchesPrevious?: boolean;
78
68
  }
79
69
  export declare function hasPlaceholder(ssml: string): boolean;
70
+ export declare function removeEmptiedPairs(ssml: string, isDropped: (id: string) => boolean, language: string | undefined): {
71
+ ssml: string;
72
+ spaced: Set<string>;
73
+ };
74
+ export declare function enclosedPlaceholders(ssml: string, language: string | undefined): Set<string>;
75
+ export declare function keepsSpaceBefore(text: string, language: string | undefined): boolean;
80
76
  /**
81
77
  * Splits a raw (pre-`stripPlaceholders`) SSML string on its embedded
82
78
  * `<readium:TAG id="...">` placeholders and `<sub alias>` abbreviations, for `interruptions`: each
@@ -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>;
@@ -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,10 @@
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;
10
+ export declare const voiceBaseLanguage: (language: 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,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.18.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.2.5",
65
- "@readium/guided-navigation": "^1.2.2",
66
- "@readium/helpers": "^1.2.0",
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,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;