@360labs/live-transcribe 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/CHANGELOG.md +14 -2
- package/README.md +82 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-01-18
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **Language Switching**: Change language mid-transcription with `setLanguage()`
|
|
14
|
+
- New `getLanguage()` method to get current language
|
|
15
|
+
- New `languageChange` event emitted when language changes
|
|
16
|
+
- Automatic stop/restart handling when switching languages during active transcription
|
|
17
|
+
- Session-level language switching support
|
|
18
|
+
- Documentation for language switching feature
|
|
19
|
+
- Tests for language switching functionality (6 new tests)
|
|
20
|
+
|
|
10
21
|
## [0.1.0] - 2026-01-17
|
|
11
22
|
|
|
12
23
|
### Added
|
|
@@ -37,5 +48,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
37
48
|
### Security
|
|
38
49
|
- N/A
|
|
39
50
|
|
|
40
|
-
[Unreleased]: https://github.com/
|
|
41
|
-
[0.
|
|
51
|
+
[Unreleased]: https://github.com/360labs/live-transcribe/compare/v0.2.0...HEAD
|
|
52
|
+
[0.2.0]: https://github.com/360labs/live-transcribe/compare/v0.1.0...v0.2.0
|
|
53
|
+
[0.1.0]: https://github.com/360labs/live-transcribe/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -407,6 +407,11 @@ transcriber.on('stateChange', (state) => {
|
|
|
407
407
|
console.log('State changed to:', state);
|
|
408
408
|
});
|
|
409
409
|
|
|
410
|
+
// Language changes
|
|
411
|
+
transcriber.on('languageChange', (change) => {
|
|
412
|
+
console.log(`Language: ${change.from} -> ${change.to}`);
|
|
413
|
+
});
|
|
414
|
+
|
|
410
415
|
// Error handling
|
|
411
416
|
transcriber.on('error', (error) => {
|
|
412
417
|
console.error('Error code:', error.code);
|
|
@@ -553,6 +558,81 @@ const session = createSession({
|
|
|
553
558
|
});
|
|
554
559
|
```
|
|
555
560
|
|
|
561
|
+
### Changing Language Mid-Transcript
|
|
562
|
+
|
|
563
|
+
You can change the language during an active transcription session. The library automatically handles stopping and restarting the transcription with the new language:
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
const session = createSession({
|
|
567
|
+
provider: TranscriptionProvider.WebSpeechAPI,
|
|
568
|
+
language: 'en-US',
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
await session.start();
|
|
572
|
+
|
|
573
|
+
// User switches to Spanish mid-conversation
|
|
574
|
+
await session.setLanguage('es-ES');
|
|
575
|
+
// Transcription continues seamlessly in Spanish
|
|
576
|
+
|
|
577
|
+
// Switch to French
|
|
578
|
+
await session.setLanguage('fr-FR');
|
|
579
|
+
|
|
580
|
+
// Get current language
|
|
581
|
+
console.log(session.getLanguage()); // 'fr-FR'
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
**With Transcriber Directly:**
|
|
585
|
+
|
|
586
|
+
```typescript
|
|
587
|
+
const transcriber = createTranscriber({
|
|
588
|
+
provider: TranscriptionProvider.WebSpeechAPI,
|
|
589
|
+
language: 'en-US',
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
// Listen for language changes
|
|
593
|
+
transcriber.on('languageChange', (change) => {
|
|
594
|
+
console.log(`Language changed from ${change.from} to ${change.to}`);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
await transcriber.initialize();
|
|
598
|
+
await transcriber.start();
|
|
599
|
+
|
|
600
|
+
// Change language while recording
|
|
601
|
+
await transcriber.setLanguage('de-DE');
|
|
602
|
+
|
|
603
|
+
// Get current language
|
|
604
|
+
console.log(transcriber.getLanguage()); // 'de-DE'
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
**React Example with Language Selector:**
|
|
608
|
+
|
|
609
|
+
```tsx
|
|
610
|
+
function TranscriptionWithLanguageSwitch() {
|
|
611
|
+
const [language, setLanguage] = useState('en-US');
|
|
612
|
+
const sessionRef = useRef<TranscriptionSession | null>(null);
|
|
613
|
+
|
|
614
|
+
const changeLanguage = async (newLang: string) => {
|
|
615
|
+
setLanguage(newLang);
|
|
616
|
+
if (sessionRef.current) {
|
|
617
|
+
await sessionRef.current.setLanguage(newLang);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
return (
|
|
622
|
+
<div>
|
|
623
|
+
<select value={language} onChange={(e) => changeLanguage(e.target.value)}>
|
|
624
|
+
<option value="en-US">English</option>
|
|
625
|
+
<option value="es-ES">Spanish</option>
|
|
626
|
+
<option value="fr-FR">French</option>
|
|
627
|
+
<option value="de-DE">German</option>
|
|
628
|
+
<option value="ja-JP">Japanese</option>
|
|
629
|
+
</select>
|
|
630
|
+
{/* Transcription continues without interruption */}
|
|
631
|
+
</div>
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
|
|
556
636
|
---
|
|
557
637
|
|
|
558
638
|
## API Reference
|
|
@@ -598,6 +678,8 @@ function createSession(config: TranscriptionConfig): TranscriptionSession;
|
|
|
598
678
|
| `getStatistics()` | SessionStatistics | Get session stats |
|
|
599
679
|
| `addTranscript(result)` | void | Add a transcript |
|
|
600
680
|
| `export(format)` | ExportResult | Export transcripts |
|
|
681
|
+
| `setLanguage(language)` | Promise<void> | Change language mid-session |
|
|
682
|
+
| `getLanguage()` | string | Get current language |
|
|
601
683
|
|
|
602
684
|
### SessionStatistics
|
|
603
685
|
|
package/dist/index.d.mts
CHANGED
|
@@ -392,6 +392,11 @@ interface TranscriptionEvents {
|
|
|
392
392
|
silence: () => void;
|
|
393
393
|
/** Emitted when speech is detected */
|
|
394
394
|
speech: () => void;
|
|
395
|
+
/** Emitted when language is changed */
|
|
396
|
+
languageChange: (change: {
|
|
397
|
+
from: string | undefined;
|
|
398
|
+
to: string;
|
|
399
|
+
}) => void;
|
|
395
400
|
/** Index signature for extensibility */
|
|
396
401
|
[key: string]: (...args: any[]) => void;
|
|
397
402
|
}
|
|
@@ -442,6 +447,18 @@ interface ITranscriptionProvider {
|
|
|
442
447
|
* Clean up resources and connections
|
|
443
448
|
*/
|
|
444
449
|
cleanup(): Promise<void>;
|
|
450
|
+
/**
|
|
451
|
+
* Change the transcription language
|
|
452
|
+
* Automatically handles stop/restart if currently active
|
|
453
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
454
|
+
* @returns Promise that resolves when language change is complete
|
|
455
|
+
*/
|
|
456
|
+
setLanguage(language: string): Promise<void>;
|
|
457
|
+
/**
|
|
458
|
+
* Get the current language
|
|
459
|
+
* @returns Current language code
|
|
460
|
+
*/
|
|
461
|
+
getLanguage(): string;
|
|
445
462
|
}
|
|
446
463
|
/**
|
|
447
464
|
* Describes the capabilities of a transcription provider
|
|
@@ -550,6 +567,27 @@ declare abstract class BaseTranscriber extends EventEmitter<TranscriptionEvents>
|
|
|
550
567
|
* Get session metadata
|
|
551
568
|
*/
|
|
552
569
|
getMetadata(): SessionMetadata;
|
|
570
|
+
/**
|
|
571
|
+
* Get the current language
|
|
572
|
+
* @returns Current language code
|
|
573
|
+
*/
|
|
574
|
+
getLanguage(): string;
|
|
575
|
+
/**
|
|
576
|
+
* Change the transcription language
|
|
577
|
+
* Automatically handles stop/restart if currently active
|
|
578
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
579
|
+
*/
|
|
580
|
+
setLanguage(language: string): Promise<void>;
|
|
581
|
+
/**
|
|
582
|
+
* Restart transcription with new language (called internally)
|
|
583
|
+
* Override in providers if needed
|
|
584
|
+
*/
|
|
585
|
+
protected restartWithNewLanguage(): Promise<void>;
|
|
586
|
+
/**
|
|
587
|
+
* Apply language change without restarting
|
|
588
|
+
* Override in providers to update language settings
|
|
589
|
+
*/
|
|
590
|
+
protected applyLanguageChange(): Promise<void>;
|
|
553
591
|
/**
|
|
554
592
|
* Get recorded audio data
|
|
555
593
|
* @returns Combined audio data or null if not recording
|
|
@@ -693,6 +731,17 @@ declare class TranscriptionSession {
|
|
|
693
731
|
* Clear all transcripts
|
|
694
732
|
*/
|
|
695
733
|
clear(): void;
|
|
734
|
+
/**
|
|
735
|
+
* Change the transcription language
|
|
736
|
+
* Automatically handles stop/restart if session is active
|
|
737
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
738
|
+
*/
|
|
739
|
+
setLanguage(language: string): Promise<void>;
|
|
740
|
+
/**
|
|
741
|
+
* Get the current transcription language
|
|
742
|
+
* @returns Current language code
|
|
743
|
+
*/
|
|
744
|
+
getLanguage(): string;
|
|
696
745
|
/**
|
|
697
746
|
* Get the total word count from final transcripts
|
|
698
747
|
*/
|
|
@@ -940,6 +989,15 @@ declare class WebSpeechProvider extends BaseTranscriber {
|
|
|
940
989
|
* Get provider capabilities
|
|
941
990
|
*/
|
|
942
991
|
getCapabilities(): ProviderCapabilities;
|
|
992
|
+
/**
|
|
993
|
+
* Restart with new language - optimized for Web Speech API
|
|
994
|
+
* Performs a quick stop/start cycle to apply new language
|
|
995
|
+
*/
|
|
996
|
+
protected restartWithNewLanguage(): Promise<void>;
|
|
997
|
+
/**
|
|
998
|
+
* Apply language change when paused
|
|
999
|
+
*/
|
|
1000
|
+
protected applyLanguageChange(): Promise<void>;
|
|
943
1001
|
/**
|
|
944
1002
|
* Set up event handlers for speech recognition
|
|
945
1003
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -392,6 +392,11 @@ interface TranscriptionEvents {
|
|
|
392
392
|
silence: () => void;
|
|
393
393
|
/** Emitted when speech is detected */
|
|
394
394
|
speech: () => void;
|
|
395
|
+
/** Emitted when language is changed */
|
|
396
|
+
languageChange: (change: {
|
|
397
|
+
from: string | undefined;
|
|
398
|
+
to: string;
|
|
399
|
+
}) => void;
|
|
395
400
|
/** Index signature for extensibility */
|
|
396
401
|
[key: string]: (...args: any[]) => void;
|
|
397
402
|
}
|
|
@@ -442,6 +447,18 @@ interface ITranscriptionProvider {
|
|
|
442
447
|
* Clean up resources and connections
|
|
443
448
|
*/
|
|
444
449
|
cleanup(): Promise<void>;
|
|
450
|
+
/**
|
|
451
|
+
* Change the transcription language
|
|
452
|
+
* Automatically handles stop/restart if currently active
|
|
453
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
454
|
+
* @returns Promise that resolves when language change is complete
|
|
455
|
+
*/
|
|
456
|
+
setLanguage(language: string): Promise<void>;
|
|
457
|
+
/**
|
|
458
|
+
* Get the current language
|
|
459
|
+
* @returns Current language code
|
|
460
|
+
*/
|
|
461
|
+
getLanguage(): string;
|
|
445
462
|
}
|
|
446
463
|
/**
|
|
447
464
|
* Describes the capabilities of a transcription provider
|
|
@@ -550,6 +567,27 @@ declare abstract class BaseTranscriber extends EventEmitter<TranscriptionEvents>
|
|
|
550
567
|
* Get session metadata
|
|
551
568
|
*/
|
|
552
569
|
getMetadata(): SessionMetadata;
|
|
570
|
+
/**
|
|
571
|
+
* Get the current language
|
|
572
|
+
* @returns Current language code
|
|
573
|
+
*/
|
|
574
|
+
getLanguage(): string;
|
|
575
|
+
/**
|
|
576
|
+
* Change the transcription language
|
|
577
|
+
* Automatically handles stop/restart if currently active
|
|
578
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
579
|
+
*/
|
|
580
|
+
setLanguage(language: string): Promise<void>;
|
|
581
|
+
/**
|
|
582
|
+
* Restart transcription with new language (called internally)
|
|
583
|
+
* Override in providers if needed
|
|
584
|
+
*/
|
|
585
|
+
protected restartWithNewLanguage(): Promise<void>;
|
|
586
|
+
/**
|
|
587
|
+
* Apply language change without restarting
|
|
588
|
+
* Override in providers to update language settings
|
|
589
|
+
*/
|
|
590
|
+
protected applyLanguageChange(): Promise<void>;
|
|
553
591
|
/**
|
|
554
592
|
* Get recorded audio data
|
|
555
593
|
* @returns Combined audio data or null if not recording
|
|
@@ -693,6 +731,17 @@ declare class TranscriptionSession {
|
|
|
693
731
|
* Clear all transcripts
|
|
694
732
|
*/
|
|
695
733
|
clear(): void;
|
|
734
|
+
/**
|
|
735
|
+
* Change the transcription language
|
|
736
|
+
* Automatically handles stop/restart if session is active
|
|
737
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
738
|
+
*/
|
|
739
|
+
setLanguage(language: string): Promise<void>;
|
|
740
|
+
/**
|
|
741
|
+
* Get the current transcription language
|
|
742
|
+
* @returns Current language code
|
|
743
|
+
*/
|
|
744
|
+
getLanguage(): string;
|
|
696
745
|
/**
|
|
697
746
|
* Get the total word count from final transcripts
|
|
698
747
|
*/
|
|
@@ -940,6 +989,15 @@ declare class WebSpeechProvider extends BaseTranscriber {
|
|
|
940
989
|
* Get provider capabilities
|
|
941
990
|
*/
|
|
942
991
|
getCapabilities(): ProviderCapabilities;
|
|
992
|
+
/**
|
|
993
|
+
* Restart with new language - optimized for Web Speech API
|
|
994
|
+
* Performs a quick stop/start cycle to apply new language
|
|
995
|
+
*/
|
|
996
|
+
protected restartWithNewLanguage(): Promise<void>;
|
|
997
|
+
/**
|
|
998
|
+
* Apply language change when paused
|
|
999
|
+
*/
|
|
1000
|
+
protected applyLanguageChange(): Promise<void>;
|
|
943
1001
|
/**
|
|
944
1002
|
* Set up event handlers for speech recognition
|
|
945
1003
|
*/
|
package/dist/index.js
CHANGED
|
@@ -206,6 +206,43 @@ var BaseTranscriber = class extends EventEmitter {
|
|
|
206
206
|
wordCount: this.wordCount
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Get the current language
|
|
211
|
+
* @returns Current language code
|
|
212
|
+
*/
|
|
213
|
+
getLanguage() {
|
|
214
|
+
return this.config.language || "en-US";
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Change the transcription language
|
|
218
|
+
* Automatically handles stop/restart if currently active
|
|
219
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
220
|
+
*/
|
|
221
|
+
async setLanguage(language) {
|
|
222
|
+
const previousLanguage = this.config.language;
|
|
223
|
+
this.config.language = language;
|
|
224
|
+
this.emit("languageChange", { from: previousLanguage, to: language });
|
|
225
|
+
if (this.state === "active" /* ACTIVE */) {
|
|
226
|
+
await this.restartWithNewLanguage();
|
|
227
|
+
} else if (this.state === "paused" /* PAUSED */) {
|
|
228
|
+
await this.applyLanguageChange();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Restart transcription with new language (called internally)
|
|
233
|
+
* Override in providers if needed
|
|
234
|
+
*/
|
|
235
|
+
async restartWithNewLanguage() {
|
|
236
|
+
await this.stop();
|
|
237
|
+
await this.initialize();
|
|
238
|
+
await this.start();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Apply language change without restarting
|
|
242
|
+
* Override in providers to update language settings
|
|
243
|
+
*/
|
|
244
|
+
async applyLanguageChange() {
|
|
245
|
+
}
|
|
209
246
|
/**
|
|
210
247
|
* Get recorded audio data
|
|
211
248
|
* @returns Combined audio data or null if not recording
|
|
@@ -883,6 +920,21 @@ var TranscriptionSession = class {
|
|
|
883
920
|
clear() {
|
|
884
921
|
this.transcripts = [];
|
|
885
922
|
}
|
|
923
|
+
/**
|
|
924
|
+
* Change the transcription language
|
|
925
|
+
* Automatically handles stop/restart if session is active
|
|
926
|
+
* @param language - New language code (e.g., 'en-US', 'es-ES')
|
|
927
|
+
*/
|
|
928
|
+
async setLanguage(language) {
|
|
929
|
+
await this.provider.setLanguage(language);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Get the current transcription language
|
|
933
|
+
* @returns Current language code
|
|
934
|
+
*/
|
|
935
|
+
getLanguage() {
|
|
936
|
+
return this.provider.getLanguage();
|
|
937
|
+
}
|
|
886
938
|
/**
|
|
887
939
|
* Get the total word count from final transcripts
|
|
888
940
|
*/
|
|
@@ -1355,6 +1407,38 @@ var _WebSpeechProvider = class _WebSpeechProvider extends BaseTranscriber {
|
|
|
1355
1407
|
getCapabilities() {
|
|
1356
1408
|
return _WebSpeechProvider.capabilities;
|
|
1357
1409
|
}
|
|
1410
|
+
// ==================== Language Switching ====================
|
|
1411
|
+
/**
|
|
1412
|
+
* Restart with new language - optimized for Web Speech API
|
|
1413
|
+
* Performs a quick stop/start cycle to apply new language
|
|
1414
|
+
*/
|
|
1415
|
+
async restartWithNewLanguage() {
|
|
1416
|
+
if (!this.recognition) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
const wasActive = this.state === "active" /* ACTIVE */;
|
|
1420
|
+
this.isRestarting = true;
|
|
1421
|
+
try {
|
|
1422
|
+
this.recognition.stop();
|
|
1423
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1424
|
+
this.recognition.lang = this.config.language || "en-US";
|
|
1425
|
+
if (wasActive) {
|
|
1426
|
+
this.recognition.start();
|
|
1427
|
+
}
|
|
1428
|
+
} catch (error) {
|
|
1429
|
+
this.handleError(error);
|
|
1430
|
+
} finally {
|
|
1431
|
+
this.isRestarting = false;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Apply language change when paused
|
|
1436
|
+
*/
|
|
1437
|
+
async applyLanguageChange() {
|
|
1438
|
+
if (this.recognition) {
|
|
1439
|
+
this.recognition.lang = this.config.language || "en-US";
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1358
1442
|
// ==================== Private Methods ====================
|
|
1359
1443
|
/**
|
|
1360
1444
|
* Set up event handlers for speech recognition
|