@pie-players/pie-tool-tts-inline 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 ADDED
@@ -0,0 +1,158 @@
1
+ # @pie-players/pie-tool-tts-inline
2
+
3
+ Inline TTS (Text-to-Speech) tool component for PIE Players Assessment Toolkit.
4
+
5
+ ## Overview
6
+
7
+ `pie-tool-tts-inline` is a web component that renders a Material Design speaker icon button for triggering TTS playback. Unlike floating modal tools, this component renders inline at its natural position in the DOM (typically in headers).
8
+
9
+ ## Features
10
+
11
+ - Material Design speaker icon (🔊)
12
+ - Registers with `ToolCoordinator` for lifecycle management
13
+ - Integrates with `TTSService` for QTI 3.0 catalog-based TTS
14
+ - Size variants: `sm`, `md`, `lg`
15
+ - Visual feedback during speaking (pulse animation)
16
+ - Full accessibility support (ARIA labels, keyboard navigation)
17
+ - Coordinator-controlled visibility via CSS `display` property
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ bun add @pie-players/pie-tool-tts-inline
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```javascript
28
+ import '@pie-players/pie-tool-tts-inline';
29
+ import { TTSService, BrowserTTSProvider, ToolCoordinator } from '@pie-players/pie-assessment-toolkit';
30
+
31
+ // Initialize services
32
+ const ttsService = new TTSService();
33
+ await ttsService.initialize(new BrowserTTSProvider());
34
+ const toolCoordinator = new ToolCoordinator();
35
+
36
+ // Create element
37
+ const ttsButton = document.createElement('pie-tool-tts-inline');
38
+ ttsButton.setAttribute('tool-id', 'tts-passage-1');
39
+ ttsButton.setAttribute('catalog-id', 'passage-1');
40
+ ttsButton.setAttribute('size', 'md');
41
+
42
+ // Bind services as JavaScript properties (not HTML attributes)
43
+ ttsButton.ttsService = ttsService;
44
+ ttsButton.coordinator = toolCoordinator;
45
+
46
+ // Coordinator controls visibility
47
+ toolCoordinator.showTool('tts-passage-1');
48
+ ```
49
+
50
+ ### With Svelte
51
+
52
+ ```svelte
53
+ <script>
54
+ import '@pie-players/pie-tool-tts-inline';
55
+ import { ZIndexLayer } from '@pie-players/pie-assessment-toolkit';
56
+
57
+ let ttsToolElement;
58
+
59
+ $effect(() => {
60
+ if (ttsToolElement && toolCoordinator) {
61
+ ttsToolElement.ttsService = ttsService;
62
+ ttsToolElement.coordinator = toolCoordinator;
63
+
64
+ if (ttsService) {
65
+ toolCoordinator.showTool('tts-passage-1');
66
+ }
67
+ }
68
+ });
69
+ </script>
70
+
71
+ <div class="header">
72
+ <h3>Passage Title</h3>
73
+ <pie-tool-tts-inline
74
+ bind:this={ttsToolElement}
75
+ tool-id="tts-passage-1"
76
+ catalog-id="passage-1"
77
+ size="md"
78
+ ></pie-tool-tts-inline>
79
+ </div>
80
+ ```
81
+
82
+ ## Props
83
+
84
+ ### HTML Attributes
85
+
86
+ - `tool-id` - Unique identifier for tool registration (default: `'tts-inline'`)
87
+ - `catalog-id` - QTI 3.0 accessibility catalog ID for SSML lookup (default: `''`)
88
+ - `language` - Language code for TTS (default: `'en-US'`)
89
+ - `size` - Icon size: `'sm'` (1.5rem), `'md'` (2rem), or `'lg'` (2.5rem) (default: `'md'`)
90
+
91
+ ### JavaScript Properties
92
+
93
+ - `ttsService` - ITTSService instance (required)
94
+ - `coordinator` - IToolCoordinator instance (optional, for visibility management)
95
+
96
+ ## Behavior
97
+
98
+ 1. **Tool Registration**: Registers with ToolCoordinator on mount using the provided `tool-id`
99
+ 2. **Text Extraction**: Finds nearest `.passage-content` or `.item-content` container
100
+ 3. **TTS Trigger**: Calls `ttsService.speak(text, { catalogId, language })`
101
+ 4. **Catalog Resolution**: TTSService checks for SSML in accessibility catalogs (priority order):
102
+ - **Extracted catalogs** (from embedded SSML) - auto-generated by section player
103
+ - **Item-level catalogs** (manually authored)
104
+ - **Assessment-level catalogs** (manually authored)
105
+ - **Plain text fallback** (browser TTS)
106
+ 5. **Visual Feedback**: Pulse animation while speaking, disabled state
107
+ 6. **Cleanup**: Unregisters from coordinator on unmount
108
+
109
+ ## SSML Extraction Integration
110
+
111
+ When used with the section player, this tool automatically benefits from SSML extraction:
112
+
113
+ **Author embeds SSML in content:**
114
+ ```html
115
+ <div>
116
+ <speak>Solve <prosody rate="slow">x squared plus two</prosody>.</speak>
117
+ <p>Solve x² + 2 = 0</p>
118
+ </div>
119
+ ```
120
+
121
+ **Section player extracts SSML at runtime:**
122
+ - Generates catalog with ID like `auto-prompt-q1-0`
123
+ - Adds `data-catalog-id="auto-prompt-q1-0"` to visual content
124
+ - Registers catalog with AccessibilityCatalogResolver
125
+
126
+ **Tool uses extracted catalog:**
127
+ - User clicks TTS button in header
128
+ - Tool calls `ttsService.speak(text, { catalogId: 'auto-prompt-q1-0' })`
129
+ - TTSService finds SSML in extracted catalogs
130
+ - Speaks with proper math pronunciation and pacing
131
+
132
+ **Result:** Authors get high-quality TTS without maintaining separate catalog files.
133
+
134
+ ## Styling
135
+
136
+ The component uses inline styles and doesn't require external CSS. The button is transparent by default with hover effects:
137
+
138
+ - **Normal**: Gray icon, transparent background
139
+ - **Hover**: Purple icon, light gray background
140
+ - **Speaking**: Purple icon, blue tinted background with pulse animation
141
+ - **Disabled**: Reduced opacity, no pointer
142
+
143
+ ## Architecture
144
+
145
+ This tool follows the PIE Assessment Toolkit tool pattern:
146
+
147
+ - Always rendered in DOM at natural position
148
+ - ToolCoordinator controls visibility via `showTool()`/`hideTool()` (CSS `display` property)
149
+ - Registers with `ZIndexLayer.TOOL` for proper layering
150
+ - Services passed as JavaScript properties (objects can't be HTML attributes)
151
+
152
+ ## Example
153
+
154
+ See the complete working demo at `packages/section-player/demos/tts-integration-demo.html`.
155
+
156
+ ## License
157
+
158
+ MIT
@@ -0,0 +1,5 @@
1
+ import { SvelteComponent } from 'svelte';
2
+
3
+ export default SvelteComponent;
4
+
5
+ export { }