voice-router-dev 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SAS SPOKE / Meeting BaaS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,455 @@
1
+ # Voice Router SDK
2
+
3
+ > Universal speech-to-text router for 6+ transcription providers with a single, unified API.
4
+
5
+ [![npm version](https://badge.fury.io/js/voice-router-dev.svg)](https://www.npmjs.com/package/voice-router-dev)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen)](https://nodejs.org)
8
+
9
+ ## Why Voice Router?
10
+
11
+ Switch between speech-to-text providers **without changing your code**. One API for Gladia, AssemblyAI, Deepgram, Azure, OpenAI Whisper, and Speechmatics.
12
+
13
+ ```typescript
14
+ import { VoiceRouter } from 'voice-router-dev';
15
+
16
+ const router = new VoiceRouter({
17
+ providers: {
18
+ gladia: { apiKey: process.env.GLADIA_KEY },
19
+ deepgram: { apiKey: process.env.DEEPGRAM_KEY }
20
+ }
21
+ });
22
+
23
+ // Same code works with ANY provider
24
+ const result = await router.transcribe(audio, {
25
+ provider: 'gladia' // Switch to 'deepgram' anytime
26
+ });
27
+ ```
28
+
29
+ ## Features
30
+
31
+ - 🔄 **Provider-Agnostic** - Switch providers with one line
32
+ - 🎯 **Unified API** - Same interface for all providers
33
+ - 📦 **Webhook Normalization** - Auto-detect and parse webhooks
34
+ - 🔊 **Real-time Streaming** - WebSocket support (Gladia, AssemblyAI, Deepgram)
35
+ - 📊 **Advanced Features** - Diarization, sentiment, summarization
36
+ - 🔒 **Type-Safe** - Full TypeScript support
37
+ - ⚡ **Provider Fallback** - Automatic failover strategies
38
+ - 🎨 **Zero Config** - Works out of the box
39
+
40
+ ## Supported Providers
41
+
42
+ | Provider | Batch | Streaming | Webhooks | Special Features |
43
+ |----------|-------|-----------|----------|------------------|
44
+ | **Gladia** | ✅ | ✅ WebSocket | ✅ | Multi-language, code-switching |
45
+ | **AssemblyAI** | ✅ | ✅ Real-time | ✅ HMAC | Auto chapters, content moderation |
46
+ | **Deepgram** | ✅ Sync | ✅ WebSocket | ✅ | PII redaction, keyword boosting |
47
+ | **Azure STT** | ✅ Async | ❌ | ✅ HMAC | Custom models, language ID |
48
+ | **OpenAI Whisper** | ✅ Sync | ❌ | ❌ | gpt-4o, multi-model support |
49
+ | **Speechmatics** | ✅ Async | ❌ | ✅ Query params | High accuracy, enhanced mode |
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ npm install voice-router-dev
55
+ # or
56
+ pnpm add voice-router-dev
57
+ # or
58
+ yarn add voice-router-dev
59
+ ```
60
+
61
+ ## Quick Start
62
+
63
+ ### Basic Transcription
64
+
65
+ ```typescript
66
+ import { VoiceRouter, GladiaAdapter } from 'voice-router-dev';
67
+
68
+ // Initialize router
69
+ const router = new VoiceRouter({
70
+ providers: {
71
+ gladia: { apiKey: 'YOUR_GLADIA_KEY' }
72
+ },
73
+ defaultProvider: 'gladia'
74
+ });
75
+
76
+ // Register adapter
77
+ router.registerAdapter(new GladiaAdapter());
78
+
79
+ // Transcribe from URL
80
+ const result = await router.transcribe({
81
+ type: 'url',
82
+ url: 'https://example.com/audio.mp3'
83
+ }, {
84
+ language: 'en',
85
+ diarization: true
86
+ });
87
+
88
+ if (result.success) {
89
+ console.log('Transcript:', result.data.text);
90
+ console.log('Speakers:', result.data.speakers);
91
+ }
92
+ ```
93
+
94
+ ### Multi-Provider with Fallback
95
+
96
+ ```typescript
97
+ import {
98
+ VoiceRouter,
99
+ GladiaAdapter,
100
+ AssemblyAIAdapter,
101
+ DeepgramAdapter
102
+ } from 'voice-router-dev';
103
+
104
+ const router = new VoiceRouter({
105
+ providers: {
106
+ gladia: { apiKey: process.env.GLADIA_KEY },
107
+ assemblyai: { apiKey: process.env.ASSEMBLYAI_KEY },
108
+ deepgram: { apiKey: process.env.DEEPGRAM_KEY }
109
+ },
110
+ selectionStrategy: 'round-robin' // Auto load-balance
111
+ });
112
+
113
+ // Register all providers
114
+ router.registerAdapter(new GladiaAdapter());
115
+ router.registerAdapter(new AssemblyAIAdapter());
116
+ router.registerAdapter(new DeepgramAdapter());
117
+
118
+ // Automatically rotates between providers
119
+ await router.transcribe(audio1); // Uses Gladia
120
+ await router.transcribe(audio2); // Uses AssemblyAI
121
+ await router.transcribe(audio3); // Uses Deepgram
122
+ ```
123
+
124
+ ### Real-time Streaming
125
+
126
+ ```typescript
127
+ import { VoiceRouter, DeepgramAdapter } from 'voice-router-dev';
128
+
129
+ const router = new VoiceRouter({
130
+ providers: {
131
+ deepgram: { apiKey: process.env.DEEPGRAM_KEY }
132
+ }
133
+ });
134
+
135
+ router.registerAdapter(new DeepgramAdapter());
136
+
137
+ // Start streaming session
138
+ const session = await router.transcribeStream({
139
+ provider: 'deepgram',
140
+ encoding: 'linear16',
141
+ sampleRate: 16000,
142
+ language: 'en',
143
+ interimResults: true
144
+ }, {
145
+ onTranscript: (event) => {
146
+ if (event.isFinal) {
147
+ console.log('Final:', event.text);
148
+ } else {
149
+ console.log('Interim:', event.text);
150
+ }
151
+ },
152
+ onError: (error) => console.error(error)
153
+ });
154
+
155
+ // Send audio chunks
156
+ const audioStream = getMicrophoneStream();
157
+ for await (const chunk of audioStream) {
158
+ await session.sendAudio({ data: chunk });
159
+ }
160
+
161
+ await session.close();
162
+ ```
163
+
164
+ ### Webhook Normalization
165
+
166
+ ```typescript
167
+ import express from 'express';
168
+ import { WebhookRouter } from 'voice-router-dev';
169
+
170
+ const app = express();
171
+ const webhookRouter = new WebhookRouter();
172
+
173
+ // Single endpoint handles ALL providers
174
+ app.post('/webhooks/transcription', express.json(), (req, res) => {
175
+ // Auto-detect provider from payload
176
+ const result = webhookRouter.route(req.body, {
177
+ queryParams: req.query,
178
+ userAgent: req.headers['user-agent'],
179
+ verification: {
180
+ signature: req.headers['x-signature'],
181
+ secret: process.env.WEBHOOK_SECRET
182
+ }
183
+ });
184
+
185
+ if (!result.success) {
186
+ return res.status(400).json({ error: result.error });
187
+ }
188
+
189
+ // Unified format across all providers
190
+ console.log('Provider:', result.provider); // 'gladia' | 'assemblyai' | etc
191
+ console.log('Event:', result.event?.eventType); // 'transcription.completed'
192
+ console.log('ID:', result.event?.data?.id);
193
+ console.log('Text:', result.event?.data?.text);
194
+
195
+ res.json({ received: true });
196
+ });
197
+ ```
198
+
199
+ ## Advanced Usage
200
+
201
+ ### Provider-Specific Features
202
+
203
+ ```typescript
204
+ // Gladia - Multi-language detection
205
+ const result = await router.transcribe(audio, {
206
+ provider: 'gladia',
207
+ languageDetection: true,
208
+ summarization: true,
209
+ sentimentAnalysis: true
210
+ });
211
+
212
+ // AssemblyAI - Content moderation
213
+ const result = await router.transcribe(audio, {
214
+ provider: 'assemblyai',
215
+ entityDetection: true,
216
+ metadata: {
217
+ content_safety: true,
218
+ auto_chapters: true
219
+ }
220
+ });
221
+
222
+ // Deepgram - PII redaction
223
+ const result = await router.transcribe(audio, {
224
+ provider: 'deepgram',
225
+ piiRedaction: true,
226
+ customVocabulary: ['technical', 'terms']
227
+ });
228
+
229
+ // OpenAI Whisper - Model selection
230
+ const result = await router.transcribe(audio, {
231
+ provider: 'openai-whisper',
232
+ metadata: {
233
+ model: 'gpt-4o-transcribe', // or 'whisper-1'
234
+ temperature: 0.2
235
+ }
236
+ });
237
+
238
+ // Speechmatics - Enhanced accuracy
239
+ const result = await router.transcribe(audio, {
240
+ provider: 'speechmatics',
241
+ metadata: {
242
+ operating_point: 'enhanced', // Higher accuracy
243
+ enable_sentiment_analysis: true
244
+ }
245
+ });
246
+ ```
247
+
248
+ ### Error Handling
249
+
250
+ ```typescript
251
+ const result = await router.transcribe(audio, {
252
+ provider: 'gladia',
253
+ language: 'en'
254
+ });
255
+
256
+ if (!result.success) {
257
+ console.error('Provider:', result.provider);
258
+ console.error('Error:', result.error);
259
+ console.error('Details:', result.data);
260
+
261
+ // Implement fallback strategy
262
+ const fallbackResult = await router.transcribe(audio, {
263
+ provider: 'assemblyai' // Try different provider
264
+ });
265
+ }
266
+ ```
267
+
268
+ ### Custom Provider Selection
269
+
270
+ ```typescript
271
+ // Explicit provider selection
272
+ const router = new VoiceRouter({
273
+ providers: {
274
+ gladia: { apiKey: '...' },
275
+ deepgram: { apiKey: '...' }
276
+ },
277
+ selectionStrategy: 'explicit' // Must specify provider
278
+ });
279
+
280
+ // Round-robin load balancing
281
+ const router = new VoiceRouter({
282
+ providers: { /* ... */ },
283
+ selectionStrategy: 'round-robin'
284
+ });
285
+
286
+ // Default fallback
287
+ const router = new VoiceRouter({
288
+ providers: { /* ... */ },
289
+ defaultProvider: 'gladia',
290
+ selectionStrategy: 'default'
291
+ });
292
+ ```
293
+
294
+ ## API Reference
295
+
296
+ ### VoiceRouter
297
+
298
+ Main class for provider-agnostic transcription.
299
+
300
+ **Constructor:**
301
+ ```typescript
302
+ new VoiceRouter(config: VoiceRouterConfig)
303
+ ```
304
+
305
+ **Methods:**
306
+ - `registerAdapter(adapter: TranscriptionAdapter)` - Register a provider adapter
307
+ - `transcribe(audio: AudioInput, options?: TranscribeOptions)` - Transcribe audio
308
+ - `transcribeStream(options: StreamingOptions, callbacks: StreamingCallbacks)` - Stream audio
309
+ - `getTranscript(id: string, provider: string)` - Get transcript by ID
310
+ - `getProviderCapabilities(provider: string)` - Get provider features
311
+
312
+ ### WebhookRouter
313
+
314
+ Automatic webhook detection and normalization.
315
+
316
+ **Methods:**
317
+ - `route(payload: unknown, options?: WebhookRouterOptions)` - Parse webhook
318
+ - `detectProvider(payload: unknown)` - Detect provider from payload
319
+ - `validate(payload: unknown)` - Validate webhook structure
320
+
321
+ ### Adapters
322
+
323
+ Provider-specific implementations:
324
+ - `GladiaAdapter` - Gladia transcription
325
+ - `AssemblyAIAdapter` - AssemblyAI transcription
326
+ - `DeepgramAdapter` - Deepgram transcription
327
+ - `AzureSTTAdapter` - Azure Speech-to-Text
328
+ - `OpenAIWhisperAdapter` - OpenAI Whisper
329
+ - `SpeechmaticsAdapter` - Speechmatics transcription
330
+
331
+ ## TypeScript Support
332
+
333
+ Full type definitions included:
334
+
335
+ ```typescript
336
+ import type {
337
+ VoiceRouter,
338
+ VoiceRouterConfig,
339
+ AudioInput,
340
+ TranscribeOptions,
341
+ UnifiedTranscriptResponse,
342
+ StreamingSession,
343
+ StreamingOptions,
344
+ UnifiedWebhookEvent,
345
+ TranscriptionProvider
346
+ } from 'voice-router-dev';
347
+ ```
348
+
349
+ ## Requirements
350
+
351
+ - **Node.js**: 20.0.0 or higher
352
+ - **TypeScript**: 5.0+ (optional)
353
+ - **Package Managers**: npm, pnpm, or yarn
354
+
355
+ ## Documentation
356
+
357
+ - **Full API Docs**: [Generated TypeDoc](https://github.com/Meeting-Baas/sdk-generator/tree/main/docs/generated)
358
+ - **Provider Integration Guide**: See `PROVIDER_INTEGRATION_PLAN.md`
359
+ - **Examples**: See `examples/` directory
360
+
361
+ ## Provider Setup Guides
362
+
363
+ ### Gladia
364
+ ```typescript
365
+ import { VoiceRouter, GladiaAdapter } from 'voice-router-dev';
366
+
367
+ const router = new VoiceRouter({
368
+ providers: { gladia: { apiKey: 'YOUR_KEY' } }
369
+ });
370
+ router.registerAdapter(new GladiaAdapter());
371
+ ```
372
+
373
+ Get your API key: https://gladia.io
374
+
375
+ ### AssemblyAI
376
+ ```typescript
377
+ import { VoiceRouter, AssemblyAIAdapter } from 'voice-router-dev';
378
+
379
+ const router = new VoiceRouter({
380
+ providers: { assemblyai: { apiKey: 'YOUR_KEY' } }
381
+ });
382
+ router.registerAdapter(new AssemblyAIAdapter());
383
+ ```
384
+
385
+ Get your API key: https://assemblyai.com
386
+
387
+ ### Deepgram
388
+ ```typescript
389
+ import { VoiceRouter, DeepgramAdapter } from 'voice-router-dev';
390
+
391
+ const router = new VoiceRouter({
392
+ providers: { deepgram: { apiKey: 'YOUR_KEY' } }
393
+ });
394
+ router.registerAdapter(new DeepgramAdapter());
395
+ ```
396
+
397
+ Get your API key: https://deepgram.com
398
+
399
+ ### Azure Speech-to-Text
400
+ ```typescript
401
+ import { VoiceRouter, AzureSTTAdapter } from 'voice-router-dev';
402
+
403
+ const router = new VoiceRouter({
404
+ providers: {
405
+ 'azure-stt': {
406
+ apiKey: 'YOUR_KEY',
407
+ region: 'eastus' // Required
408
+ }
409
+ }
410
+ });
411
+ router.registerAdapter(new AzureSTTAdapter());
412
+ ```
413
+
414
+ Get your credentials: https://azure.microsoft.com/en-us/services/cognitive-services/speech-to-text/
415
+
416
+ ### OpenAI Whisper
417
+ ```typescript
418
+ import { VoiceRouter, OpenAIWhisperAdapter } from 'voice-router-dev';
419
+
420
+ const router = new VoiceRouter({
421
+ providers: { 'openai-whisper': { apiKey: 'YOUR_KEY' } }
422
+ });
423
+ router.registerAdapter(new OpenAIWhisperAdapter());
424
+ ```
425
+
426
+ Get your API key: https://platform.openai.com
427
+
428
+ ### Speechmatics
429
+ ```typescript
430
+ import { VoiceRouter, SpeechmaticsAdapter } from 'voice-router-dev';
431
+
432
+ const router = new VoiceRouter({
433
+ providers: { speechmatics: { apiKey: 'YOUR_KEY' } }
434
+ });
435
+ router.registerAdapter(new SpeechmaticsAdapter());
436
+ ```
437
+
438
+ Get your API key: https://speechmatics.com
439
+
440
+ ## Contributing
441
+
442
+ Contributions welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
443
+
444
+ ## License
445
+
446
+ MIT © [Lazare Zemliak](https://github.com/Meeting-Baas)
447
+
448
+ ## Support
449
+
450
+ - **Issues**: [GitHub Issues](https://github.com/Meeting-Baas/sdk-generator/issues)
451
+ - **Repository**: [GitHub](https://github.com/Meeting-Baas/sdk-generator)
452
+
453
+ ---
454
+
455
+ **Note**: This is a development version (`voice-router-dev`). The stable release will be published as `voice-router`.