@readium/speech 0.9.1 → 0.10.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 (38) hide show
  1. package/README.md +13 -11
  2. package/build/gnd/converter.d.ts +3 -0
  3. package/build/gnd/domRangeGenerator.d.ts +1 -1
  4. package/build/gnd/object.d.ts +4 -0
  5. package/build/gnd/options.d.ts +2 -0
  6. package/build/gnd/selectorGenerator.d.ts +3 -2
  7. package/build/gnd/textrefFragment.d.ts +2 -0
  8. package/build/index.cjs +17 -43
  9. package/build/index.js +4987 -5320
  10. package/build/preferences/SpeechDefaults.d.ts +4 -1
  11. package/build/preferences/SpeechPreferences.d.ts +3 -2
  12. package/build/preferences/SpeechPreferencesEditor.d.ts +3 -1
  13. package/build/preferences/SpeechSettings.d.ts +3 -1
  14. package/build/preferences/constraints.d.ts +3 -1
  15. package/build/preferences/index.d.ts +2 -1
  16. package/build/speechNavigator.d.ts +8 -0
  17. package/build/utils/text.d.ts +3 -0
  18. package/build/utterance.d.ts +6 -1
  19. package/build/utterances/applySubstitutions.d.ts +3 -0
  20. package/build/utterances/boundaryLocate.d.ts +11 -0
  21. package/build/utterances/builtInSubstitutions.d.ts +2 -0
  22. package/build/utterances/builtInSuppressions.d.ts +1 -0
  23. package/build/utterances/contextualization.d.ts +15 -0
  24. package/build/utterances/extractUtterances.d.ts +3 -1
  25. package/build/utterances/index.d.ts +4 -1
  26. package/build/utterances/locate.d.ts +22 -0
  27. package/build/utterances/mergeUtterances.d.ts +17 -0
  28. package/build/utterances/sentenceBoundaryMerge.d.ts +7 -0
  29. package/build/utterances/sentenceReconstruction.d.ts +6 -0
  30. package/build/utterances/sentenceSegmenter.d.ts +8 -0
  31. package/build/utterances/splitSsmlAtSentences.d.ts +2 -0
  32. package/build/utterances/text.d.ts +29 -0
  33. package/build/utterances/types.d.ts +18 -2
  34. package/build/utterances/utteranceLocate.d.ts +4 -0
  35. package/build/utterances/utteranceOutput.d.ts +6 -0
  36. package/build/utterances/walk.d.ts +4 -0
  37. package/build/utterances/walkContext.d.ts +40 -0
  38. package/package.json +4 -5
@@ -1,5 +1,6 @@
1
1
  import { GndRole } from '../gnd/types.js';
