@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.
- package/README.md +18 -3
- package/build/Fallback/fallbackEngineProvider.d.ts +1 -0
- package/build/Fallback/fallbackSpeechEngine.d.ts +9 -2
- package/build/Fallback/recoverableFailure.d.ts +2 -1
- package/build/SpeechServer/index.d.ts +7 -7
- package/build/SpeechServer/speechServerEngine.d.ts +1 -3
- package/build/SpeechServer/speechServerEngineProvider.d.ts +1 -0
- package/build/WebSpeech/WebSpeechVoiceManager.d.ts +1 -1
- package/build/WebSpeech/webSpeechEngine.d.ts +8 -9
- package/build/WebSpeech/webSpeechEngineProvider.d.ts +1 -0
- package/build/engine.d.ts +2 -2
- package/build/index.d.ts +1 -0
- package/build/index.js +2541 -1727
- package/build/navigator.d.ts +59 -4
- package/build/preferences/SpeechSettings.d.ts +1 -5
- package/build/preferences/index.d.ts +1 -1
- package/build/provider.d.ts +1 -0
- package/build/speechNavigator.d.ts +17 -3
- package/build/utils/patches.d.ts +1 -0
- package/build/utils/text.d.ts +2 -1
- package/build/utterances/abbreviationAlias.d.ts +28 -0
- package/build/utterances/blocks.d.ts +5 -0
- package/build/utterances/boundaryLocate.d.ts +2 -1
- package/build/utterances/contextualization.d.ts +4 -4
- package/build/utterances/index.d.ts +3 -1
- package/build/utterances/language.d.ts +5 -5
- package/build/utterances/locate.d.ts +3 -2
- package/build/utterances/mergeUtterances.d.ts +9 -12
- package/build/utterances/nodeFields.d.ts +2 -1
- package/build/utterances/piece.d.ts +50 -0
- package/build/utterances/plainText.d.ts +31 -0
- package/build/utterances/sentenceBoundaryMerge.d.ts +1 -0
- package/build/utterances/sentenceReconstruction.d.ts +3 -6
- package/build/utterances/sentenceSegmenter.d.ts +2 -0
- package/build/utterances/sourceSpans.d.ts +45 -0
- package/build/utterances/splitSsmlAtSentences.d.ts +2 -1
- package/build/utterances/ssml.d.ts +49 -0
- package/build/utterances/tableStructure.d.ts +2 -0
- package/build/utterances/text.d.ts +17 -21
- package/build/utterances/utteranceOutput.d.ts +7 -6
- package/build/utterances/walk.d.ts +3 -3
- package/build/utterances/walkContext.d.ts +1 -16
- package/build/voices/defaultVoice.d.ts +13 -0
- package/build/voices/languageCode.d.ts +10 -0
- package/build/voices/languages.d.ts +2 -9
- package/build/voices/reachability.d.ts +2 -0
- package/build/voices/voiceSelection.d.ts +35 -0
- package/package.json +9 -6
- package/build/voices/languageMatching.d.ts +0 -3
package/build/navigator.d.ts
CHANGED
|
@@ -4,11 +4,65 @@ import { SpeechPreferences } from './preferences/SpeechPreferences.js';
|
|
|
4
4
|
import { SpeechSettings } from './preferences/SpeechSettings.js';
|
|
5
5
|
import { ReadiumSpeechVoice } from './voices/types.js';
|
|
6
6
|
import { ReadiumSpeechUtterance } from './utterance.js';
|
|
7
|
+
import { LocatorOptions } from './decorator/createLocator.js';
|
|
8
|
+
import { ErrorEventDetail } from './Fallback/recoverableFailure.js';
|
|
7
9
|
export type ReadiumSpeechPlaybackState = "playing" | "paused" | "idle" | "loading" | "ready";
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export interface ReadiumSpeechBoundaryDetail {
|
|
11
|
+
name: string;
|
|
12
|
+
charIndex: number;
|
|
13
|
+
charLength: number;
|
|
14
|
+
elapsedTime?: number;
|
|
15
|
+
locate?: LocatorOptions | LocatorOptions[];
|
|
16
|
+
word?: string;
|
|
11
17
|
}
|
|
18
|
+
export interface ReadiumSpeechPlaybackEventDetails {
|
|
19
|
+
start: {
|
|
20
|
+
voice: ReadiumSpeechVoice | null;
|
|
21
|
+
};
|
|
22
|
+
pause: undefined;
|
|
23
|
+
resume: undefined;
|
|
24
|
+
end: undefined;
|
|
25
|
+
stop: undefined;
|
|
26
|
+
skip: {
|
|
27
|
+
position: number;
|
|
28
|
+
};
|
|
29
|
+
error: ErrorEventDetail;
|
|
30
|
+
boundary: ReadiumSpeechBoundaryDetail;
|
|
31
|
+
mark: {
|
|
32
|
+
name: string;
|
|
33
|
+
};
|
|
34
|
+
idle: undefined;
|
|
35
|
+
loading: undefined;
|
|
36
|
+
ready: undefined;
|
|
37
|
+
voiceschanged: undefined;
|
|
38
|
+
languagefallback: {
|
|
39
|
+
language: string;
|
|
40
|
+
reason: "no-matching-voice";
|
|
41
|
+
};
|
|
42
|
+
enginefallback: {
|
|
43
|
+
reason: ErrorEventDetail;
|
|
44
|
+
voice: ReadiumSpeechVoice | null;
|
|
45
|
+
};
|
|
46
|
+
enginerecovered: {
|
|
47
|
+
voice: ReadiumSpeechVoice | null;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface ReadiumSpeechNavigatorEventDetails extends ReadiumSpeechPlaybackEventDetails {
|
|
51
|
+
contentchange: {
|
|
52
|
+
content: ReadiumSpeechUtterance[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
type EventOf<Details, T extends keyof Details> = {
|
|
56
|
+
[K in T]: Details[K] extends undefined ? {
|
|
57
|
+
type: K;
|
|
58
|
+
detail?: undefined;
|
|
59
|
+
} : {
|
|
60
|
+
type: K;
|
|
61
|
+
detail: Details[K];
|
|
62
|
+
};
|
|
63
|
+
}[T];
|
|
64
|
+
export type ReadiumSpeechPlaybackEvent<T extends keyof ReadiumSpeechPlaybackEventDetails = keyof ReadiumSpeechPlaybackEventDetails> = EventOf<ReadiumSpeechPlaybackEventDetails, T>;
|
|
65
|
+
export type ReadiumSpeechNavigatorEvent<T extends keyof ReadiumSpeechNavigatorEventDetails = keyof ReadiumSpeechNavigatorEventDetails> = EventOf<ReadiumSpeechNavigatorEventDetails, T>;
|
|
12
66
|
export interface ReadiumSpeechContentOptions {
|
|
13
67
|
language?: string;
|
|
14
68
|
}
|
|
@@ -25,6 +79,7 @@ export interface ReadiumSpeechNavigatorContract extends Configurable<SpeechSetti
|
|
|
25
79
|
previous(): boolean;
|
|
26
80
|
jumpTo(utteranceIndex: number): void;
|
|
27
81
|
getState(): ReadiumSpeechPlaybackState;
|
|
28
|
-
on(event:
|
|
82
|
+
on<T extends keyof ReadiumSpeechNavigatorEventDetails>(event: T, listener: (event: ReadiumSpeechNavigatorEvent<T>) => void): () => void;
|
|
29
83
|
destroy(): Promise<void>;
|
|
30
84
|
}
|
|
85
|
+
export {};
|
|
@@ -3,7 +3,6 @@ import { ConfigurableSettings } from './Configurable.js';
|
|
|
3
3
|
import { SpeechDefaults } from './SpeechDefaults.js';
|
|
4
4
|
import { AutoPauseScope, SpeechPreferences, VerbosityPreset, VoicePreference } from './SpeechPreferences.js';
|
|
5
5
|
import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
|
|
6
|
-
import { ReadiumSpeechVoice } from '../voices/types.js';
|
|
7
6
|
export declare class SpeechSettings implements ConfigurableSettings {
|
|
8
7
|
[key: string]: unknown;
|
|
9
8
|
readonly format: ExtractionFormat;
|
|
@@ -21,8 +20,5 @@ export declare class SpeechSettings implements ConfigurableSettings {
|
|
|
21
20
|
readonly rate: number;
|
|
22
21
|
readonly pitch: number;
|
|
23
22
|
readonly volume: number;
|
|
24
|
-
|
|
25
|
-
* @param engineVoice The engine's voice, which `voice` falls back to: when unset, or for its language in a record without it.
|
|
26
|
-
*/
|
|
27
|
-
constructor(preferences: SpeechPreferences, defaults: SpeechDefaults, engineVoice?: ReadiumSpeechVoice | null);
|
|
23
|
+
constructor(preferences: SpeechPreferences, defaults: SpeechDefaults);
|
|
28
24
|
}
|
|
@@ -5,7 +5,7 @@ export type { IEnumPreference, IPreference, IRangePreference } from './Preferenc
|
|
|
5
5
|
export { SpeechPreferences } from './SpeechPreferences.js';
|
|
6
6
|
export type { AutoPauseScope, ISpeechPreferences, VerbosityPreset, VoicePreference } from './SpeechPreferences.js';
|
|
7
7
|
export type { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
|
|
8
|
-
export { autoPauseScopes, extractionFormats, extractionPreferenceKeys, languageModes, pauseDurationRangeConfig, pitchRangeConfig, rateRangeConfig, segmentationModes, verbosityPresets, volumeRangeConfig, } from './constraints.js';
|
|
8
|
+
export { autoPauseScopes, extractionFormats, extractionPreferenceKeys, interruptionValues, languageModes, pauseDurationRangeConfig, pitchRangeConfig, rateRangeConfig, segmentationModes, verbosityPresets, volumeRangeConfig, } from './constraints.js';
|
|
9
9
|
export type { RangeConfig } from './constraints.js';
|
|
10
10
|
export { SpeechDefaults } from './SpeechDefaults.js';
|
|
11
11
|
export type { ISpeechDefaults } from './SpeechDefaults.js';
|
package/build/provider.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface ReadiumSpeechEngineProvider {
|
|
|
4
4
|
readonly id: string;
|
|
5
5
|
readonly name: string;
|
|
6
6
|
getVoices(forceRefresh?: boolean): Promise<ReadiumSpeechVoice[]>;
|
|
7
|
+
isAvailable?(): Promise<boolean>;
|
|
7
8
|
createEngine(voice?: ReadiumSpeechVoice | string): Promise<ReadiumSpeechPlaybackEngine>;
|
|
8
9
|
destroy(): Promise<void>;
|
|
9
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReadiumSpeechPlaybackEngine } from './engine.js';
|
|
2
2
|
import { GuidedNavigationObject } from '@readium/shared';
|
|
3
|
-
import { ReadiumSpeechContentOptions, ReadiumSpeechNavigatorContract,
|
|
3
|
+
import { ReadiumSpeechContentOptions, ReadiumSpeechNavigatorContract, ReadiumSpeechNavigatorEvent, ReadiumSpeechPlaybackState } from './navigator.js';
|
|
4
4
|
import { ISpeechDefaults } from './preferences/SpeechDefaults.js';
|
|
5
5
|
import { ISpeechPreferences, SpeechPreferences } from './preferences/SpeechPreferences.js';
|
|
6
6
|
import { SpeechPreferencesEditor } from './preferences/SpeechPreferencesEditor.js';
|
|
@@ -24,9 +24,11 @@ export interface ReadiumSpeechNavigatorConfiguration {
|
|
|
24
24
|
defaults?: ISpeechDefaults;
|
|
25
25
|
contextualizationOverrides?: ContextualizationOverrides;
|
|
26
26
|
segmentationOverrides?: SegmentationOverrides;
|
|
27
|
+
languages?: string[];
|
|
27
28
|
}
|
|
28
29
|
export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorContract {
|
|
29
30
|
private engine;
|
|
31
|
+
private readonly languages;
|
|
30
32
|
private contentQueue;
|
|
31
33
|
private loadedQueue;
|
|
32
34
|
private readonly events;
|
|
@@ -36,7 +38,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
36
38
|
private _preferences;
|
|
37
39
|
private _settings;
|
|
38
40
|
private _preferencesEditor;
|
|
39
|
-
private
|
|
41
|
+
private preferencesEditorVoice;
|
|
40
42
|
private readonly contextualizationOverrides?;
|
|
41
43
|
private readonly segmentationOverrides?;
|
|
42
44
|
private source;
|
|
@@ -46,15 +48,26 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
46
48
|
private pendingResumeIndex;
|
|
47
49
|
private pendingResumeState;
|
|
48
50
|
private pendingAutoPauseIndex;
|
|
51
|
+
private voiceSelection;
|
|
52
|
+
private reportedLanguageFallbacks;
|
|
53
|
+
private notifiedVoice;
|
|
54
|
+
private loadGeneration;
|
|
49
55
|
constructor(engine: ReadiumSpeechPlaybackEngine, configuration?: ReadiumSpeechNavigatorConfiguration);
|
|
50
56
|
private applyEngineParameters;
|
|
51
57
|
private initializeEngine;
|
|
58
|
+
private spokenLanguages;
|
|
59
|
+
private refreshVoices;
|
|
60
|
+
private refreshVoicesForEngine;
|
|
61
|
+
private notifyVoicesChanged;
|
|
62
|
+
private spokenVoice;
|
|
52
63
|
private setupEngineListeners;
|
|
53
64
|
private setNavigatorState;
|
|
54
65
|
getVoices(): Promise<ReadiumSpeechVoice[]>;
|
|
55
66
|
loadContent(content: ReadiumSpeechUtterance | ReadiumSpeechUtterance[], options?: ReadiumSpeechContentOptions): void;
|
|
56
67
|
loadGndContent(nodes: GuidedNavigationObject[], options?: ReadiumSpeechContentOptions): Promise<void>;
|
|
57
68
|
private setContentQueue;
|
|
69
|
+
private stamped;
|
|
70
|
+
private reportLanguageFallbacks;
|
|
58
71
|
private withLanguage;
|
|
59
72
|
private withVoice;
|
|
60
73
|
private reextract;
|
|
@@ -73,11 +86,12 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
73
86
|
previous(forcePlay?: boolean): boolean;
|
|
74
87
|
jumpTo(utteranceIndex: number, forcePlay?: boolean): boolean;
|
|
75
88
|
getState(): ReadiumSpeechPlaybackState;
|
|
76
|
-
on
|
|
89
|
+
on<T extends ReadiumSpeechNavigatorEvent["type"]>(event: T, listener: (event: ReadiumSpeechNavigatorEvent<T>) => void): () => void;
|
|
77
90
|
private emitEvent;
|
|
78
91
|
private emitUtteranceBoundary;
|
|
79
92
|
private emitContentChangeEvent;
|
|
80
93
|
get settings(): SpeechSettings;
|
|
94
|
+
private settingsWith;
|
|
81
95
|
get preferencesEditor(): SpeechPreferencesEditor;
|
|
82
96
|
submitPreferences(preferences: SpeechPreferences): Promise<void>;
|
|
83
97
|
private applyPreferences;
|
package/build/utils/patches.d.ts
CHANGED
package/build/utils/text.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const OPENING_PUNCT_CLASS = "\\p{Ps}\\p{Pi}\u00BF\u00A1";
|
|
2
2
|
export declare function startsWithOpeningPunct(s: string): boolean;
|
|
3
3
|
export declare function endsWithOpeningPunct(s: string): boolean;
|
|
4
|
+
export declare function joinsWithoutSpace(before: string, after: string): boolean;
|
|
5
|
+
export declare function meetsUnspaced(before: string, after: string): boolean;
|
|
4
6
|
export declare function isSinglePunctuationChar(s: string): boolean;
|
|
5
7
|
export declare function neutralizeAngleBrackets(text: string): string;
|
|
6
|
-
export declare function decodeResidualHtmlEntities(text: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Piece } from './piece.js';
|
|
2
|
+
import { SentenceBoundary } from './sentenceSegmenter.js';
|
|
3
|
+
import { WalkContext } from './walkContext.js';
|
|
4
|
+
export declare function isAlias(piece: Piece): boolean;
|
|
5
|
+
export declare function segmentAroundAliases(pieces: Piece[], plainParts: string[], joined: string, ranges: {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
}[], language: string, suppressions: string[] | undefined, ctx: WalkContext): Promise<SentenceBoundary[]>;
|
|
9
|
+
export type AliasSegmentation = {
|
|
10
|
+
boundaries: SentenceBoundary[];
|
|
11
|
+
textRanges: {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
}[];
|
|
15
|
+
included: number[];
|
|
16
|
+
};
|
|
17
|
+
export declare function segmentAliasText(pieces: Piece[], plainParts: string[], language: string, suppressions: string[] | undefined, ctx: WalkContext): Promise<AliasSegmentation>;
|
|
18
|
+
export declare function mapAliasBoundaries({ boundaries: textBoundaries, textRanges, included }: AliasSegmentation, pieces: Piece[], joined: string, ranges: {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
}[], ctx: WalkContext): SentenceBoundary[];
|
|
22
|
+
export declare function endsWithSentenceTerminator(text: string): boolean;
|
|
23
|
+
export declare function punctuateSentenceEndingAliases(pieces: Piece[], joined: string, ranges: {
|
|
24
|
+
start: number;
|
|
25
|
+
end: number;
|
|
26
|
+
}[], boundaries: SentenceBoundary[], ctx: WalkContext): boolean;
|
|
27
|
+
export declare function punctuateLoneAlias(piece: Piece, ctx: WalkContext): void;
|
|
28
|
+
export declare function mergeAliasPieces(out: Piece[], ctx: WalkContext): Promise<Piece[]>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
|
+
import { SourceTrace, WalkContext } from './walkContext.js';
|
|
3
|
+
export declare function isBlockNode(node: GuidedNavigationObject, ctx: WalkContext): boolean;
|
|
4
|
+
export declare function edgeNode(source: NonNullable<SourceTrace[number]>, edge: "leading" | "trailing"): GuidedNavigationObject;
|
|
5
|
+
export declare function blockOf(source: SourceTrace[number], edge: "leading" | "trailing", ctx: WalkContext): GuidedNavigationObject | undefined;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { LocatorOptions } from '../decorator/createLocator.js';
|
|
2
|
-
import { ReadiumSpeechUtterance } from '../utterance.js';
|
|
2
|
+
import { ReadiumSpeechUtterance, UtteranceOffset } from '../utterance.js';
|
|
3
3
|
export declare function recordSubstitutionSource(utterance: ReadiumSpeechUtterance, source: {
|
|
4
4
|
plain: string;
|
|
5
5
|
map: number[];
|
|
6
6
|
}): void;
|
|
7
7
|
export declare function markNonQuotable<T extends LocatorOptions>(locate: T): T;
|
|
8
|
+
export declare function recordAliasOffset(offset: UtteranceOffset, spokenLength: number): void;
|
|
8
9
|
export declare function resolveBoundaryLocate(utterance: ReadiumSpeechUtterance, charIndex: number, charLength: number): {
|
|
9
10
|
locate: LocatorOptions;
|
|
10
11
|
word: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
2
|
import { GndRole } from '@readium/guided-navigation';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { WalkContext } from './walkContext.js';
|
|
4
|
+
import { Piece } from './piece.js';
|
|
5
5
|
export declare function resolveEntryText(ctx: WalkContext, base: string, variantKey?: string, params?: Record<string, string>): string | undefined;
|
|
6
6
|
export declare function isRoleContextualized(role: string, ctx: WalkContext): boolean;
|
|
7
7
|
export declare function isDroppedByAnotherRole(role: GndRole, roles: GndRole[], ctx: WalkContext): boolean;
|
|
8
|
-
export declare function scopeToQuote(utterance:
|
|
9
|
-
export declare function pushRoleContextualization(out:
|
|
8
|
+
export declare function scopeToQuote(utterance: Piece, at: number | undefined, quoteText: string, node: GuidedNavigationObject, ctx: WalkContext): void;
|
|
9
|
+
export declare function pushRoleContextualization(out: Piece[], node: GuidedNavigationObject, ctx: WalkContext, role: string, phase: "before" | "after", variantKey?: string, params?: Record<string, string>): void;
|
|
10
10
|
export declare function resolvePluralPart(ctx: WalkContext, role: string, name: string, count: number): string;
|
|
11
11
|
type ContextualizationParams = {
|
|
12
12
|
variantKey?: string;
|
|
@@ -3,5 +3,7 @@ export { resolveBoundaryLocate } from './boundaryLocate.js';
|
|
|
3
3
|
export { resolveUtteranceLocate } from './utteranceLocate.js';
|
|
4
4
|
export { blockLevelRoles, interruptionRoles, skippableRoles } from './roles.js';
|
|
5
5
|
export { defaultContextualizations } from './contextualizations.js';
|
|
6
|
-
export
|
|
6
|
+
export { builtInSubstitutions } from './builtInSubstitutions.js';
|
|
7
|
+
export { builtInSuppressions } from './builtInSuppressions.js';
|
|
8
|
+
export type { ContextualizationEntry, Contextualizations, ContextualizationOptions, ExtractUtterancesOptions, Interruption, Segmentation, SegmentationOptions, SubstitutionRule, SubstitutionTable, } from './types.js';
|
|
7
9
|
export type { SentenceBoundary, SentenceSegmenter } from './sentenceSegmenter.js';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReadiumSpeechUtterance } from '../utterance.js';
|
|
2
1
|
import { WalkContext } from './walkContext.js';
|
|
2
|
+
import { Piece } from './piece.js';
|
|
3
3
|
export declare function stripLangTags(ssml: string): string;
|
|
4
4
|
export declare function overriddenLanguage(language: string | undefined, languageOverrides: Record<string, string>): string | undefined;
|
|
5
5
|
export declare function languageFor(declared: string | undefined, ctx: WalkContext): string | undefined;
|
|
6
6
|
export declare function sameLanguage(a: string | undefined, b: string | undefined): boolean;
|
|
7
|
-
export declare function sharedLanguage(pieces:
|
|
8
|
-
export declare function runLanguage(pieces:
|
|
9
|
-
export declare function ssmlInLanguage(piece:
|
|
10
|
-
export declare function languageRuns(pieces:
|
|
7
|
+
export declare function sharedLanguage(pieces: Piece[], ctx: WalkContext): string | undefined | null;
|
|
8
|
+
export declare function runLanguage(pieces: Piece[], ctx: WalkContext): string | undefined | null;
|
|
9
|
+
export declare function ssmlInLanguage(piece: Piece, runLanguage: string | undefined, ctx: WalkContext): string;
|
|
10
|
+
export declare function languageRuns(pieces: Piece[], ctx: WalkContext): [number, number][];
|
|
11
11
|
export declare function overrideLangTags(ssml: string, languageOverrides: Record<string, string>): string;
|
|
@@ -2,7 +2,8 @@ import { GuidedNavigationObject } from '@readium/shared';
|
|
|
2
2
|
import { DecodedTextref } from '@readium/guided-navigation';
|
|
3
3
|
import { LocatorOptions } from '../decorator/createLocator.js';
|
|
4
4
|
import { ReadiumSpeechUtterance } from '../utterance.js';
|
|
5
|
-
import {
|
|
5
|
+
import { WalkContext } from './walkContext.js';
|
|
6
|
+
import { Piece } from './piece.js';
|
|
6
7
|
export declare function subLocateFor(nodeRef: DecodedTextref, quoteText: string): LocatorOptions;
|
|
7
8
|
export declare function resolveNodeLocate(node: GuidedNavigationObject, ancestorChains: Map<GuidedNavigationObject, GuidedNavigationObject[]>): {
|
|
8
9
|
own: boolean;
|
|
@@ -19,4 +20,4 @@ export declare function spanLocate(firstRef: {
|
|
|
19
20
|
own: boolean;
|
|
20
21
|
ref: DecodedTextref;
|
|
21
22
|
} | undefined, fallback: LocatorOptions | undefined): LocatorOptions | undefined;
|
|
22
|
-
export declare function attachLocate(
|
|
23
|
+
export declare function attachLocate(pieces: Piece[], ctx: WalkContext): ReadiumSpeechUtterance[];
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
2
|
import { LocatorOptions } from '../decorator/createLocator.js';
|
|
3
|
-
import { ReadiumSpeechUtterance, UtteranceOffset } from '../utterance.js';
|
|
4
3
|
import { ResolvedNodeText } from './text.js';
|
|
5
4
|
import { ExtractionFormat, LanguageMode } from './types.js';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}[];
|
|
13
|
-
};
|
|
5
|
+
import { WalkContext } from './walkContext.js';
|
|
6
|
+
import { Piece } from './piece.js';
|
|
7
|
+
export declare function pieceIndexAt(ranges: {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
}[], pos: number): number;
|
|
14
11
|
export declare function substitutedBareLocate(node: GuidedNavigationObject, ctx: WalkContext): LocatorOptions | undefined;
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function applyFormat(resolved: ResolvedNodeText, format: ExtractionFormat, language: LanguageMode | undefined, ctx: WalkContext): ReadiumSpeechUtterance[];
|
|
12
|
+
export declare function mergeUtterances(pieces: Piece[], ctx: WalkContext): Piece | undefined;
|
|
13
|
+
export declare function applyFormat(node: GuidedNavigationObject, resolved: ResolvedNodeText, format: ExtractionFormat, language: LanguageMode | undefined, ctx: WalkContext): Piece[];
|
|
18
14
|
export declare function plainOf(text: string, format: ExtractionFormat): string;
|
|
15
|
+
export declare function pieceText(piece: Piece, ctx: WalkContext): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GuidedNavigationText, GuidedNavigationObject } from '@readium/shared';
|
|
2
2
|
import { GndRole } from '@readium/guided-navigation';
|
|
3
3
|
export declare function nodeRoles(node: GuidedNavigationObject): GndRole[];
|
|
4
|
+
export declare function nodeText(text: GuidedNavigationText | undefined): GuidedNavigationText | undefined;
|
|
4
5
|
export declare function spokenText(node: GuidedNavigationObject): GuidedNavigationText | undefined;
|
|
5
6
|
export declare function descriptionOf(node: GuidedNavigationObject): string | undefined;
|
|
6
7
|
export declare function descriptionLanguageOf(node: GuidedNavigationObject): string | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
|
+
import { LocatorOptions } from '../decorator/createLocator.js';
|
|
3
|
+
import { ReadiumSpeechUtterance } from '../utterance.js';
|
|
4
|
+
import { SsmlElement } from './ssml.js';
|
|
5
|
+
import { SourceSpan } from './sourceSpans.js';
|
|
6
|
+
import { SourceTrace } from './walkContext.js';
|
|
7
|
+
export type PieceSpacing = "touching" | "spaced" | undefined;
|
|
8
|
+
export interface Placement {
|
|
9
|
+
node: GuidedNavigationObject;
|
|
10
|
+
kind?: "inline" | "after" | "alias";
|
|
11
|
+
abbreviation?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PieceTags {
|
|
14
|
+
open: SsmlElement[];
|
|
15
|
+
close: SsmlElement[];
|
|
16
|
+
around: SsmlElement[];
|
|
17
|
+
}
|
|
18
|
+
export interface Piece {
|
|
19
|
+
plain?: string;
|
|
20
|
+
ssml?: string;
|
|
21
|
+
language?: string;
|
|
22
|
+
locate?: LocatorOptions;
|
|
23
|
+
source?: SourceTrace[number];
|
|
24
|
+
spans?: SourceSpan[];
|
|
25
|
+
synthetic?: boolean;
|
|
26
|
+
blockStart?: boolean;
|
|
27
|
+
placement?: Placement;
|
|
28
|
+
spacing?: PieceSpacing;
|
|
29
|
+
tags?: PieceTags;
|
|
30
|
+
enclosingLanguage?: string;
|
|
31
|
+
edgeLocates?: {
|
|
32
|
+
leading?: LocatorOptions;
|
|
33
|
+
trailing?: LocatorOptions;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare function toUtterance(piece: Piece): ReadiumSpeechUtterance;
|
|
37
|
+
export declare function nestTags(pieces: Piece[], around: SsmlElement[]): void;
|
|
38
|
+
export declare function balancedSsml(piece: Piece): string;
|
|
39
|
+
export declare function encloseOwnTags(piece: Piece): void;
|
|
40
|
+
export declare function joinPieceTexts(parts: string[], spacing?: PieceSpacing[]): {
|
|
41
|
+
joined: string;
|
|
42
|
+
ranges: {
|
|
43
|
+
start: number;
|
|
44
|
+
end: number;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
export declare function joinPieceSsml(pieces: Piece[], texts: string[], plainParts: string[], ranges: {
|
|
48
|
+
start: number;
|
|
49
|
+
end: number;
|
|
50
|
+
}[]): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SsmlElement, SsmlNode } from './ssml.js';
|
|
2
|
+
export declare function breakSpaced(before: string, after: string): boolean;
|
|
3
|
+
export declare function separatesWords(markup: string): boolean;
|
|
4
|
+
export type PlainPiece = {
|
|
5
|
+
kind: "text";
|
|
6
|
+
text: string;
|
|
7
|
+
start: number;
|
|
8
|
+
positions: number[];
|
|
9
|
+
chain: SsmlElement[];
|
|
10
|
+
} | {
|
|
11
|
+
kind: "separator";
|
|
12
|
+
start: number;
|
|
13
|
+
position: number;
|
|
14
|
+
chain: SsmlElement[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: "element";
|
|
17
|
+
node: SsmlNode;
|
|
18
|
+
chain: SsmlElement[];
|
|
19
|
+
};
|
|
20
|
+
export declare function layoutSsml(ssml: string): {
|
|
21
|
+
plain: string;
|
|
22
|
+
pieces: PlainPiece[];
|
|
23
|
+
};
|
|
24
|
+
export declare function textReader(pieces: PlainPiece[]): (from: number, to: number) => string;
|
|
25
|
+
export declare function stripSsmlTagsKeepSpacing(ssml: string): string;
|
|
26
|
+
export declare function stripSsmlTagsWithMap(ssml: string): {
|
|
27
|
+
plain: string;
|
|
28
|
+
map: number[];
|
|
29
|
+
};
|
|
30
|
+
export declare function stripSsmlTags(ssml: string): string;
|
|
31
|
+
export declare function ssmlIndexToPlainIndex(map: number[], ssmlIndex: number): number;
|
|
@@ -4,4 +4,5 @@ interface RawBoundary {
|
|
|
4
4
|
end: number;
|
|
5
5
|
}
|
|
6
6
|
export declare function refineSentenceBoundaries(text: string, raw: RawBoundary[], suppressions: string[]): SentenceBoundary[];
|
|
7
|
+
export declare function mergeBoundaries(text: string, boundaries: SentenceBoundary[], joinsNext: (boundary: SentenceBoundary, next: SentenceBoundary) => boolean): SentenceBoundary[];
|
|
7
8
|
export {};
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function splitIntoSentenceUtterances(out:
|
|
4
|
-
out: ReadiumSpeechUtterance[];
|
|
5
|
-
sources: SourceTrace;
|
|
6
|
-
}>;
|
|
1
|
+
import { WalkContext } from './walkContext.js';
|
|
2
|
+
import { Piece } from './piece.js';
|
|
3
|
+
export declare function splitIntoSentenceUtterances(out: Piece[], ctx: WalkContext): Promise<Piece[]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { WalkContext } from './walkContext.js';
|
|
1
2
|
export interface SentenceBoundary {
|
|
2
3
|
text: string;
|
|
3
4
|
start: number;
|
|
@@ -6,4 +7,5 @@ export interface SentenceBoundary {
|
|
|
6
7
|
}
|
|
7
8
|
export type SentenceSegmenter = (language: string, text: string, customSuppressions?: string[]) => Promise<SentenceBoundary[]>;
|
|
8
9
|
export declare function suppressionLanguage(language: string): string;
|
|
10
|
+
export declare function callerSuppressions(language: string, ctx: WalkContext): string[] | undefined;
|
|
9
11
|
export declare function segmentSentences(language: string, text: string, customSuppressions?: string[]): Promise<SentenceBoundary[]>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
|
+
import { LocatorOptions } from '../decorator/createLocator.js';
|
|
3
|
+
import { UtteranceOffset } from '../utterance.js';
|
|
4
|
+
import { Piece } from './piece.js';
|
|
5
|
+
import { WalkContext } from './walkContext.js';
|
|
6
|
+
export type SourceSpan = TextSpan | AliasSpan;
|
|
7
|
+
interface TextSpan {
|
|
8
|
+
node: GuidedNavigationObject;
|
|
9
|
+
ownText: string;
|
|
10
|
+
at: number;
|
|
11
|
+
map: number[];
|
|
12
|
+
quotedOnly?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface AliasSpan {
|
|
15
|
+
node: GuidedNavigationObject;
|
|
16
|
+
at: number;
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
alias: LocatorOptions;
|
|
20
|
+
length?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function spansOf(utterance: Piece, ctx: WalkContext): SourceSpan[];
|
|
23
|
+
export declare function setSpans(utterance: Piece, spans: SourceSpan[]): void;
|
|
24
|
+
export declare function setAliasSpan(piece: Piece, node: GuidedNavigationObject, range: {
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
}, alias: LocatorOptions): void;
|
|
28
|
+
export declare function setQuotedSpan(utterance: Piece, node: GuidedNavigationObject, ownText: string, at: number): void;
|
|
29
|
+
export declare function sliceSpans(spans: SourceSpan[], from: number, to: number): SourceSpan[];
|
|
30
|
+
export declare function joinedSpans(pieces: Piece[], ranges: {
|
|
31
|
+
start: number;
|
|
32
|
+
end: number;
|
|
33
|
+
}[], ctx: WalkContext): SourceSpan[];
|
|
34
|
+
export interface OwnTextAligner {
|
|
35
|
+
place(text: string): TextSpan | undefined;
|
|
36
|
+
embed(childText: string): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function ownTextAligner(node: GuidedNavigationObject): OwnTextAligner;
|
|
39
|
+
export declare function ownRange(spans: (SourceSpan | undefined)[]): {
|
|
40
|
+
start: number;
|
|
41
|
+
end: number;
|
|
42
|
+
} | undefined;
|
|
43
|
+
export declare function placeInOwnText(pieces: Piece[], node: GuidedNavigationObject, ctx: WalkContext): void;
|
|
44
|
+
export declare function buildOffsets(utterance: Piece, ctx: WalkContext): UtteranceOffset[];
|
|
45
|
+
export {};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { SentenceSegmenter } from './sentenceSegmenter.js';
|
|
1
|
+
import { SentenceBoundary, SentenceSegmenter } from './sentenceSegmenter.js';
|
|
2
2
|
export declare function splitSsmlAtSentences(ssml: string, language: string, segmenter: SentenceSegmenter, customSuppressions?: string[]): Promise<string[] | undefined>;
|
|
3
|
+
export declare function keepUnrepeatableWhole(ssml: string, boundaries: SentenceBoundary[]): SentenceBoundary[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export interface SsmlElement {
|
|
2
|
+
kind: "element";
|
|
3
|
+
name: string;
|
|
4
|
+
attrs: Map<string, string>;
|
|
5
|
+
children: SsmlNode[];
|
|
6
|
+
selfClosing: boolean;
|
|
7
|
+
openTag: string;
|
|
8
|
+
start: number;
|
|
9
|
+
closeStart: number;
|
|
10
|
+
end: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SsmlText {
|
|
13
|
+
kind: "text";
|
|
14
|
+
text: string;
|
|
15
|
+
positions?: number[];
|
|
16
|
+
}
|
|
17
|
+
export type SsmlNode = SsmlElement | SsmlText;
|
|
18
|
+
export interface SsmlLeaf {
|
|
19
|
+
node: SsmlText | SsmlElement;
|
|
20
|
+
ancestors: SsmlElement[];
|
|
21
|
+
}
|
|
22
|
+
export declare const SSML_ENTITY_RE: RegExp;
|
|
23
|
+
export declare function decodeSsmlEntities(text: string): string;
|
|
24
|
+
export declare function ssmlEntityAt(text: string, index: number): {
|
|
25
|
+
length: number;
|
|
26
|
+
decoded: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
export declare function ssmlMarkup(ssml: string): string | undefined;
|
|
29
|
+
export declare function parseSsml(ssml: string): SsmlNode[];
|
|
30
|
+
export declare function closeTag(element: SsmlElement): string;
|
|
31
|
+
export declare function openTags(elements: SsmlElement[]): string;
|
|
32
|
+
export declare function closeTags(elements: SsmlElement[]): string;
|
|
33
|
+
export declare function serializeSsml(nodes: SsmlNode[]): string;
|
|
34
|
+
export declare function commonAncestors(a: SsmlElement[], b: SsmlElement[]): SsmlElement[];
|
|
35
|
+
export declare class SsmlWriter {
|
|
36
|
+
private out;
|
|
37
|
+
private open;
|
|
38
|
+
private moveTo;
|
|
39
|
+
text(chain: SsmlElement[], text: string): void;
|
|
40
|
+
node(chain: SsmlElement[], node: SsmlNode): void;
|
|
41
|
+
flush(): string;
|
|
42
|
+
}
|
|
43
|
+
export declare function isUnrepeatable(element: SsmlElement): boolean;
|
|
44
|
+
export declare function declaredLanguage(element: SsmlElement): string | undefined;
|
|
45
|
+
export declare function ssmlElements(nodes: SsmlNode[]): Generator<SsmlElement>;
|
|
46
|
+
export declare function setSsmlAttribute(element: SsmlElement, name: string, value: string | undefined): void;
|
|
47
|
+
export declare function bindNamespacesInward(ssml: string, unwrapped: (element: SsmlElement) => boolean): string;
|
|
48
|
+
export declare function unwrapSsmlElements(nodes: SsmlNode[], unwrap: (element: SsmlElement) => boolean): SsmlNode[];
|
|
49
|
+
export declare function ssmlLeaves(nodes: SsmlNode[], whole?: (element: SsmlElement) => boolean, ancestors?: SsmlElement[]): SsmlLeaf[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GuidedNavigationObject } from '@readium/shared';
|
|
2
2
|
export declare function plainTextOf(node: GuidedNavigationObject): string;
|
|
3
|
+
export declare function redundantCaptionOf(node: GuidedNavigationObject): GuidedNavigationObject | undefined;
|
|
4
|
+
export declare function spokenDescriptionOf(node: GuidedNavigationObject): string | undefined;
|
|
3
5
|
export interface TableStructure {
|
|
4
6
|
lines: number;
|
|
5
7
|
columns: number;
|