@readium/speech 0.16.1 → 0.17.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.
@@ -1,9 +1,9 @@
1
1
  import { GndRole } from '@readium/guided-navigation';
2
2
  import { AutoPauseScope, VerbosityPreset, VoicePreference } from './SpeechPreferences.js';
3
- import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
3
+ import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
4
4
  export interface ISpeechDefaults {
5
5
  format?: ExtractionFormat | null;
6
- inlineContextualization?: GndRole[] | null;
6
+ interruptions?: Partial<Record<GndRole, Interruption>> | null;
7
7
  verbosity?: VerbosityPreset | null;
8
8
  skip?: GndRole[] | null;
9
9
  contextualize?: GndRole[] | null;
@@ -19,7 +19,7 @@ export interface ISpeechDefaults {
19
19
  }
20
20
  export declare class SpeechDefaults {
21
21
  readonly format: ExtractionFormat;
22
- readonly inlineContextualization: GndRole[];
22
+ readonly interruptions: Partial<Record<GndRole, Interruption>>;
23
23
  readonly verbosity: VerbosityPreset;
24
24
  readonly skip: GndRole[];
25
25
  readonly contextualize: GndRole[];
@@ -1,12 +1,12 @@
1
1
  import { GndRole } from '@readium/guided-navigation';
2
- import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
2
+ import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
3
3
  import { ConfigurablePreferences } from './Configurable.js';
4
4
  export type VerbosityPreset = "none" | "few" | "some" | "most" | "custom";
5
5
  export type AutoPauseScope = "none" | "utterance" | "block";
6
6
  export type VoicePreference = string | Record<string, string>;
7
7
  export interface ISpeechPreferences {
8
8
  format?: ExtractionFormat | null;
9
- inlineContextualization?: GndRole[] | null;
9
+ interruptions?: Partial<Record<GndRole, Interruption>> | null;
10
10
  verbosity?: VerbosityPreset | null;
11
11
  skip?: GndRole[] | null;
12
12
  contextualize?: GndRole[] | null;
@@ -22,7 +22,7 @@ export interface ISpeechPreferences {
22
22
  }
23
23
  export declare class SpeechPreferences implements ISpeechPreferences, ConfigurablePreferences<SpeechPreferences> {
24
24
  format: ExtractionFormat | null | undefined;
25
- inlineContextualization: GndRole[] | null | undefined;
25
+ interruptions: Partial<Record<GndRole, Interruption>> | null | undefined;
26
26
  verbosity: VerbosityPreset | null | undefined;
27
27
  skip: GndRole[] | null | undefined;
28
28
  contextualize: GndRole[] | null | undefined;
@@ -1,8 +1,9 @@
1
+ import { GndRole } from '@readium/guided-navigation';
1
2
  import { IPreferencesEditor } from './PreferencesEditor.js';
2
3
  import { EnumPreference, Preference, RangePreference, StringArrayPreference } from './Preference.js';
3
4
  import { SpeechPreferences, VerbosityPreset, AutoPauseScope, VoicePreference } from './SpeechPreferences.js';
4
5
  import { SpeechSettings } from './SpeechSettings.js';
5
- import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
6
+ import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
6
7
  export declare class SpeechPreferencesEditor implements IPreferencesEditor {
7
8
  preferences: SpeechPreferences;
8
9
  private settings;
@@ -10,7 +11,7 @@ export declare class SpeechPreferencesEditor implements IPreferencesEditor {
10
11
  clear(): void;
11
12
  private updatePreference;
12
13
  get format(): EnumPreference<ExtractionFormat>;
13
- get inlineContextualization(): StringArrayPreference;
14
+ get interruptions(): Preference<Partial<Record<GndRole, Interruption>>>;
14
15
  get verbosity(): EnumPreference<VerbosityPreset>;
15
16
  get skip(): StringArrayPreference;
16
17
  get contextualize(): StringArrayPreference;
@@ -2,12 +2,12 @@ import { GndRole } from '@readium/guided-navigation';
2
2
  import { ConfigurableSettings } from './Configurable.js';
3
3
  import { SpeechDefaults } from './SpeechDefaults.js';
4
4
  import { AutoPauseScope, SpeechPreferences, VerbosityPreset, VoicePreference } from './SpeechPreferences.js';
5
- import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
5
+ import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
6
6
  import { ReadiumSpeechVoice } from '../voices/types.js';
7
7
  export declare class SpeechSettings implements ConfigurableSettings {
8
8
  [key: string]: unknown;
9
9
  readonly format: ExtractionFormat;
10
- readonly inlineContextualization: GndRole[];
10
+ readonly interruptions: Partial<Record<GndRole, Interruption>>;
11
11
  readonly verbosity: VerbosityPreset;
12
12
  readonly skip: GndRole[];
13
13
  readonly contextualize: GndRole[];
@@ -1,4 +1,4 @@
1
- import { ExtractionFormat, LanguageMode, Segmentation } from '../utterances/types.js';
1
+ import { ExtractionFormat, Interruption, LanguageMode, Segmentation } from '../utterances/types.js';
2
2
  import { AutoPauseScope, ISpeechPreferences, VerbosityPreset } from './SpeechPreferences.js';
3
3
  export interface RangeConfig {
4
4
  readonly range: readonly [number, number];
@@ -13,4 +13,5 @@ export declare const languageModes: readonly LanguageMode[];
13
13
  export declare const extractionFormats: readonly ExtractionFormat[];
14
14
  export declare const autoPauseScopes: readonly AutoPauseScope[];
15
15
  export declare const segmentationModes: readonly Segmentation[];
16
+ export declare const interruptionValues: readonly Interruption[];
16
17
  export declare const extractionPreferenceKeys: readonly (keyof ISpeechPreferences)[];
@@ -2,5 +2,6 @@ export declare function ensureBoolean(value: boolean | null | undefined): boolea
2
2
  export declare function ensureEnumValue<T extends string | number | symbol>(value: T | null | undefined, supportedValues: readonly T[]): T | null | undefined;
3
3
  export declare function ensureValueInRange(value: number | null | undefined, range: readonly [number, number]): number | null | undefined;
4
4
  export declare function ensureStringRecord(value: Record<string, string> | null | undefined): Record<string, string> | null | undefined;
5
+ export declare function ensureEnumRecord<T extends string>(value: Partial<Record<string, T>> | null | undefined, supportedValues: readonly T[]): Partial<Record<string, T>> | null | undefined;
5
6
  export declare function ensureStringOrStringRecord(value: string | Record<string, string> | null | undefined): string | Record<string, string> | null | undefined;
6
7
  export declare function ensureStringArray(value: string[] | null | undefined): string[] | null | undefined;
@@ -1,5 +1,6 @@
1
1
  export declare const OPENING_PUNCT_CLASS = "\\p{Ps}\\p{Pi}\u00BF\u00A1";
2
2
  export declare function startsWithOpeningPunct(s: string): boolean;
3
+ export declare function endsWithOpeningPunct(s: string): boolean;
3
4
  export declare function isSinglePunctuationChar(s: string): boolean;
4
5
  export declare function neutralizeAngleBrackets(text: string): string;
5
6
  export declare function decodeResidualHtmlEntities(text: string): string;
@@ -1,7 +1,7 @@
1
1
  export { extractUtterances } from './extractUtterances.js';
2
2
  export { resolveBoundaryLocate } from './boundaryLocate.js';
3
3
  export { resolveUtteranceLocate } from './utteranceLocate.js';
4
- export { blockLevelRoles, inlineContextualizationRoles, skippableRoles } from './roles.js';
4
+ export { blockLevelRoles, interruptionRoles, skippableRoles } from './roles.js';
5
5
  export { defaultContextualizations } from './contextualizations.js';
6
- export type { ContextualizationEntry, Contextualizations, ContextualizationOptions, ExtractUtterancesOptions, Segmentation, SegmentationOptions, } from './types.js';
6
+ export type { ContextualizationEntry, Contextualizations, ContextualizationOptions, ExtractUtterancesOptions, Interruption, Segmentation, SegmentationOptions, } from './types.js';
7
7
  export type { SentenceBoundary, SentenceSegmenter } from './sentenceSegmenter.js';
@@ -5,7 +5,8 @@ export declare const roleDropOverrides: Partial<Record<GndRole, {
5
5
  drops: GndRole[];
6
6
  unconditional?: boolean;
7
7
  }>>;
8
- export declare const inlineContextualizationRoles: GndRole[];
8
+ export declare const interruptionRoles: GndRole[];
9
+ export declare const textReferenceRoles: GndRole[];
9
10
  export declare const descriptionFoldingRoles: GndRole[];
10
11
  export declare const valueFoldingRoles: GndRole[];
11
12
  export declare const contentlessRoles: GndRole[];
@@ -72,11 +72,14 @@ export declare function splitOnLangTags(ssml: string, baseLanguage: string | und
72
72
  export interface SsmlSegment {
73
73
  ssml?: string;
74
74
  placeholderId?: string;
75
+ abbreviation?: "text" | "alias";
76
+ abbreviationText?: string;
77
+ parenthesizedSsml?: string;
75
78
  }
76
79
  export declare function hasPlaceholder(ssml: string): boolean;
77
80
  /**
78
81
  * Splits a raw (pre-`stripPlaceholders`) SSML string on its embedded
79
- * `<readium:TAG id="...">` placeholders, for `inlineContextualization`: each
82
+ * `<readium:TAG id="...">` placeholders and `<sub alias>` abbreviations, for `interruptions`: each
80
83
  * placeholder becomes its own segment (resolved via the `GuidedNavigationObject` sharing
81
84
  * its `id`) instead of being spoken after the whole enclosing text.
82
85
  */
@@ -4,6 +4,7 @@ import { SentenceSegmenter } from './sentenceSegmenter.js';
4
4
  export type ExtractionFormat = "plain" | "ssml";
5
5
  export type LanguageMode = "none" | "block-level" | "always";
6
6
  export type Segmentation = "structure" | "sentence";
7
+ export type Interruption = "never" | "inline" | "after";
7
8
  export type ContextualizationEntry = string | {
8
9
  [key: string]: ContextualizationEntry;
9
10
  };
@@ -32,7 +33,7 @@ export interface ExtractUtterancesOptions {
32
33
  language?: LanguageMode;
33
34
  contentLanguage?: string;
34
35
  languageOverrides?: Record<string, string>;
35
- inlineContextualization?: GndRole[];
36
+ interruptions?: Partial<Record<GndRole, Interruption>>;
36
37
  segmentation?: SegmentationOptions;
37
38
  substitutions?: SubstitutionTable;
38
39
  }
@@ -4,7 +4,7 @@ import { GndRole } from '@readium/guided-navigation';
4
4
  import { LocatorOptions } from '../decorator/createLocator.js';
5
5
  import { ReadiumSpeechUtterance } from '../utterance.js';
6
6
  import { SentenceSegmenter } from './sentenceSegmenter.js';
7
- import { ExtractionFormat, ExtractUtterancesOptions, LanguageMode, Segmentation, SubstitutionTable } from './types.js';
7
+ import { ExtractionFormat, ExtractUtterancesOptions, Interruption, LanguageMode, Segmentation, SubstitutionTable } from './types.js';
8
8
  export interface WalkContext {
9
9
  i18n: i18n;
10
10
  contextualizationLanguage: string;
@@ -13,7 +13,7 @@ export interface WalkContext {
13
13
  contextualizationShapes: Partial<Record<GndRole, "inline" | "block">>;
14
14
  contextualizationParams?: (role: GndRole, node: GuidedNavigationObject) => Record<string, string> | undefined;
15
15
  format: ExtractionFormat;
16
- inlineContextualization: ReadonlySet<GndRole>;
16
+ interruptions: Partial<Record<GndRole, Interruption>>;
17
17
  language?: LanguageMode;
18
18
  languageOverrides: Record<string, string>;
19
19
  contentLanguage?: string;
@@ -34,15 +34,17 @@ export interface WalkContext {
34
34
  leading?: LocatorOptions;
35
35
  trailing?: LocatorOptions;
36
36
  }>;
37
+ aliasLocates: WeakSet<LocatorOptions>;
37
38
  placeholderPieces: Map<ReadiumSpeechUtterance, {
38
39
  node: GuidedNavigationObject;
39
- placement?: "inline" | "after";
40
+ placement?: "inline" | "after" | "alias";
40
41
  }>;
41
42
  }
42
43
  export type SourceTrace = (GuidedNavigationObject | [GuidedNavigationObject, GuidedNavigationObject] | undefined)[];
43
44
  export declare const blockLevelRoleSet: ReadonlySet<GndRole>;
44
- export declare const inlineContextualizationRoleSet: ReadonlySet<GndRole>;
45
+ export declare const interruptionRoleSet: ReadonlySet<GndRole>;
45
46
  export declare const descriptionFoldingRoleSet: ReadonlySet<GndRole>;
46
47
  export declare const valueFoldingRoleSet: ReadonlySet<GndRole>;
47
48
  export declare const contentlessRoleSet: ReadonlySet<GndRole>;
49
+ export declare const textReferenceRoleSet: ReadonlySet<GndRole>;
48
50
  export declare function makeWalkContext(nodes: GuidedNavigationObject[], options: ExtractUtterancesOptions): Promise<WalkContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/speech",
3
- "version": "0.16.1",
3
+ "version": "0.17.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": [
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@readium/decorator": "^1.2.5",
65
- "@readium/guided-navigation": "^1.1.3",
65
+ "@readium/guided-navigation": "^1.2.2",
66
66
  "@readium/helpers": "^1.2.0",
67
67
  "@readium/shared": "^2.8.0",
68
68
  "i18next": "^26.4.0"