2
- import { AutoPauseScope, ExtractionFormat, LanguageMode, VerbosityPreset } from './SpeechPreferences.js';
2
+ import { AutoPauseScope, VerbosityPreset } from './SpeechPreferences.js';
3
+ import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
3
4
  export interface ISpeechDefaults {
4
5
  format?: ExtractionFormat | null;
5
6
  inlineContextualization?: boolean | null;
@@ -7,6 +8,7 @@ export interface ISpeechDefaults {
7
8
  skip?: GndRole[] | null;
8
9
  contextualize?: GndRole[] | null;
9
10
  language?: LanguageMode | null;
11
+ segmentation?: Segmentation | null;
10
12
  pauseDuration?: number | null;
11
13
  autoPause?: AutoPauseScope | null;
12
14
  rate?: number | null;
@@ -20,6 +22,7 @@ export declare class SpeechDefaults {
20
22
  readonly skip: GndRole[];
21
23
  readonly contextualize: GndRole[];
22
24
  readonly language: LanguageMode;
25
+ readonly segmentation: Segmentation;
23
26
  readonly pauseDuration: number;
24
27
  readonly autoPause: AutoPauseScope;
25
28
  readonly rate: number;
@@ -1,8 +1,7 @@
1
1
  import { GndRole } from '../gnd/types.js';
2
+ import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
2
3
  import { ConfigurablePreferences } from './Configurable.js';
3
4
  export type VerbosityPreset = "none" | "few" | "some" | "most" | "custom";
4
- export type LanguageMode = "none" | "block-level" | "always";
5
- export type ExtractionFormat = "plain" | "ssml";
6
5
  export type AutoPauseScope = "none" | "utterance" | "block";
7
6
  export interface ISpeechPreferences {
8
7
  format?: ExtractionFormat | null;
@@ -11,6 +10,7 @@ export interface ISpeechPreferences {
11
10
  skip?: GndRole[] | null;
12
11
  contextualize?: GndRole[] | null;
13
12
  language?: LanguageMode | null;
13
+ segmentation?: Segmentation | null;
14
14
  pauseDuration?: number | null;
15
15
  autoPause?: AutoPauseScope | null;
16
16
  rate?: number | null;
@@ -24,6 +24,7 @@ export declare class SpeechPreferences implements ISpeechPreferences, Configurab
24
24
  skip: GndRole[] | null | undefined;
25
25
  contextualize: GndRole[] | null | undefined;
26
26
  language: LanguageMode | null | undefined;
27
+ segmentation: Segmentation | null | undefined;
27
28
  pauseDuration: number | null | undefined;
28
29
  autoPause: AutoPauseScope | null | undefined;
29
30
  rate: number | null | undefined;
@@ -1,7 +1,8 @@
1
1
  import { IPreferencesEditor } from './PreferencesEditor.js';
2
2
  import { BooleanPreference, EnumPreference, RangePreference, StringArrayPreference } from './Preference.js';
3
- import { SpeechPreferences, VerbosityPreset, LanguageMode, ExtractionFormat, AutoPauseScope } from './SpeechPreferences.js';
3
+ import { SpeechPreferences, VerbosityPreset, AutoPauseScope } from './SpeechPreferences.js';
4
4
  import { SpeechSettings } from './SpeechSettings.js';
5
+ import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
5
6
  export declare class SpeechPreferencesEditor implements IPreferencesEditor {
6
7
  preferences: SpeechPreferences;
7
8
  private settings;
@@ -14,6 +15,7 @@ export declare class SpeechPreferencesEditor implements IPreferencesEditor {
14
15
  get skip(): StringArrayPreference;
15
16
  get contextualize(): StringArrayPreference;
16
17
  get language(): EnumPreference<LanguageMode>;
18
+ get segmentation(): EnumPreference<Segmentation>;
17
19
  get pauseDuration(): RangePreference<number>;
18
20
  get autoPause(): EnumPreference<AutoPauseScope>;
19
21
  get rate(): RangePreference<number>;
@@ -1,7 +1,8 @@
1
1
  import { GndRole } from '../gnd/types.js';
2
2
  import { ConfigurableSettings } from './Configurable.js';
3
3
  import { SpeechDefaults } from './SpeechDefaults.js';
4
- import { AutoPauseScope, ExtractionFormat, LanguageMode, SpeechPreferences, VerbosityPreset } from './SpeechPreferences.js';
4
+ import { AutoPauseScope, SpeechPreferences, VerbosityPreset } from './SpeechPreferences.js';
5
+ import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
5
6
  export declare class SpeechSettings implements ConfigurableSettings {
6
7
  [key: string]: unknown;
7
8
  readonly format: ExtractionFormat;
@@ -10,6 +11,7 @@ export declare class SpeechSettings implements ConfigurableSettings {
10
11
  readonly skip: GndRole[];
11
12
  readonly contextualize: GndRole[];
12
13
  readonly language: LanguageMode;
14
+ readonly segmentation: Segmentation;
13
15
  readonly pauseDuration: number;
14
16
  readonly autoPause: AutoPauseScope;
15
17
  readonly rate: number;
@@ -1,4 +1,5 @@
1
- import { AutoPauseScope, ExtractionFormat, ISpeechPreferences, LanguageMode, VerbosityPreset } from './SpeechPreferences.js';
1
+ import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
2
+ import { AutoPauseScope, ISpeechPreferences, VerbosityPreset } from './SpeechPreferences.js';
2
3
  export interface RangeConfig {
3
4
  range: [number, number];
4
5
  step: number;
@@ -11,4 +12,5 @@ export declare const verbosityPresets: VerbosityPreset[];
11
12
  export declare const languageModes: LanguageMode[];
12
13
  export declare const extractionFormats: ExtractionFormat[];
13
14
  export declare const autoPauseScopes: AutoPauseScope[];
15
+ export declare const segmentationModes: Segmentation[];
14
16
  export declare const extractionPreferenceKeys: (keyof ISpeechPreferences)[];
@@ -3,7 +3,8 @@ export type { IPreferencesEditor } from './PreferencesEditor.js';
3
3
  export { BooleanPreference, EnumPreference, Preference, RangePreference, StringArrayPreference } from './Preference.js';
4
4
  export type { IEnumPreference, IPreference, IRangePreference } from './Preference.js';
5
5
  export { SpeechPreferences } from './SpeechPreferences.js';
6
- export type { ISpeechPreferences, LanguageMode, VerbosityPreset } from './SpeechPreferences.js';
6
+ export type { ISpeechPreferences, VerbosityPreset } from './SpeechPreferences.js';
7
+ export type { LanguageMode, Segmentation } from '../utterances/types.js';
7
8
  export { SpeechDefaults } from './SpeechDefaults.js';
8
9
  export type { ISpeechDefaults } from './SpeechDefaults.js';
9
10
  export { SpeechSettings } from './SpeechSettings.js';
@@ -8,16 +8,22 @@ import { SpeechSettings } from './preferences/SpeechSettings';
8
8
  import { ContextualizationShapeOverrides } from './preferences/verbosityTables';
9
9
  import { ReadiumSpeechUtterance } from './utterance';
10
10
  import { Contextualizations } from './utterances/types';
11
+ import { SentenceSegmenter } from './utterances/sentenceSegmenter';
11
12
  import { ReadiumSpeechVoice } from './voices/types';
12
13
  export interface ContextualizationOverrides {
13
14
  contextualizations?: Contextualizations;
14
15
  shapes?: ContextualizationShapeOverrides;
15
16
  params?: (role: string, node: GndObject) => Record<string, string> | undefined;
16
17
  }
18
+ export interface SegmentationOverrides {
19
+ suppressions?: Record<string, string[]>;
20
+ segmenter?: SentenceSegmenter;
21
+ }
17
22
  export interface ReadiumSpeechNavigatorConfiguration {
18
23
  preferences?: ISpeechPreferences;
19
24
  defaults?: ISpeechDefaults;
20
25
  contextualizationOverrides?: ContextualizationOverrides;
26
+ segmentationOverrides?: SegmentationOverrides;
21
27
  }
22
28
  export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorContract {
23
29
  private engine;
@@ -30,6 +36,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
30
36
  private _settings;
31
37
  private _preferencesEditor;
32
38
  private readonly contextualizationOverrides?;
39
+ private readonly segmentationOverrides?;
33
40
  private source;
34
41
  private contentSources;
35
42
  private contentBlockStarts;
@@ -65,6 +72,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
65
72
  getState(): ReadiumSpeechPlaybackState;
66
73
  on(event: ReadiumSpeechPlaybackEvent["type"] | "contentchange", listener: (event: ReadiumSpeechPlaybackEvent) => void): () => void;
67
74
  private emitEvent;
75
+ private emitUtteranceBoundary;
68
76
  private emitContentChangeEvent;
69
77
  get settings(): SpeechSettings;
70
78
  get preferencesEditor(): SpeechPreferencesEditor;
@@ -2,3 +2,6 @@ export declare const BINDING_PUNCT_CLASS = "\\p{Pe}\\p{Pf}.,;:!?\uFF0C\u3002\u30
2
2
  export declare const OPENING_PUNCT_CLASS = "\\p{Ps}\\p{Pi}\u00BF\u00A1";
3
3
  export declare function startsWithBindingPunct(s: string): boolean;
4
4
  export declare function startsWithOpeningPunct(s: string): boolean;
5
+ export declare function isSinglePunctuationChar(s: string): boolean;
6
+ export declare function neutralizeAngleBrackets(text: string): string;
7
+ export declare function decodeResidualHtmlEntities(text: string): string;
@@ -1,9 +1,14 @@
1
1
  import { LocatorOptions } from './decorator/createLocator.js';
2
+ export interface UtteranceOffset {
3
+ start: number;
4
+ end: number;
5
+ locate: LocatorOptions;
6
+ }
2
7
  export interface ReadiumSpeechUtterance {
3
8
  id?: string;
4
9
  plain?: string;
5
10
  ssml?: string;
6
11
  language?: string;
7
12
  locate?: LocatorOptions;
8
- synthetic?: boolean;
13
+ offsets?: UtteranceOffset[];
9
14
  }
@@ -0,0 +1,3 @@
1
+ import { ReadiumSpeechUtterance } from '../utterance.js';
2
+ import { WalkContext } from './walkContext.js';
3
+ export declare function applySubstitutions(utterances: ReadiumSpeechUtterance[], ctx: WalkContext): ReadiumSpeechUtterance[];
@@ -0,0 +1,11 @@
1
+ import { LocatorOptions } from '../decorator/createLocator.js';
2
+ import { ReadiumSpeechUtterance } from '../utterance.js';
3
+ export declare function recordSubstitutionSource(utterance: ReadiumSpeechUtterance, source: {
4
+ plain: string;
5
+ map: number[];
6
+ }): void;
7
+ export declare function markNonQuotable<T extends LocatorOptions>(locate: T): T;
8
+ export declare function resolveBoundaryLocate(utterance: ReadiumSpeechUtterance, charIndex: number, charLength: number): {
9
+ locate: LocatorOptions;
10
+ word: string;
11
+ } | undefined;
@@ -0,0 +1,2 @@
1
+ import { SubstitutionTable } from './types.js';
2
+ export declare const builtInSubstitutions: SubstitutionTable;
@@ -0,0 +1 @@
1
+ export declare const builtInSuppressions: Record<string, string[]>;
@@ -0,0 +1,15 @@
1
+ import { GndObject, GndRole } from '../gnd/types.js';
2
+ import { ReadiumSpeechUtterance } from '../utterance.js';
3
+ import { SourceTrace, WalkContext } from './walkContext.js';
4
+ export declare function resolveEntryText(ctx: WalkContext, base: string, variantKey?: string, params?: Record<string, string>): string | undefined;
5
+ export declare function isRoleContextualized(role: string, ctx: WalkContext): boolean;
6
+ export declare function isDroppedByAnotherRole(role: GndRole, roles: GndRole[], ctx: WalkContext): boolean;
7
+ export declare function scopeToQuote(utterance: ReadiumSpeechUtterance, text: string, quoteText: string, node: GndObject, ctx: WalkContext): void;
8
+ export declare function pushRoleContextualization(out: ReadiumSpeechUtterance[], sources: SourceTrace, node: GndObject, ctx: WalkContext, role: string, phase: "before" | "after", variantKey?: string, params?: Record<string, string>): void;
9
+ export declare function resolvePluralPart(ctx: WalkContext, role: string, name: string, count: number): string;
10
+ type ContextualizationParams = {
11
+ variantKey?: string;
12
+ params?: Record<string, string>;
13
+ };
14
+ export declare function contextualizationParamsFor(role: string, node: GndObject, ctx: WalkContext): ContextualizationParams;
15
+ export {};
@@ -1,6 +1,8 @@
1
1
  import { GndObject } from '../gnd/types.js';
2
2
  import { ReadiumSpeechUtterance } from '../utterance.js';
3
3
  import { ExtractUtterancesOptions } from './types.js';
4
+ import { SourceTrace } from './walkContext.js';
5
+ export type { SourceTrace } from './walkContext.js';
4
6
  /**
5
7
  * Extracts an ordered list of read-aloud utterances from a Guided
6
8
  * Navigation node tree, following the patterns documented at
@@ -16,6 +18,6 @@ export declare function extractUtterances(nodes: GndObject[], options: ExtractUt
16
18
  */
17
19
  export declare function extractUtterancesWithSources(nodes: GndObject[], options: ExtractUtterancesOptions): Promise<{
18
20
  utterances: ReadiumSpeechUtterance[];
19
- sources: (GndObject | undefined)[];
21
+ sources: SourceTrace;
20
22
  blockStarts: boolean[];
21
23
  }>;
@@ -1,4 +1,7 @@
1
1
  export { extractUtterances } from './extractUtterances.js';
2
+ export { resolveBoundaryLocate } from './boundaryLocate.js';
3
+ export { resolveUtteranceLocate } from './utteranceLocate.js';
2
4
  export { blockLevelRoles, skippableRoles } from './roles.js';
3
5
  export { defaultContextualizations } from './contextualizations.js';
4
- export type { ContextualizationEntry, Contextualizations, ContextualizationOptions, ExtractUtterancesOptions } from './types.js';
6
+ export type { ContextualizationEntry, Contextualizations, ContextualizationOptions, ExtractUtterancesOptions, Segmentation, SegmentationOptions, } from './types.js';
7
+ export type { SentenceBoundary, SentenceSegmenter } from './sentenceSegmenter.js';
@@ -0,0 +1,22 @@
1
+ import { GndObject } from '../gnd/types.js';
2
+ import { DecodedTextref } from '../gnd/textrefFragment.js';
3
+ import { LocatorOptions } from '../decorator/createLocator.js';
4
+ import { ReadiumSpeechUtterance } from '../utterance.js';
5
+ import { SourceTrace, WalkContext } from './walkContext.js';
6
+ export declare function subLocateFor(nodeRef: DecodedTextref, quoteText: string): LocatorOptions;
7
+ export declare function resolveNodeLocate(node: GndObject, ancestorChains: Map<GndObject, GndObject[]>): {
8
+ own: boolean;
9
+ ref: DecodedTextref;
10
+ } | undefined;
11
+ export declare function preciseLocateFor(resolved: {
12
+ own: boolean;
13
+ ref: DecodedTextref;
14
+ } | undefined, text: string): LocatorOptions | undefined;
15
+ export declare function spanLocate(firstRef: {
16
+ own: boolean;
17
+ ref: DecodedTextref;
18
+ } | undefined, lastRef: {
19
+ own: boolean;
20
+ ref: DecodedTextref;
21
+ } | undefined, fallback: LocatorOptions | undefined): LocatorOptions | undefined;
22
+ export declare function attachLocate(utterances: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext): ReadiumSpeechUtterance[];
@@ -0,0 +1,17 @@
1
+ import { GndObject } from '../gnd/types.js';
2
+ import { LocatorOptions } from '../decorator/createLocator.js';
3
+ import { ReadiumSpeechUtterance } from '../utterance.js';
4
+ import { ResolvedNodeText } from './text.js';
5
+ import { ExtractionFormat, LanguageMode } from './types.js';
6
+ import { SourceTrace, WalkContext } from './walkContext.js';
7
+ export declare function joinPieceTexts(parts: string[]): {
8
+ joined: string;
9
+ ranges: {
10
+ start: number;
11
+ end: number;
12
+ }[];
13
+ };
14
+ export declare function substitutedBareLocate(node: GndObject, ctx: WalkContext): LocatorOptions | undefined;
15
+ export declare function mergeUtterances(pieces: ReadiumSpeechUtterance[], pieceSources: SourceTrace, ctx: WalkContext): ReadiumSpeechUtterance | undefined;
16
+ export declare function applyFormat(resolved: ResolvedNodeText, format: ExtractionFormat, language: LanguageMode | undefined, ctx: WalkContext): ReadiumSpeechUtterance[];
17
+ export declare function plainOf(text: string, format: ExtractionFormat): string;
@@ -0,0 +1,7 @@
1
+ import { SentenceBoundary } from './sentenceSegmenter.js';
2
+ interface RawBoundary {
3
+ start: number;
4
+ end: number;
5
+ }
6
+ export declare function refineSentenceBoundaries(text: string, raw: RawBoundary[], suppressions: string[]): SentenceBoundary[];
7
+ export {};
@@ -0,0 +1,6 @@
1
+ import { ReadiumSpeechUtterance } from '../utterance.js';
2
+ import { SourceTrace, WalkContext } from './walkContext.js';
3
+ export declare function splitIntoSentenceUtterances(out: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext): Promise<{
4
+ out: ReadiumSpeechUtterance[];
5
+ sources: SourceTrace;
6
+ }>;
@@ -0,0 +1,8 @@
1
+ export interface SentenceBoundary {
2
+ text: string;
3
+ start: number;
4
+ end: number;
5
+ contentEnd: number;
6
+ }
7
+ export type SentenceSegmenter = (language: string, text: string, customSuppressions?: string[]) => Promise<SentenceBoundary[]>;
8
+ export declare function segmentSentences(language: string, text: string, customSuppressions?: string[]): Promise<SentenceBoundary[]>;
@@ -0,0 +1,2 @@
1
+ import { SentenceSegmenter } from './sentenceSegmenter.js';
2
+ export declare function splitSsmlAtSentences(ssml: string, language: string, segmenter: SentenceSegmenter, customSuppressions?: string[]): Promise<string[] | undefined>;
@@ -1,4 +1,5 @@
1
1
  import { GndObject } from '../gnd/types.js';
2
+ import { SubstitutionTable } from './types.js';
2
3
  export interface ResolvedNodeText {
3
4
  plain?: string;
4
5
  ssml?: string;
@@ -25,9 +26,37 @@ export interface ResolvedNodeText {
25
26
  */
26
27
  export declare function resolveNodeText(text: GndObject["text"]): ResolvedNodeText | undefined;
27
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
+ export declare function substituteWithMap(text: string, table: SubstitutionTable): {
35
+ text: string;
36
+ map: number[];
37
+ };
38
+ 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
+ export interface SsmlSubstitutionResult {
50
+ ssml: string;
51
+ plain: string;
52
+ map: number[];
53
+ }
54
+ export declare function substituteSsmlText(ssml: string, table: SubstitutionTable): SsmlSubstitutionResult;
28
55
  export interface LangSegment {
29
56
  plain: string;
30
57
  language?: string;
58
+ start: number;
59
+ end: number;
31
60
  }
32
61
  export declare function hasLangTag(ssml: string): boolean;
33
62
  /**
@@ -1,4 +1,8 @@
1
1
  import { GndObject, GndRole } from '../gnd/types.js';
2
+ import { SentenceSegmenter } from './sentenceSegmenter.js';
3
+ export type ExtractionFormat = "plain" | "ssml";
4
+ export type LanguageMode = "none" | "block-level" | "always";
5
+ export type Segmentation = "structure" | "sentence";
2
6
  export type ContextualizationEntry = string | {
3
7
  [key: string]: ContextualizationEntry;
4
8
  };
@@ -8,12 +12,24 @@ export interface ContextualizationOptions {
8
12
  shapes?: Partial<Record<GndRole, "inline" | "block">>;
9
13
  params?: (role: GndRole, node: GndObject) => Record<string, string> | undefined;
10
14
  }
15
+ export type SubstitutionRule = string | {
16
+ pattern: RegExp;
17
+ replace: string | ((...match: string[]) => string);
18
+ };
19
+ export type SubstitutionTable = Record<string, SubstitutionRule>;
20
+ export interface SegmentationOptions {
21
+ mode?: Segmentation;
22
+ suppressions?: Record<string, string[]>;
23
+ segmenter?: SentenceSegmenter;
24
+ }
11
25
  export interface ExtractUtterancesOptions {
12
- format?: "plain" | "ssml";
26
+ format?: ExtractionFormat;
13
27
  contextualization?: ContextualizationOptions;
14
28
  contextualizationLocale?: string;
15
29
  skip?: GndRole[];
16
30
  contextualize?: GndRole[];
17
- language?: "none" | "block-level" | "always";
31
+ language?: LanguageMode;
18
32
  inlineContextualization?: boolean;
33
+ segmentation?: SegmentationOptions;
34
+ substitutions?: SubstitutionTable;
19
35
  }
@@ -0,0 +1,4 @@
1
+ import { LocatorOptions } from '../decorator/createLocator.js';
2
+ import { Segmentation } from './types.js';
3
+ import { ReadiumSpeechUtterance } from '../utterance.js';
4
+ export declare function resolveUtteranceLocate(utterance: ReadiumSpeechUtterance, segmentation: Segmentation): LocatorOptions[];
@@ -0,0 +1,6 @@
1
+ import { ReadiumSpeechUtterance } from '../utterance.js';
2
+ import { GndObject } from '../gnd/types.js';
3
+ import { SourceTrace, WalkContext } from './walkContext.js';
4
+ export declare function formatPlain(text: string, ctx: WalkContext): ReadiumSpeechUtterance;
5
+ export declare function push(out: ReadiumSpeechUtterance[], sources: SourceTrace, node: SourceTrace[number], items: ReadiumSpeechUtterance[]): void;
6
+ export declare function pushPiecesOrMerged(out: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext, node: GndObject, pieces: ReadiumSpeechUtterance[], pieceSources: SourceTrace, merged: ReadiumSpeechUtterance | undefined): void;
@@ -0,0 +1,4 @@
1
+ import { GndObject } from '../gnd/types.js';
2
+ import { ReadiumSpeechUtterance } from '../utterance.js';
3
+ import { SourceTrace, WalkContext } from './walkContext.js';
4
+ export declare function walk(nodes: GndObject[], out: ReadiumSpeechUtterance[], sources: SourceTrace, ctx: WalkContext, suppress: boolean): void;
@@ -0,0 +1,40 @@
1
+ import { i18n } from 'i18next';
2
+ import { GndObject, GndRole } from '../gnd/types.js';
3
+ import { LocatorOptions } from '../decorator/createLocator.js';
4
+ import { ReadiumSpeechUtterance } from '../utterance.js';
5
+ import { SentenceSegmenter } from './sentenceSegmenter.js';
6
+ import { ExtractionFormat, ExtractUtterancesOptions, LanguageMode, Segmentation, SubstitutionTable } from './types.js';
7
+ export interface WalkContext {
8
+ i18n: i18n;
9
+ skip: ReadonlySet<GndRole>;
10
+ contextualize: ReadonlySet<GndRole>;
11
+ contextualizationShapes: Partial<Record<GndRole, "inline" | "block">>;
12
+ contextualizationParams?: (role: GndRole, node: GndObject) => Record<string, string> | undefined;
13
+ format: ExtractionFormat;
14
+ inlineContextualization: boolean;
15
+ language?: LanguageMode;
16
+ segmentation: Segmentation;
17
+ segmentationSuppressions: Record<string, string[]>;
18
+ segmenter: SentenceSegmenter;
19
+ substitutions: SubstitutionTable;
20
+ blockStarts: Set<ReadiumSpeechUtterance>;
21
+ tableRowNumbers: Map<GndObject, number>;
22
+ tableCellHeaders: Map<GndObject, string>;
23
+ synthetic: Set<ReadiumSpeechUtterance>;
24
+ ancestorChains: Map<GndObject, GndObject[]>;
25
+ pendingRange: Map<ReadiumSpeechUtterance, {
26
+ start: number;
27
+ end: number;
28
+ }>;
29
+ edgeSubstitutedLocate: WeakMap<ReadiumSpeechUtterance, {
30
+ leading?: LocatorOptions;
31
+ trailing?: LocatorOptions;
32
+ }>;
33
+ }
34
+ export type SourceTrace = (GndObject | [GndObject, GndObject] | undefined)[];
35
+ export declare const blockLevelRoleSet: ReadonlySet<GndRole>;
36
+ export declare const deferrablePlaceholderRoleSet: ReadonlySet<GndRole>;
37
+ export declare const descriptionFoldingRoleSet: ReadonlySet<GndRole>;
38
+ export declare const valueFoldingRoleSet: ReadonlySet<GndRole>;
39
+ export declare const contentlessRoleSet: ReadonlySet<GndRole>;
40
+ export declare function makeWalkContext(nodes: GndObject[], options: ExtractUtterancesOptions): Promise<WalkContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.9.1",
3
+ "version": "0.10.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,11 +61,10 @@
61
61
  "vite-plugin-dts": "^4.5.4"
62
62
  },
63
63
  "dependencies": {
64
- "@readium/decorator": "1.2.0",
64
+ "@readium/decorator": "1.2.2",
65
65
  "@readium/helpers": "1.1.0",
66
- "@readium/shared": "2.5.0",
66
+ "@readium/shared": "2.5.1",
67
67
  "css-selector-generator": "^3.9.4",
68
- "i18next": "^26.4.0",
69
- "string-strip-html": "^13.4.23"
68
+ "i18next": "^26.4.0"
70
69
  }
71
70
  }