@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.
- package/README.md +18 -3
- package/build/Fallback/fallbackEngineProvider.d.ts +1 -0
- package/build/Fallback/fallbackSpeechEngine.d.ts +7 -1
- package/build/Fallback/recoverableFailure.d.ts +2 -1
- package/build/SpeechServer/index.d.ts +7 -7
- package/build/SpeechServer/speechServerEngine.d.ts +1 -1
- package/build/SpeechServer/speechServerEngineProvider.d.ts +1 -0
- package/build/WebSpeech/WebSpeechVoiceManager.d.ts +1 -1
- package/build/WebSpeech/webSpeechEngine.d.ts +3 -2
- package/build/WebSpeech/webSpeechEngineProvider.d.ts +1 -0
- package/build/engine.d.ts +1 -1
- package/build/index.js +2773 -2053
- package/build/navigator.d.ts +59 -4
- package/build/preferences/index.d.ts +1 -1
- package/build/provider.d.ts +1 -0
- package/build/speechNavigator.d.ts +3 -19
- 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/languageCode.d.ts +1 -0
- package/build/voices/reachability.d.ts +2 -0
- package/build/voices/voiceSelection.d.ts +35 -0
- package/package.json +9 -6
- package/build/voices/voiceForLanguage.d.ts +0 -6
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 {};
|
|
@@ -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';
|
|
@@ -31,7 +31,6 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
31
31
|
private readonly languages;
|
|
32
32
|
private contentQueue;
|
|
33
33
|
private loadedQueue;
|
|
34
|
-
private loadedLanguages;
|
|
35
34
|
private readonly events;
|
|
36
35
|
private navigatorState;
|
|
37
36
|
private pendingAdvanceTimeout;
|
|
@@ -49,11 +48,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
49
48
|
private pendingResumeIndex;
|
|
50
49
|
private pendingResumeState;
|
|
51
50
|
private pendingAutoPauseIndex;
|
|
52
|
-
private
|
|
53
|
-
private voiceIds;
|
|
54
|
-
private pickedVoices;
|
|
55
|
-
private pickingVoices;
|
|
56
|
-
private voiceListing;
|
|
51
|
+
private voiceSelection;
|
|
57
52
|
private reportedLanguageFallbacks;
|
|
58
53
|
private notifiedVoice;
|
|
59
54
|
private loadGeneration;
|
|
@@ -61,21 +56,10 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
61
56
|
private applyEngineParameters;
|
|
62
57
|
private initializeEngine;
|
|
63
58
|
private spokenLanguages;
|
|
64
|
-
private voiceIdFor;
|
|
65
|
-
private needsBoundary;
|
|
66
|
-
private pickKey;
|
|
67
|
-
private pickedVoice;
|
|
68
|
-
private pickVoice;
|
|
69
|
-
private pickVoices;
|
|
70
59
|
private refreshVoices;
|
|
71
60
|
private refreshVoicesForEngine;
|
|
72
61
|
private notifyVoicesChanged;
|
|
73
62
|
private spokenVoice;
|
|
74
|
-
private availableVoice;
|
|
75
|
-
private preferredVoiceIds;
|
|
76
|
-
private listedVoiceId;
|
|
77
|
-
private pickedVoiceRecord;
|
|
78
|
-
private pickedVoiceKey;
|
|
79
63
|
private setupEngineListeners;
|
|
80
64
|
private setNavigatorState;
|
|
81
65
|
getVoices(): Promise<ReadiumSpeechVoice[]>;
|
|
@@ -102,7 +86,7 @@ export declare class ReadiumSpeechNavigator implements ReadiumSpeechNavigatorCon
|
|
|
102
86
|
previous(forcePlay?: boolean): boolean;
|
|
103
87
|
jumpTo(utteranceIndex: number, forcePlay?: boolean): boolean;
|
|
104
88
|
getState(): ReadiumSpeechPlaybackState;
|
|
105
|
-
on
|
|
89
|
+
on<T extends ReadiumSpeechNavigatorEvent["type"]>(event: T, listener: (event: ReadiumSpeechNavigatorEvent<T>) => void): () => void;
|
|
106
90
|
private emitEvent;
|
|
107
91
|
private emitUtteranceBoundary;
|
|
108
92
|
private emitContentChangeEvent;
|
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;
|
|
@@ -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
|
|
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
|
|
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
|