@lokutor/sdk 1.1.42 → 1.2.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/dist/index.d.mts CHANGED
@@ -68,12 +68,14 @@ declare const AUDIO_CONFIG: {
68
68
  declare const DEFAULT_URLS: {
69
69
  VOICE_AGENT: string;
70
70
  TTS: string;
71
+ STT: string;
71
72
  };
72
73
  /**
73
74
  * SDK Configuration interface
74
75
  */
75
76
  interface LokutorConfig {
76
77
  apiKey: string;
78
+ agentId?: string;
77
79
  onTranscription?: (text: string) => void;
78
80
  onResponse?: (text: string) => void;
79
81
  onAudio?: (data: Uint8Array) => void;
@@ -91,6 +93,59 @@ interface SynthesizeOptions {
91
93
  steps?: number;
92
94
  visemes?: boolean;
93
95
  }
96
+ /**
97
+ * Options for one-shot batch transcription via STTClient.transcribe()
98
+ * (POST /stt/transcribe) — pass a complete recording and get a transcript
99
+ * back. For continuous/live transcription, use SpeechToTextClient instead.
100
+ */
101
+ interface TranscribeOptions {
102
+ /** Complete audio to transcribe. A Blob/File (e.g. from a file input or
103
+ * MediaRecorder) is sent as multipart/form-data; a raw PCM16 buffer is
104
+ * sent as base64 JSON with `format: "pcm16"`. */
105
+ audio: Blob | ArrayBuffer | Uint8Array;
106
+ /** Required when `audio` is raw PCM16 (ignored for WAV/Blob input, whose
107
+ * rate is read from the file header). */
108
+ sampleRate?: number;
109
+ /** Set when passing a raw PCM16 buffer instead of a WAV Blob. */
110
+ format?: 'wav' | 'pcm16';
111
+ language?: Language;
112
+ }
113
+ /** One transcribed segment with timing, when the engine provides them. */
114
+ interface TranscribeSegment {
115
+ text: string;
116
+ start: number;
117
+ end: number;
118
+ duration: number;
119
+ }
120
+ /** Result of STTClient.transcribe() — mirrors POST /stt/transcribe's response body. */
121
+ interface TranscribeResult {
122
+ text: string;
123
+ latencyMs: number;
124
+ engine: string;
125
+ sampleRate: number;
126
+ language: string;
127
+ durationSeconds: number;
128
+ segments?: TranscribeSegment[];
129
+ }
130
+ /**
131
+ * Continuous speech-to-text options (WS /ws/stt) — standalone transcription
132
+ * with server-side VAD, independent of the full voice-agent pipeline (no
133
+ * LLM turn, no TTS). Use this for live captioning/dictation; use
134
+ * STTClient.transcribe() for a single pre-recorded clip.
135
+ */
136
+ interface SpeechToTextOptions {
137
+ apiKey: string;
138
+ serverUrl?: string;
139
+ language?: Language;
140
+ /** VAD engine: "silero" (default, neural) or "rms" (energy-threshold fallback). */
141
+ vad?: 'silero' | 'rms';
142
+ /** Fires repeatedly while the user is mid-utterance, with the best partial guess so far. */
143
+ onPartialTranscript?: (text: string) => void;
144
+ /** Fires once VAD detects the utterance ended. */
145
+ onFinalTranscript?: (text: string) => void;
146
+ onError?: (error: LokutorError) => void;
147
+ onStatusChange?: (status: 'connecting' | 'connected' | 'disconnected') => void;
148
+ }
94
149
  /**
95
150
  * Browser audio configuration options
96
151
  */
@@ -245,6 +300,7 @@ interface AudioManager {
245
300
  declare class VoiceAgentClient {
246
301
  private ws;
247
302
  private apiKey;
303
+ private agentId;
248
304
  prompt: string;
249
305
  voice: VoiceStyle;
250
306
  language: Language;
@@ -433,6 +489,55 @@ declare class TTSClient {
433
489
  onError?: (error: any) => void;
434
490
  }): Promise<void>;
435
491
  }
492
+ /**
493
+ * Standalone speech-to-text — batch transcription of a single, complete
494
+ * audio clip (POST /stt/transcribe). No LLM, no TTS, no voice-agent session.
495
+ * For continuous/live transcription (e.g. dictation, live captions), use
496
+ * SpeechToTextClient instead.
497
+ */
498
+ declare class STTClient {
499
+ private apiKey;
500
+ private baseUrl;
501
+ constructor(config: {
502
+ apiKey: string;
503
+ serverUrl?: string;
504
+ });
505
+ /**
506
+ * Transcribe a complete audio clip. Pass a Blob/File (e.g. from a file
507
+ * input or MediaRecorder) for WAV/compressed audio, or a raw PCM16
508
+ * buffer with `format: "pcm16"` and `sampleRate` set.
509
+ */
510
+ transcribe(options: TranscribeOptions): Promise<TranscribeResult>;
511
+ }
512
+ /**
513
+ * Continuous speech-to-text (WS /ws/stt) — streams microphone audio to the
514
+ * server and receives partial transcripts while the user is speaking and a
515
+ * final transcript when the server's VAD detects the utterance ended.
516
+ * Standalone: no LLM turn, no TTS, no voice-agent session — just
517
+ * transcription. For a single pre-recorded clip, use STTClient instead.
518
+ */
519
+ declare class SpeechToTextClient {
520
+ private apiKey;
521
+ private serverUrl;
522
+ private language?;
523
+ private vad;
524
+ private onPartialTranscript?;
525
+ private onFinalTranscript?;
526
+ private onError?;
527
+ private onStatusChange?;
528
+ private ws;
529
+ private audioManager;
530
+ private isConnected;
531
+ constructor(config: SpeechToTextOptions);
532
+ /**
533
+ * Connect and start streaming microphone audio.
534
+ * @param customAudioManager Optional replacement for the default audio hardware handler (e.g. NodeAudioManager for CLI use)
535
+ */
536
+ connect(customAudioManager?: AudioManager): Promise<boolean>;
537
+ /** Force-finalize whatever utterance is currently in progress. */
538
+ endUtterance(): void;
539
+ disconnect(): void;
540
+ }
436
541
  /**
437
542
  * Quick function to start a conversation (requires manual audio piping in JS)
438
543
  */
@@ -446,6 +551,13 @@ declare function simpleTTS(options: SynthesizeOptions & {
446
551
  apiKey: string;
447
552
  onAudio: (buf: Uint8Array) => void;
448
553
  }): Promise<void>;
554
+ /**
555
+ * Quick function for standalone, one-shot transcription of a complete audio clip.
556
+ */
557
+ declare function simpleTranscribe(options: TranscribeOptions & {
558
+ apiKey: string;
559
+ serverUrl?: string;
560
+ }): Promise<TranscribeResult>;
449
561
 
450
562
  /**
451
563
  * Audio utility functions for format conversion, resampling, and PCM processing
@@ -558,6 +670,7 @@ declare class BrowserAudioManager {
558
670
  private mediaStreamAudioSourceNode;
559
671
  private scriptProcessor;
560
672
  private analyserNode;
673
+ private amplitudeBuffer;
561
674
  private mediaStream;
562
675
  private resampler;
563
676
  private nextPlaybackTime;
@@ -637,14 +750,42 @@ declare class BrowserAudioManager {
637
750
  isRecording(): boolean;
638
751
  }
639
752
 
753
+ /**
754
+ * Node.js-specific AudioManager implementation.
755
+ * Note: These require 'speaker' and 'node-record-lpcm16' to be installed by the user.
756
+ */
757
+ declare class NodeAudioManager implements AudioManager {
758
+ private speaker;
759
+ private recorder;
760
+ private recordingStream;
761
+ private isMuted;
762
+ private isListening;
763
+ constructor();
764
+ init(): Promise<void>;
765
+ startMicrophone(onAudioInput: (pcm16Data: Uint8Array) => void): Promise<void>;
766
+ stopMicrophone(): void;
767
+ playAudio(pcm16Data: Uint8Array): Promise<void>;
768
+ stopPlayback(): void;
769
+ cleanup(): void;
770
+ isMicMuted(): boolean;
771
+ setMuted(muted: boolean): void;
772
+ getAmplitude(): number;
773
+ }
774
+
640
775
  interface ConversationalPanelConfig {
776
+ /** Container element to mount the panel */
641
777
  container: HTMLElement;
642
- title: string;
643
- description: string;
644
- prompt: string;
778
+ /** Agent name or title shown in the curtain */
779
+ title?: string;
780
+ /** Short description below the title */
781
+ description?: string;
782
+ /** System prompt for the voice agent */
783
+ prompt?: string;
784
+ /** Voice style identifier (default: M1) */
645
785
  voice?: string;
786
+ /** Language code (default: en) */
646
787
  language?: string;
647
- /** Accent color for the sphere glow and highlights, e.g. '#e74c3c' */
788
+ /** Accent color for the sphere glow and highlights, e.g. '#e74c3b' */
648
789
  accentColor?: string;
649
790
  /** Background color, e.g. '#0a0a0a' */
650
791
  backgroundColor?: string;
@@ -662,7 +803,7 @@ interface ConversationalPanelConfig {
662
803
  tools?: any[];
663
804
  /** Maximum conversation duration in seconds (default 300) */
664
805
  maxDuration?: number;
665
- /** Seconds of silence before auto-close (default 30) */
806
+ /** Seconds of silence before auto-close (default 60) */
666
807
  silenceTimeout?: number;
667
808
  }
668
809
  declare class ConversationalPanel {
@@ -676,10 +817,13 @@ declare class ConversationalPanel {
676
817
  private isRunning;
677
818
  private _locked;
678
819
  private _lastSpeechTime;
820
+ private selectedVoice;
679
821
  private el;
680
822
  private curtain;
681
823
  private curtainTitle;
682
824
  private curtainDesc;
825
+ private curtainBg;
826
+ private curtainOverlay;
683
827
  private startBtn;
684
828
  private errorEl;
685
829
  private errorText;
@@ -708,6 +852,7 @@ declare class ConversationalPanel {
708
852
  setBackgroundColor(color: string): void;
709
853
  /** Update title text */
710
854
  setTitle(title: string): void;
855
+ /** Select a voice from the picker */
711
856
  /** Update description text */
712
857
  setDescription(desc: string): void;
713
858
  /** Update prompt (only takes effect on next start()) */
@@ -726,4 +871,4 @@ declare class ConversationalPanel {
726
871
  private playErrorTone;
727
872
  }
728
873
 
729
- export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, type ServerConfig, type ServerStatus, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };
874
+ export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, NodeAudioManager, STTClient, type ServerConfig, type ServerStatus, SpeechToTextClient, type SpeechToTextOptions, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type TranscribeOptions, type TranscribeResult, type TranscribeSegment, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS, simpleTranscribe };
package/dist/index.d.ts CHANGED
@@ -68,12 +68,14 @@ declare const AUDIO_CONFIG: {
68
68
  declare const DEFAULT_URLS: {
69
69
  VOICE_AGENT: string;
70
70
  TTS: string;
71
+ STT: string;
71
72
  };
72
73
  /**
73
74
  * SDK Configuration interface
74
75
  */
75
76
  interface LokutorConfig {
76
77
  apiKey: string;
78
+ agentId?: string;
77
79
  onTranscription?: (text: string) => void;
78
80
  onResponse?: (text: string) => void;
79
81
  onAudio?: (data: Uint8Array) => void;
@@ -91,6 +93,59 @@ interface SynthesizeOptions {
91
93
  steps?: number;
92
94
  visemes?: boolean;
93
95
  }
96
+ /**
97
+ * Options for one-shot batch transcription via STTClient.transcribe()
98
+ * (POST /stt/transcribe) — pass a complete recording and get a transcript
99
+ * back. For continuous/live transcription, use SpeechToTextClient instead.
100
+ */
101
+ interface TranscribeOptions {
102
+ /** Complete audio to transcribe. A Blob/File (e.g. from a file input or
103
+ * MediaRecorder) is sent as multipart/form-data; a raw PCM16 buffer is
104
+ * sent as base64 JSON with `format: "pcm16"`. */
105
+ audio: Blob | ArrayBuffer | Uint8Array;
106
+ /** Required when `audio` is raw PCM16 (ignored for WAV/Blob input, whose
107
+ * rate is read from the file header). */
108
+ sampleRate?: number;
109
+ /** Set when passing a raw PCM16 buffer instead of a WAV Blob. */
110
+ format?: 'wav' | 'pcm16';
111
+ language?: Language;
112
+ }
113
+ /** One transcribed segment with timing, when the engine provides them. */
114
+ interface TranscribeSegment {
115
+ text: string;
116
+ start: number;
117
+ end: number;
118
+ duration: number;
119
+ }
120
+ /** Result of STTClient.transcribe() — mirrors POST /stt/transcribe's response body. */
121
+ interface TranscribeResult {
122
+ text: string;
123
+ latencyMs: number;
124
+ engine: string;
125
+ sampleRate: number;
126
+ language: string;
127
+ durationSeconds: number;
128
+ segments?: TranscribeSegment[];
129
+ }
130
+ /**
131
+ * Continuous speech-to-text options (WS /ws/stt) — standalone transcription
132
+ * with server-side VAD, independent of the full voice-agent pipeline (no
133
+ * LLM turn, no TTS). Use this for live captioning/dictation; use
134
+ * STTClient.transcribe() for a single pre-recorded clip.
135
+ */
136
+ interface SpeechToTextOptions {
137
+ apiKey: string;
138
+ serverUrl?: string;
139
+ language?: Language;
140
+ /** VAD engine: "silero" (default, neural) or "rms" (energy-threshold fallback). */
141
+ vad?: 'silero' | 'rms';
142
+ /** Fires repeatedly while the user is mid-utterance, with the best partial guess so far. */
143
+ onPartialTranscript?: (text: string) => void;
144
+ /** Fires once VAD detects the utterance ended. */
145
+ onFinalTranscript?: (text: string) => void;
146
+ onError?: (error: LokutorError) => void;
147
+ onStatusChange?: (status: 'connecting' | 'connected' | 'disconnected') => void;
148
+ }
94
149
  /**
95
150
  * Browser audio configuration options
96
151
  */
@@ -245,6 +300,7 @@ interface AudioManager {
245
300
  declare class VoiceAgentClient {
246
301
  private ws;
247
302
  private apiKey;
303
+ private agentId;
248
304
  prompt: string;
249
305
  voice: VoiceStyle;
250
306
  language: Language;
@@ -433,6 +489,55 @@ declare class TTSClient {
433
489
  onError?: (error: any) => void;
434
490
  }): Promise<void>;
435
491
  }
492
+ /**
493
+ * Standalone speech-to-text — batch transcription of a single, complete
494
+ * audio clip (POST /stt/transcribe). No LLM, no TTS, no voice-agent session.
495
+ * For continuous/live transcription (e.g. dictation, live captions), use
496
+ * SpeechToTextClient instead.
497
+ */
498
+ declare class STTClient {
499
+ private apiKey;
500
+ private baseUrl;
501
+ constructor(config: {
502
+ apiKey: string;
503
+ serverUrl?: string;
504
+ });
505
+ /**
506
+ * Transcribe a complete audio clip. Pass a Blob/File (e.g. from a file
507
+ * input or MediaRecorder) for WAV/compressed audio, or a raw PCM16
508
+ * buffer with `format: "pcm16"` and `sampleRate` set.
509
+ */
510
+ transcribe(options: TranscribeOptions): Promise<TranscribeResult>;
511
+ }
512
+ /**
513
+ * Continuous speech-to-text (WS /ws/stt) — streams microphone audio to the
514
+ * server and receives partial transcripts while the user is speaking and a
515
+ * final transcript when the server's VAD detects the utterance ended.
516
+ * Standalone: no LLM turn, no TTS, no voice-agent session — just
517
+ * transcription. For a single pre-recorded clip, use STTClient instead.
518
+ */
519
+ declare class SpeechToTextClient {
520
+ private apiKey;
521
+ private serverUrl;
522
+ private language?;
523
+ private vad;
524
+ private onPartialTranscript?;
525
+ private onFinalTranscript?;
526
+ private onError?;
527
+ private onStatusChange?;
528
+ private ws;
529
+ private audioManager;
530
+ private isConnected;
531
+ constructor(config: SpeechToTextOptions);
532
+ /**
533
+ * Connect and start streaming microphone audio.
534
+ * @param customAudioManager Optional replacement for the default audio hardware handler (e.g. NodeAudioManager for CLI use)
535
+ */
536
+ connect(customAudioManager?: AudioManager): Promise<boolean>;
537
+ /** Force-finalize whatever utterance is currently in progress. */
538
+ endUtterance(): void;
539
+ disconnect(): void;
540
+ }
436
541
  /**
437
542
  * Quick function to start a conversation (requires manual audio piping in JS)
438
543
  */
@@ -446,6 +551,13 @@ declare function simpleTTS(options: SynthesizeOptions & {
446
551
  apiKey: string;
447
552
  onAudio: (buf: Uint8Array) => void;
448
553
  }): Promise<void>;
554
+ /**
555
+ * Quick function for standalone, one-shot transcription of a complete audio clip.
556
+ */
557
+ declare function simpleTranscribe(options: TranscribeOptions & {
558
+ apiKey: string;
559
+ serverUrl?: string;
560
+ }): Promise<TranscribeResult>;
449
561
 
450
562
  /**
451
563
  * Audio utility functions for format conversion, resampling, and PCM processing
@@ -558,6 +670,7 @@ declare class BrowserAudioManager {
558
670
  private mediaStreamAudioSourceNode;
559
671
  private scriptProcessor;
560
672
  private analyserNode;
673
+ private amplitudeBuffer;
561
674
  private mediaStream;
562
675
  private resampler;
563
676
  private nextPlaybackTime;
@@ -637,14 +750,42 @@ declare class BrowserAudioManager {
637
750
  isRecording(): boolean;
638
751
  }
639
752
 
753
+ /**
754
+ * Node.js-specific AudioManager implementation.
755
+ * Note: These require 'speaker' and 'node-record-lpcm16' to be installed by the user.
756
+ */
757
+ declare class NodeAudioManager implements AudioManager {
758
+ private speaker;
759
+ private recorder;
760
+ private recordingStream;
761
+ private isMuted;
762
+ private isListening;
763
+ constructor();
764
+ init(): Promise<void>;
765
+ startMicrophone(onAudioInput: (pcm16Data: Uint8Array) => void): Promise<void>;
766
+ stopMicrophone(): void;
767
+ playAudio(pcm16Data: Uint8Array): Promise<void>;
768
+ stopPlayback(): void;
769
+ cleanup(): void;
770
+ isMicMuted(): boolean;
771
+ setMuted(muted: boolean): void;
772
+ getAmplitude(): number;
773
+ }
774
+
640
775
  interface ConversationalPanelConfig {
776
+ /** Container element to mount the panel */
641
777
  container: HTMLElement;
642
- title: string;
643
- description: string;
644
- prompt: string;
778
+ /** Agent name or title shown in the curtain */
779
+ title?: string;
780
+ /** Short description below the title */
781
+ description?: string;
782
+ /** System prompt for the voice agent */
783
+ prompt?: string;
784
+ /** Voice style identifier (default: M1) */
645
785
  voice?: string;
786
+ /** Language code (default: en) */
646
787
  language?: string;
647
- /** Accent color for the sphere glow and highlights, e.g. '#e74c3c' */
788
+ /** Accent color for the sphere glow and highlights, e.g. '#e74c3b' */
648
789
  accentColor?: string;
649
790
  /** Background color, e.g. '#0a0a0a' */
650
791
  backgroundColor?: string;
@@ -662,7 +803,7 @@ interface ConversationalPanelConfig {
662
803
  tools?: any[];
663
804
  /** Maximum conversation duration in seconds (default 300) */
664
805
  maxDuration?: number;
665
- /** Seconds of silence before auto-close (default 30) */
806
+ /** Seconds of silence before auto-close (default 60) */
666
807
  silenceTimeout?: number;
667
808
  }
668
809
  declare class ConversationalPanel {
@@ -676,10 +817,13 @@ declare class ConversationalPanel {
676
817
  private isRunning;
677
818
  private _locked;
678
819
  private _lastSpeechTime;
820
+ private selectedVoice;
679
821
  private el;
680
822
  private curtain;
681
823
  private curtainTitle;
682
824
  private curtainDesc;
825
+ private curtainBg;
826
+ private curtainOverlay;
683
827
  private startBtn;
684
828
  private errorEl;
685
829
  private errorText;
@@ -708,6 +852,7 @@ declare class ConversationalPanel {
708
852
  setBackgroundColor(color: string): void;
709
853
  /** Update title text */
710
854
  setTitle(title: string): void;
855
+ /** Select a voice from the picker */
711
856
  /** Update description text */
712
857
  setDescription(desc: string): void;
713
858
  /** Update prompt (only takes effect on next start()) */
@@ -726,4 +871,4 @@ declare class ConversationalPanel {
726
871
  private playErrorTone;
727
872
  }
728
873
 
729
- export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, type ServerConfig, type ServerStatus, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS };
874
+ export { AUDIO_CONFIG, type AnalyserConfig, type AudioManager, type BrowserAudioConfig, BrowserAudioManager, type BrowserAudioOptions, ConversationalPanel, type ConversationalPanelConfig, DEFAULT_URLS, type ErrorCode, type HealthStatus, Language, type LanguageInfo, type LokutorConfig, LokutorError, type ModelInfo, NodeAudioManager, STTClient, type ServerConfig, type ServerStatus, SpeechToTextClient, type SpeechToTextOptions, StreamResampler, type SynthesizeOptions, TTSClient, type ToolCall, type ToolDefinition, type TranscribeOptions, type TranscribeResult, type TranscribeSegment, type Viseme, VoiceAgentClient, type VoiceAgentOptions, type VoiceInfo, VoiceStyle, applyLowPassFilter, bytesToPcm16, calculateRMS, float32ToPcm16, isRetryable, normalizeAudio, pcm16ToBytes, pcm16ToFloat32, resample, resampleWithAntiAliasing, simpleConversation, simpleTTS, simpleTranscribe };