@micdrop/gradium 1.1.2 → 1.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/README.md CHANGED
@@ -20,7 +20,7 @@ import { MicdropServer } from '@micdrop/server'
20
20
 
21
21
  const tts = new GradiumTTS({
22
22
  apiKey: process.env.GRADIUM_API_KEY || '',
23
- voiceId: 'YTpq7expH9539ERJ', // Gradium voice ID
23
+ voiceId: 'Bla6SbVMczYnOhfK', // Gradium voice ID
24
24
  modelName: 'default', // Optional: model name
25
25
  outputFormat: 'pcm_16000', // Optional: audio format
26
26
  region: 'eu', // Optional: 'eu' or 'us'
@@ -47,7 +47,7 @@ import { Readable } from 'stream'
47
47
 
48
48
  const tts = new GradiumTTS({
49
49
  apiKey: process.env.GRADIUM_API_KEY || '',
50
- voiceId: 'YTpq7expH9539ERJ',
50
+ voiceId: 'Bla6SbVMczYnOhfK',
51
51
  })
52
52
 
53
53
  // Audio is raw PCM, 16 bits, 16 kHz, mono
@@ -59,10 +59,10 @@ tts.speak(Readable.from(['Hello! ', 'What can I do for you?']))
59
59
 
60
60
  ### Events
61
61
 
62
- | Event | Payload | Description |
63
- | -------- | ---------- | ------------------------------------------------------------------------ |
64
- | `Audio` | `Buffer` | A chunk of audio, PCM 16 bits, 16 kHz, mono, ready to be played. |
65
- | `Failed` | `string[]` | Synthesis gave up after its retries, with the text that stayed unspoken. |
62
+ | Event | Payload | Description |
63
+ | -------- | ---------- | --------------------------------------------------------------------------------------------------------- |
64
+ | `Audio` | `Buffer` | A chunk of audio, PCM 16 bits, 16 kHz, mono, ready to be played. |
65
+ | `Failed` | `string[]` | Gradium refused the request, or every reconnection attempt failed, with the text that stayed unspoken. The next utterance connects again. |
66
66
 
67
67
  See the [TTS interface](https://micdrop.dev/docs/ai-integration/custom-integrations/custom-tts) for the full contract.
68
68
 
@@ -111,10 +111,10 @@ stt.transcribe(createReadStream('speech.pcm'))
111
111
 
112
112
  ### Events
113
113
 
114
- | Event | Payload | Description |
115
- | ------------ | ---------- | ------------------------------------------------------------------------------ |
116
- | `Transcript` | `string` | Transcription of one utterance. The text is empty when nothing was recognized. |
117
- | `Failed` | `Buffer[]` | Transcription gave up after its retries, with the audio chunks left pending. |
114
+ | Event | Payload | Description |
115
+ | ------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
116
+ | `Transcript` | `string` | Transcription of one utterance, emitted once per utterance even when the next one starts before it returns. The text is empty when nothing was recognized. |
117
+ | `Failed` | `Buffer[]` | Every reconnection attempt failed, with the audio of the utterances still waiting for their transcript. The next utterance connects again. |
118
118
 
119
119
  See the [STT interface](https://micdrop.dev/docs/ai-integration/custom-integrations/custom-stt) for the full contract.
120
120
 
package/dist/index.d.mts CHANGED
@@ -125,65 +125,58 @@ interface GradiumErrorResponse {
125
125
 
126
126
  declare class GradiumSTT extends STT {
127
127
  private options;
128
- private socket?;
129
- private initPromise;
130
- private reconnectTimeout?;
131
- private connectionTimeout?;
132
- private transcriptionTimeout?;
133
- private audioChunksPending;
134
- private transcript;
128
+ private socket;
129
+ private utterances;
135
130
  private flushId;
136
131
  private delayInFrames;
137
- private retryCount;
138
- private destroyed;
139
132
  constructor(options: GradiumSTTOptions);
140
133
  transcribe(audioStream: Readable): void;
141
134
  destroy(): void;
142
- private connect;
143
- private getEndpoint;
144
- private initWS;
145
135
  private buildJsonConfig;
146
- private sendSetup;
136
+ /** Sends the setup, and waits for the server to accept it */
137
+ private handshake;
147
138
  private sendAudioChunk;
148
139
  /**
149
- * Follows the speech with as much silence as the transcription lags behind.
140
+ * Silence as long as the transcription lags behind, to follow the speech.
150
141
  *
151
142
  * The model writes each word a few frames after hearing it, and a flush only
152
143
  * processes the audio already sent. With nothing after the last word, the
153
144
  * server confirms the flush before writing that word, which then opens the
154
145
  * next transcript.
155
146
  */
156
- private sendTrailingSilence;
157
- private sendFlush;
147
+ private trailingSilence;
148
+ /** Sends the trailing silence, already the last audio chunk, and the flush */
149
+ private sendEnd;
158
150
  private emitTranscript;
159
- private handleMessage;
160
- private reconnect;
151
+ private onOpen;
152
+ private onMessage;
153
+ private onFailed;
161
154
  }
162
155
 
163
156
  declare class GradiumTTS extends TTS {
164
157
  private readonly options;
165
- private socket?;
166
- private initPromise;
158
+ private socket;
167
159
  private counter;
168
160
  private generation;
169
- private isProcessing;
170
- private reconnectTimeout?;
171
- private connectionTimeout?;
172
- private textSent;
173
- private textBuffer;
174
- private retryCount;
175
- private destroyed;
161
+ private request?;
176
162
  constructor(options: GradiumTTSOptions);
177
- private connect;
178
163
  speak(textStream: Readable): void;
164
+ /**
165
+ * Stops the current utterance. Gradium can only stop a synthesis by closing
166
+ * its connection, so a new one opens right away.
167
+ */
179
168
  cancel(): void;
180
169
  destroy(): void;
181
- private getEndpoint;
182
- private initWS;
170
+ /** Forgets the current request, and closes the connection that carries it */
171
+ private stopRequest;
183
172
  private sendSetup;
184
173
  private sendTranscript;
174
+ /** Sends the last partial word, then the end of the text */
175
+ private sendEnd;
176
+ private onOpen;
177
+ private onMessage;
185
178
  private processAudioMessage;
186
- private reconnect;
179
+ private onFailed;
187
180
  }
188
181
 
189
182
  export { DEFAULT_INPUT_FORMAT, DEFAULT_LANGUAGE, DEFAULT_MODEL_NAME, DEFAULT_OUTPUT_FORMAT, DEFAULT_REGION, type GradiumASRJsonConfig, type GradiumASRResponse, type GradiumASRSetupMessage, type GradiumAudioMessage, type GradiumAudioResponse, type GradiumEndTextResponse, type GradiumEosMessage, type GradiumEosResponse, type GradiumErrorResponse, type GradiumFlushMessage, type GradiumFlushedResponse, type GradiumInputFormat, type GradiumJsonConfig, type GradiumOutputFormat, type GradiumReadyResponse, type GradiumRegion, type GradiumResponse, GradiumSTT, type GradiumSTTOptions, type GradiumSetupMessage, type GradiumStepResponse, GradiumTTS, type GradiumTTSOptions, type GradiumTextMessage, type GradiumTextResponse };
package/dist/index.d.ts CHANGED
@@ -125,65 +125,58 @@ interface GradiumErrorResponse {
125
125
 
126
126
  declare class GradiumSTT extends STT {
127
127
  private options;
128
- private socket?;
129
- private initPromise;
130
- private reconnectTimeout?;
131
- private connectionTimeout?;
132
- private transcriptionTimeout?;
133
- private audioChunksPending;
134
- private transcript;
128
+ private socket;
129
+ private utterances;
135
130
  private flushId;
136
131
  private delayInFrames;
137
- private retryCount;
138
- private destroyed;
139
132
  constructor(options: GradiumSTTOptions);
140
133
  transcribe(audioStream: Readable): void;
141
134
  destroy(): void;
142
- private connect;
143
- private getEndpoint;
144
- private initWS;
145
135
  private buildJsonConfig;
146
- private sendSetup;
136
+ /** Sends the setup, and waits for the server to accept it */
137
+ private handshake;
147
138
  private sendAudioChunk;
148
139
  /**
149
- * Follows the speech with as much silence as the transcription lags behind.
140
+ * Silence as long as the transcription lags behind, to follow the speech.
150
141
  *
151
142
  * The model writes each word a few frames after hearing it, and a flush only
152
143
  * processes the audio already sent. With nothing after the last word, the
153
144
  * server confirms the flush before writing that word, which then opens the
154
145
  * next transcript.
155
146
  */
156
- private sendTrailingSilence;
157
- private sendFlush;
147
+ private trailingSilence;
148
+ /** Sends the trailing silence, already the last audio chunk, and the flush */
149
+ private sendEnd;
158
150
  private emitTranscript;
159
- private handleMessage;
160
- private reconnect;
151
+ private onOpen;
152
+ private onMessage;
153
+ private onFailed;
161
154
  }
162
155
 
163
156
  declare class GradiumTTS extends TTS {
164
157
  private readonly options;
165
- private socket?;
166
- private initPromise;
158
+ private socket;
167
159
  private counter;
168
160
  private generation;
169
- private isProcessing;
170
- private reconnectTimeout?;
171
- private connectionTimeout?;
172
- private textSent;
173
- private textBuffer;
174
- private retryCount;
175
- private destroyed;
161
+ private request?;
176
162
  constructor(options: GradiumTTSOptions);
177
- private connect;
178
163
  speak(textStream: Readable): void;
164
+ /**
165
+ * Stops the current utterance. Gradium can only stop a synthesis by closing
166
+ * its connection, so a new one opens right away.
167
+ */
179
168
  cancel(): void;
180
169
  destroy(): void;
181
- private getEndpoint;
182
- private initWS;
170
+ /** Forgets the current request, and closes the connection that carries it */
171
+ private stopRequest;
183
172
  private sendSetup;
184
173
  private sendTranscript;
174
+ /** Sends the last partial word, then the end of the text */
175
+ private sendEnd;
176
+ private onOpen;
177
+ private onMessage;
185
178
  private processAudioMessage;
186
- private reconnect;
179
+ private onFailed;
187
180
  }
188
181
 
189
182
  export { DEFAULT_INPUT_FORMAT, DEFAULT_LANGUAGE, DEFAULT_MODEL_NAME, DEFAULT_OUTPUT_FORMAT, DEFAULT_REGION, type GradiumASRJsonConfig, type GradiumASRResponse, type GradiumASRSetupMessage, type GradiumAudioMessage, type GradiumAudioResponse, type GradiumEndTextResponse, type GradiumEosMessage, type GradiumEosResponse, type GradiumErrorResponse, type GradiumFlushMessage, type GradiumFlushedResponse, type GradiumInputFormat, type GradiumJsonConfig, type GradiumOutputFormat, type GradiumReadyResponse, type GradiumRegion, type GradiumResponse, GradiumSTT, type GradiumSTTOptions, type GradiumSetupMessage, type GradiumStepResponse, GradiumTTS, type GradiumTTSOptions, type GradiumTextMessage, type GradiumTextResponse };