@readium/speech 0.1.1 → 0.2.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 CHANGED
@@ -30,6 +30,10 @@ In the second phase, we focused on implementing a WebSpeech API-based solution w
30
30
 
31
31
  Key features include advanced voice selection, cross-browser playback control, flexible content loading, and comprehensive event handling for UI feedback. The architecture is designed to be extensible for different TTS backends while maintaining TypeScript-first development practices.
32
32
 
33
+ In the third phase, we added highlighting: content currently being spoken (e.g. the current word or sentence) can be highlighted as playback progresses. See the [Highlighting guide](docs/Highlighting.md).
34
+
35
+ We are now focused on the fourth phase: extracting [Guided Navigation objects](https://readium.org/guided-navigation) from a document (or a fragment of a document), and generating utterances from these objects.
36
+
33
37
  ## Demos
34
38
 
35
39
  Two live demos are available:
@@ -45,7 +49,7 @@ The first demo showcases the following features:
45
49
  - using embedded test utterances to demo voices
46
50
  - using the current Navigator for playback control
47
51
 
48
- The second demo focuses on in-context reading with seamless voice selection (grouped by region and sorted based on quality), and playback control, providing an optional read-along experience that integrates naturally with the content.
52
+ The second demo focuses on in-context reading with seamless voice selection (grouped by region and sorted based on quality), and playback control, providing an optional read-along experience that integrates naturally with the content. Both demos also showcase highlighting: as playback progresses, the current word/sentence is highlighted.
49
53
 
50
54
  ## Installation
51
55
 
@@ -64,7 +68,12 @@ yarn add @readium/speech
64
68
  ## Quick Start
65
69
 
66
70
  ```typescript
67
- import { WebSpeechVoiceManager, WebSpeechReadAloudNavigator } from "@readium/speech";
71
+ import {
72
+ WebSpeechVoiceManager,
73
+ WebSpeechReadAloudNavigator,
74
+ setupDecorations,
75
+ DecorationStyleType,
76
+ } from "@readium/speech";
68
77
 
69
78
  // Initialize voice manager
70
79
  const voiceManager = await WebSpeechVoiceManager.initialize({
@@ -78,24 +87,46 @@ const voice = await voiceManager.getDefaultVoice("en-US");
78
87
  const navigator = new WebSpeechReadAloudNavigator();
79
88
  await navigator.setVoice(voice);
80
89
 
90
+ const content = document.getElementById("content");
91
+ if (!content) throw new Error("Missing #content element");
92
+
93
+ // Set up highlighting for the current window
94
+ const decorations = setupDecorations();
95
+
81
96
  // Handle playback events
82
97
  navigator.on("play", () => console.log("Playback started"));
83
98
  navigator.on("pause", () => console.log("Playback paused"));
84
99
  navigator.on("end", () => console.log("Playback completed"));
85
100
 
101
+ // Highlight each word as it's spoken
102
+ navigator.on("boundary", (event) => {
103
+ const { charIndex, charLength } = event.detail;
104
+ const utterance = content.textContent ?? "";
105
+ const word = utterance.substring(charIndex, charIndex + charLength);
106
+
107
+ decorations.decorate([{
108
+ id: "tts-word",
109
+ style: { type: DecorationStyleType.Highlight, tint: "#ffeb3b" },
110
+ highlight: word,
111
+ }], "tts");
112
+ });
113
+
86
114
  // Load and play content
87
- const content = document.getElementById("content");
88
115
  navigator.loadContent(content);
89
116
  navigator.play();
90
117
  ```
91
118
 
119
+ See the [Highlighting guide](docs/Highlighting.md) for the other ways to build and apply decorations.
120
+
92
121
  ## Docs
93
122
 
94
123
  Documentation provides guides for:
95
124
 
96
125
  - [SpeechSynthesis in browsers and OSes](docs/WebSpeech.md)
97
126
  - [Voices and Filtering](docs/VoicesAndFiltering.md)
98
- - [API Reference](docs/API.md)
127
+ - [Voice Management](docs/VoiceManagement.md)
128
+ - [Playback API](docs/Playback.md)
129
+ - [Highlighting](docs/Highlighting.md)
99
130
 
100
131
  ## Development
101
132
 
@@ -0,0 +1,9 @@
1
+ import { Locator } from '@readium/shared';
2
+ export interface LocatorOptions {
3
+ highlight?: string;
4
+ before?: string;
5
+ after?: string;
6
+ selector?: string;
7
+ fragment?: string;
8
+ }
9
+ export declare function createLocator(options: LocatorOptions, wnd?: Window): Locator;
@@ -0,0 +1,2 @@
1
+ export * from './setupDecorations';
2
+ export * from './createLocator';
@@ -0,0 +1,15 @@
1
+ import { DirectCommsChannel, Decorator, DecorationController, DecorationControllerConfig, DecorationStyle } from '@readium/decorator';
2
+ import { LocatorOptions } from './createLocator';
3
+ export interface DecorationInput extends LocatorOptions {
4
+ id: string;
5
+ style: DecorationStyle;
6
+ }
7
+ export declare class ReadiumSpeechDecorationController extends DecorationController {
8
+ private readonly channel;
9
+ private readonly wnd;
10
+ private readonly decorator;
11
+ constructor(channel: DirectCommsChannel, wnd: Window, decorator: Decorator, config?: DecorationControllerConfig);
12
+ decorate(decorations: DecorationInput[], group: string): void;
13
+ destroy(): void;
14
+ }
15
+ export declare function setupDecorations(wnd?: Window, config?: DecorationControllerConfig): ReadiumSpeechDecorationController;