@pie-players/pie-tool-text-to-speech 0.1.1
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 +209 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/tool-text-to-speech.js +2991 -0
- package/dist/tool-text-to-speech.js.map +1 -0
- package/index.ts +8 -0
- package/package.json +62 -0
- package/tool-text-to-speech.svelte +660 -0
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Text-to-Speech Tool (`<pie-tool-text-to-speech>`)
|
|
2
|
+
|
|
3
|
+
A draggable, floating tool that reads selected text aloud with word-level highlighting for accessibility.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Text Selection**: Automatically detects selected text on the page
|
|
8
|
+
- ✅ **Word Highlighting**: Highlights each word as it's spoken (yellow background + underline)
|
|
9
|
+
- ✅ **Speed Control**: Adjustable speech rate from 0.5x (Slow) to 2.0x (Very Fast)
|
|
10
|
+
- ✅ **Playback Controls**: Play, Pause/Resume, and Stop buttons
|
|
11
|
+
- ✅ **Visual Feedback**: Status indicator shows speaking/paused state
|
|
12
|
+
- ✅ **Draggable**: Move the tool anywhere on screen
|
|
13
|
+
- ✅ **Accessibility**: Full keyboard support and screen reader compatible
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### As Web Component
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<pie-tool-text-to-speech
|
|
21
|
+
visible="true"
|
|
22
|
+
tool-id="textToSpeech"
|
|
23
|
+
></pie-tool-text-to-speech>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### As Svelte Component
|
|
27
|
+
|
|
28
|
+
```svelte
|
|
29
|
+
<script>
|
|
30
|
+
import { ToolTextToSpeech } from '$lib/tags/tool-text-to-speech';
|
|
31
|
+
import { toolCoordinator } from '$lib/assessment-toolkit/tools';
|
|
32
|
+
|
|
33
|
+
let visible = false;
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<ToolTextToSpeech
|
|
37
|
+
{visible}
|
|
38
|
+
toolId="textToSpeech"
|
|
39
|
+
coordinator={toolCoordinator}
|
|
40
|
+
/>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Via Tool Toolbar
|
|
44
|
+
|
|
45
|
+
The TTS tool is automatically included when using `<pie-tool-toolbar>`:
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<pie-tool-toolbar tools="protractor,ruler,textToSpeech"></pie-tool-toolbar>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## How It Works
|
|
52
|
+
|
|
53
|
+
1. **Select Text**: User selects any text on the page
|
|
54
|
+
2. **Click Play**: Tool reads the selected text aloud
|
|
55
|
+
3. **Word Highlighting**: Each word is highlighted with yellow background and underline as it's spoken
|
|
56
|
+
4. **Adjust Speed**: Use the slider to change speech rate (0.5x - 2.0x)
|
|
57
|
+
5. **Pause/Resume**: Pause and resume playback at any time
|
|
58
|
+
6. **Stop**: Stop playback and clear highlights
|
|
59
|
+
|
|
60
|
+
## Props
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|------|------|---------|-------------|
|
|
64
|
+
| `visible` | `Boolean` | `false` | Show/hide the tool |
|
|
65
|
+
| `toolId` | `String` | `'textToSpeech'` | Unique identifier for the tool |
|
|
66
|
+
| `coordinator` | `ToolCoordinator` | Required | Tool coordination service |
|
|
67
|
+
|
|
68
|
+
## TTS Service Integration
|
|
69
|
+
|
|
70
|
+
The tool uses the shared `TTSService` from `$lib/services/tts`:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { ttsService } from '$lib/services/tts';
|
|
74
|
+
|
|
75
|
+
// Initialize
|
|
76
|
+
await ttsService.initialize();
|
|
77
|
+
|
|
78
|
+
// Set root element for highlighting
|
|
79
|
+
ttsService.setRootElement(containerElement);
|
|
80
|
+
|
|
81
|
+
// Speak with options
|
|
82
|
+
await ttsService.speak(text, {
|
|
83
|
+
rate: 1.0,
|
|
84
|
+
highlightWords: true
|
|
85
|
+
}, {
|
|
86
|
+
onEnd: () => { /* cleanup */ },
|
|
87
|
+
onError: (error) => { /* handle error */ }
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Browser Support
|
|
92
|
+
|
|
93
|
+
### Text-to-Speech (Web Speech API)
|
|
94
|
+
- ✅ Chrome 33+
|
|
95
|
+
- ✅ Safari 7+
|
|
96
|
+
- ✅ Edge 14+
|
|
97
|
+
- ✅ Firefox 49+
|
|
98
|
+
- ✅ Mobile: iOS 7+, Android 4.4+
|
|
99
|
+
- **Coverage**: 97%+ of users
|
|
100
|
+
|
|
101
|
+
### Word Highlighting (CSS Custom Highlight API)
|
|
102
|
+
- ✅ Chrome 105+
|
|
103
|
+
- ✅ Safari 17.2+
|
|
104
|
+
- ✅ Edge 105+
|
|
105
|
+
- ✅ Firefox 128+
|
|
106
|
+
- **Coverage**: 85-90% of users
|
|
107
|
+
|
|
108
|
+
The tool gracefully degrades: TTS works everywhere, highlighting only on modern browsers.
|
|
109
|
+
|
|
110
|
+
## Accessibility
|
|
111
|
+
|
|
112
|
+
- **Screen Reader Compatible**: Uses Web Speech API which doesn't interfere with screen readers
|
|
113
|
+
- **Keyboard Navigation**: Tool can be moved with keyboard (when focused)
|
|
114
|
+
- **High Contrast**: Works with high contrast mode
|
|
115
|
+
- **Reduced Motion**: Respects `prefers-reduced-motion` setting
|
|
116
|
+
- **ARIA Labels**: All buttons have proper aria-label attributes
|
|
117
|
+
|
|
118
|
+
## Speed Presets
|
|
119
|
+
|
|
120
|
+
| Value | Label | Description |
|
|
121
|
+
|-------|-------|-------------|
|
|
122
|
+
| 0.5x | Slow | Half speed |
|
|
123
|
+
| 0.75x | Slower | 3/4 speed |
|
|
124
|
+
| 1.0x | Normal | Default speed |
|
|
125
|
+
| 1.25x | Faster | 1.25x speed |
|
|
126
|
+
| 1.5x | Fast | 1.5x speed |
|
|
127
|
+
| 2.0x | Very Fast | Double speed |
|
|
128
|
+
|
|
129
|
+
## Visual Design
|
|
130
|
+
|
|
131
|
+
The tool features:
|
|
132
|
+
- **Purple gradient header** (matches other PIE tools)
|
|
133
|
+
- **Clean, modern UI** with rounded corners
|
|
134
|
+
- **Responsive buttons** with hover/disabled states
|
|
135
|
+
- **Status indicators** with animated pulse
|
|
136
|
+
- **Color-coded feedback**: Green (speaking), Yellow (paused), Red (error)
|
|
137
|
+
|
|
138
|
+
## Error Handling
|
|
139
|
+
|
|
140
|
+
The tool handles these error scenarios:
|
|
141
|
+
|
|
142
|
+
1. **TTS Not Supported**: Shows error message if browser doesn't support Web Speech API
|
|
143
|
+
2. **No Text Selected**: Disables play button until text is selected
|
|
144
|
+
3. **Speech Errors**: Shows error message and stops playback
|
|
145
|
+
4. **Network Issues**: Gracefully handles offline scenarios (Web Speech API works offline)
|
|
146
|
+
|
|
147
|
+
## Performance
|
|
148
|
+
|
|
149
|
+
- **Lightweight**: ~15KB minified
|
|
150
|
+
- **No Dependencies**: Uses browser-native APIs
|
|
151
|
+
- **Efficient**: Only highlights visible text, no DOM mutation
|
|
152
|
+
- **Memory Safe**: Cleans up event listeners on unmount
|
|
153
|
+
|
|
154
|
+
## Example: Complete Integration
|
|
155
|
+
|
|
156
|
+
```svelte
|
|
157
|
+
<script>
|
|
158
|
+
import { ToolTextToSpeech } from '$lib/tags/tool-text-to-speech';
|
|
159
|
+
import { toolCoordinator } from '$lib/assessment-toolkit/tools';
|
|
160
|
+
import { onMount } from 'svelte';
|
|
161
|
+
|
|
162
|
+
let showTTS = false;
|
|
163
|
+
|
|
164
|
+
onMount(() => {
|
|
165
|
+
// Register tool
|
|
166
|
+
toolCoordinator.registerTool('textToSpeech', 'Text-to-Speech');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Subscribe to tool visibility
|
|
170
|
+
$: {
|
|
171
|
+
const state = toolCoordinator.getToolState('textToSpeech');
|
|
172
|
+
showTTS = state?.isVisible ?? false;
|
|
173
|
+
}
|
|
174
|
+
</script>
|
|
175
|
+
|
|
176
|
+
<!-- Assessment content -->
|
|
177
|
+
<div class="question-prompt">
|
|
178
|
+
<p>Read this question carefully and select the best answer.</p>
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
<!-- TTS button -->
|
|
182
|
+
<button on:click={() => toolCoordinator.toggleTool('textToSpeech')}>
|
|
183
|
+
🔊 Text-to-Speech
|
|
184
|
+
</button>
|
|
185
|
+
|
|
186
|
+
<!-- TTS tool -->
|
|
187
|
+
<ToolTextToSpeech
|
|
188
|
+
visible={showTTS}
|
|
189
|
+
toolId="textToSpeech"
|
|
190
|
+
coordinator={toolCoordinator}
|
|
191
|
+
/>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Future Enhancements
|
|
195
|
+
|
|
196
|
+
- [ ] Voice selection (male/female, language)
|
|
197
|
+
- [ ] Auto-detect language
|
|
198
|
+
- [ ] Save speed preference
|
|
199
|
+
- [ ] Read entire page/section
|
|
200
|
+
- [ ] Keyboard shortcuts
|
|
201
|
+
- [ ] Multiple language support
|
|
202
|
+
- [ ] AWS Polly integration (premium voices)
|
|
203
|
+
|
|
204
|
+
## Related
|
|
205
|
+
|
|
206
|
+
- [TTSService](../../services/tts/README.md) - Core TTS service
|
|
207
|
+
- [Highlight Infrastructure](../../services/highlight/README.md) - Word highlighting system
|
|
208
|
+
- [Tool Toolbar](../tool-toolbar/README.md) - Tool management
|
|
209
|
+
- [Tool Coordinator](../../tools/README.md) - Tool lifecycle
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|