telnyx 6.2.0 → 6.4.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 +36 -0
- package/client.d.mts +2 -8
- package/client.d.mts.map +1 -1
- package/client.d.ts +2 -8
- package/client.d.ts.map +1 -1
- package/client.js +4 -10
- package/client.js.map +1 -1
- package/client.mjs +4 -10
- package/client.mjs.map +1 -1
- package/core/EventEmitter.d.mts +45 -0
- package/core/EventEmitter.d.mts.map +1 -0
- package/core/EventEmitter.d.ts +45 -0
- package/core/EventEmitter.d.ts.map +1 -0
- package/core/EventEmitter.js +79 -0
- package/core/EventEmitter.js.map +1 -0
- package/core/EventEmitter.mjs +75 -0
- package/core/EventEmitter.mjs.map +1 -0
- package/core/pagination.d.mts.map +1 -1
- package/core/pagination.d.ts.map +1 -1
- package/internal/detect-platform.js +1 -1
- package/internal/detect-platform.js.map +1 -1
- package/internal/detect-platform.mjs +1 -1
- package/internal/detect-platform.mjs.map +1 -1
- package/package.json +9 -1
- package/resources/ai/assistants/assistants.d.mts +4 -0
- package/resources/ai/assistants/assistants.d.mts.map +1 -1
- package/resources/ai/assistants/assistants.d.ts +4 -0
- package/resources/ai/assistants/assistants.d.ts.map +1 -1
- package/resources/ai/assistants/assistants.js +4 -0
- package/resources/ai/assistants/assistants.js.map +1 -1
- package/resources/ai/assistants/assistants.mjs +4 -0
- package/resources/ai/assistants/assistants.mjs.map +1 -1
- package/resources/ai/assistants/index.d.mts +1 -0
- package/resources/ai/assistants/index.d.mts.map +1 -1
- package/resources/ai/assistants/index.d.ts +1 -0
- package/resources/ai/assistants/index.d.ts.map +1 -1
- package/resources/ai/assistants/index.js +3 -1
- package/resources/ai/assistants/index.js.map +1 -1
- package/resources/ai/assistants/index.mjs +1 -0
- package/resources/ai/assistants/index.mjs.map +1 -1
- package/resources/ai/assistants/tags.d.mts +59 -0
- package/resources/ai/assistants/tags.d.mts.map +1 -0
- package/resources/ai/assistants/tags.d.ts +59 -0
- package/resources/ai/assistants/tags.d.ts.map +1 -0
- package/resources/ai/assistants/tags.js +52 -0
- package/resources/ai/assistants/tags.js.map +1 -0
- package/resources/ai/assistants/tags.mjs +48 -0
- package/resources/ai/assistants/tags.mjs.map +1 -0
- package/resources/ai/audio.d.mts +0 -3
- package/resources/ai/audio.d.mts.map +1 -1
- package/resources/ai/audio.d.ts +0 -3
- package/resources/ai/audio.d.ts.map +1 -1
- package/resources/ai/audio.js +0 -3
- package/resources/ai/audio.js.map +1 -1
- package/resources/ai/audio.mjs +0 -3
- package/resources/ai/audio.mjs.map +1 -1
- package/resources/index.d.mts +1 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +2 -4
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +0 -1
- package/resources/index.mjs.map +1 -1
- package/resources/inexplicit-number-orders.d.mts.map +1 -1
- package/resources/inexplicit-number-orders.d.ts.map +1 -1
- package/resources/messages/messages.d.mts +12 -0
- package/resources/messages/messages.d.mts.map +1 -1
- package/resources/messages/messages.d.ts +12 -0
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/resources/messages/rcs.d.mts +6 -0
- package/resources/messages/rcs.d.mts.map +1 -1
- package/resources/messages/rcs.d.ts +6 -0
- package/resources/messages/rcs.d.ts.map +1 -1
- package/resources/networks/networks.d.mts.map +1 -1
- package/resources/networks/networks.d.ts.map +1 -1
- package/resources/networks/networks.js.map +1 -1
- package/resources/networks/networks.mjs.map +1 -1
- package/resources/text-to-speech/index.d.mts +2 -0
- package/resources/text-to-speech/index.d.mts.map +1 -0
- package/resources/text-to-speech/index.d.ts +2 -0
- package/resources/text-to-speech/index.d.ts.map +1 -0
- package/resources/text-to-speech/index.js +7 -0
- package/resources/text-to-speech/index.js.map +1 -0
- package/resources/text-to-speech/index.mjs +3 -0
- package/resources/text-to-speech/index.mjs.map +1 -0
- package/resources/text-to-speech/internal-base.d.mts +40 -0
- package/resources/text-to-speech/internal-base.d.mts.map +1 -0
- package/resources/text-to-speech/internal-base.d.ts +40 -0
- package/resources/text-to-speech/internal-base.d.ts.map +1 -0
- package/resources/text-to-speech/internal-base.js +52 -0
- package/resources/text-to-speech/internal-base.js.map +1 -0
- package/resources/text-to-speech/internal-base.mjs +46 -0
- package/resources/text-to-speech/internal-base.mjs.map +1 -0
- package/resources/text-to-speech/text-to-speech.d.mts +427 -0
- package/resources/text-to-speech/text-to-speech.d.mts.map +1 -0
- package/resources/text-to-speech/text-to-speech.d.ts +427 -0
- package/resources/text-to-speech/text-to-speech.d.ts.map +1 -0
- package/resources/text-to-speech/text-to-speech.js +41 -0
- package/resources/text-to-speech/text-to-speech.js.map +1 -0
- package/resources/text-to-speech/text-to-speech.mjs +37 -0
- package/resources/text-to-speech/text-to-speech.mjs.map +1 -0
- package/resources/text-to-speech/ws.d.mts +17 -0
- package/resources/text-to-speech/ws.d.mts.map +1 -0
- package/resources/text-to-speech/ws.d.ts +17 -0
- package/resources/text-to-speech/ws.d.ts.map +1 -0
- package/resources/text-to-speech/ws.js +69 -0
- package/resources/text-to-speech/ws.js.map +1 -0
- package/resources/text-to-speech/ws.mjs +64 -0
- package/resources/text-to-speech/ws.mjs.map +1 -0
- package/resources/text-to-speech.d.mts +1 -386
- package/resources/text-to-speech.d.mts.map +1 -1
- package/resources/text-to-speech.d.ts +1 -386
- package/resources/text-to-speech.d.ts.map +1 -1
- package/resources/text-to-speech.js +2 -67
- package/resources/text-to-speech.js.map +1 -1
- package/resources/text-to-speech.mjs +1 -65
- package/resources/text-to-speech.mjs.map +1 -1
- package/resources/virtual-cross-connects.d.mts.map +1 -1
- package/resources/virtual-cross-connects.d.ts.map +1 -1
- package/resources/wireguard-interfaces.d.mts.map +1 -1
- package/resources/wireguard-interfaces.d.ts.map +1 -1
- package/src/client.ts +14 -20
- package/src/core/EventEmitter.ts +98 -0
- package/src/core/pagination.ts +3 -3
- package/src/internal/detect-platform.ts +1 -1
- package/src/resources/ai/assistants/assistants.ts +20 -0
- package/src/resources/ai/assistants/index.ts +8 -0
- package/src/resources/ai/assistants/tags.ts +83 -0
- package/src/resources/ai/audio.ts +0 -3
- package/src/resources/index.ts +2 -2
- package/src/resources/inexplicit-number-orders.ts +1 -2
- package/src/resources/messages/messages.ts +14 -0
- package/src/resources/messages/rcs.ts +7 -0
- package/src/resources/networks/networks.ts +1 -2
- package/src/resources/text-to-speech/index.ts +11 -0
- package/src/resources/text-to-speech/internal-base.ts +93 -0
- package/src/resources/text-to-speech/text-to-speech.ts +518 -0
- package/src/resources/text-to-speech/ws.ts +74 -0
- package/src/resources/text-to-speech.ts +1 -475
- package/src/resources/virtual-cross-connects.ts +1 -2
- package/src/resources/wireguard-interfaces.ts +1 -2
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/speech-to-text.d.mts +0 -38
- package/resources/speech-to-text.d.mts.map +0 -1
- package/resources/speech-to-text.d.ts +0 -38
- package/resources/speech-to-text.d.ts.map +0 -1
- package/resources/speech-to-text.js +0 -23
- package/resources/speech-to-text.js.map +0 -1
- package/resources/speech-to-text.mjs +0 -19
- package/resources/speech-to-text.mjs.map +0 -1
- package/src/resources/speech-to-text.ts +0 -66
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../../core/resource';
|
|
4
|
+
import { APIPromise } from '../../core/api-promise';
|
|
5
|
+
import { RequestOptions } from '../../internal/request-options';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Text to speech streaming command operations
|
|
9
|
+
*/
|
|
10
|
+
export class TextToSpeech extends APIResource {
|
|
11
|
+
/**
|
|
12
|
+
* Generate synthesized speech audio from text input. Returns audio in the
|
|
13
|
+
* requested format (binary audio stream, base64-encoded JSON, or an audio URL for
|
|
14
|
+
* later retrieval).
|
|
15
|
+
*
|
|
16
|
+
* Authentication is provided via the standard `Authorization: Bearer <API_KEY>`
|
|
17
|
+
* header.
|
|
18
|
+
*
|
|
19
|
+
* The `voice` parameter provides a convenient shorthand to specify provider,
|
|
20
|
+
* model, and voice in a single string (e.g. `telnyx.NaturalHD.Alloy`).
|
|
21
|
+
* Alternatively, specify `provider` explicitly along with provider-specific
|
|
22
|
+
* parameters.
|
|
23
|
+
*
|
|
24
|
+
* Supported providers: `aws`, `telnyx`, `azure`, `elevenlabs`, `minimax`, `rime`,
|
|
25
|
+
* `resemble`.
|
|
26
|
+
*/
|
|
27
|
+
generate(
|
|
28
|
+
body: TextToSpeechGenerateParams,
|
|
29
|
+
options?: RequestOptions,
|
|
30
|
+
): APIPromise<TextToSpeechGenerateResponse> {
|
|
31
|
+
return this._client.post('/text-to-speech/speech', { body, ...options });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Retrieve a list of available voices from one or all TTS providers. When
|
|
36
|
+
* `provider` is specified, returns voices for that provider only. Otherwise,
|
|
37
|
+
* returns voices from all providers.
|
|
38
|
+
*
|
|
39
|
+
* Some providers (ElevenLabs, Resemble) require an API key to list voices.
|
|
40
|
+
*/
|
|
41
|
+
listVoices(
|
|
42
|
+
query: TextToSpeechListVoicesParams | null | undefined = {},
|
|
43
|
+
options?: RequestOptions,
|
|
44
|
+
): APIPromise<TextToSpeechListVoicesResponse> {
|
|
45
|
+
return this._client.get('/text-to-speech/voices', { query, ...options });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Response when `output_type` is `base64_output`.
|
|
51
|
+
*/
|
|
52
|
+
export interface TextToSpeechGenerateResponse {
|
|
53
|
+
/**
|
|
54
|
+
* Base64-encoded audio data.
|
|
55
|
+
*/
|
|
56
|
+
base64_audio?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* List of available voices.
|
|
61
|
+
*/
|
|
62
|
+
export interface TextToSpeechListVoicesResponse {
|
|
63
|
+
voices?: Array<TextToSpeechListVoicesResponse.Voice>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export namespace TextToSpeechListVoicesResponse {
|
|
67
|
+
/**
|
|
68
|
+
* A voice available for text-to-speech synthesis.
|
|
69
|
+
*/
|
|
70
|
+
export interface Voice {
|
|
71
|
+
/**
|
|
72
|
+
* Voice gender.
|
|
73
|
+
*/
|
|
74
|
+
gender?: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Language code.
|
|
78
|
+
*/
|
|
79
|
+
language?: string;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Voice name.
|
|
83
|
+
*/
|
|
84
|
+
name?: string;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The TTS provider.
|
|
88
|
+
*/
|
|
89
|
+
provider?: string;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Voice identifier.
|
|
93
|
+
*/
|
|
94
|
+
voice_id?: string;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Client-to-server frame containing text to synthesize.
|
|
100
|
+
*/
|
|
101
|
+
export interface StreamClientEvent {
|
|
102
|
+
/**
|
|
103
|
+
* Text to convert to speech. Send `" "` (single space) as an initial handshake
|
|
104
|
+
* with optional `voice_settings`. Subsequent messages contain the actual text to
|
|
105
|
+
* synthesize.
|
|
106
|
+
*/
|
|
107
|
+
text: string;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* When `true`, stops the current synthesis worker and starts a new one. Used to
|
|
111
|
+
* interrupt speech mid-stream and begin synthesizing new text.
|
|
112
|
+
*/
|
|
113
|
+
force?: boolean;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Provider-specific voice settings sent with the initial handshake. Contents vary
|
|
117
|
+
* by provider — e.g. `{"speed": 1.2}` for Minimax, `{"voice_speed": 1.5}` for
|
|
118
|
+
* Telnyx.
|
|
119
|
+
*/
|
|
120
|
+
voice_settings?: { [key: string]: unknown };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Union of all server-to-client WebSocket events for TTS streaming.
|
|
125
|
+
*/
|
|
126
|
+
export type StreamServerEvent =
|
|
127
|
+
| StreamServerEvent.AudioChunkFrame
|
|
128
|
+
| StreamServerEvent.FinalFrame
|
|
129
|
+
| StreamServerEvent.ErrorFrame;
|
|
130
|
+
|
|
131
|
+
export namespace StreamServerEvent {
|
|
132
|
+
/**
|
|
133
|
+
* Server-to-client frame containing a base64-encoded audio chunk.
|
|
134
|
+
*/
|
|
135
|
+
export interface AudioChunkFrame {
|
|
136
|
+
/**
|
|
137
|
+
* Base64-encoded audio data. May be `null` for providers that use
|
|
138
|
+
* `drop_concatenated_audio` mode (Telnyx Natural/NaturalHD, Rime, Minimax, MurfAI,
|
|
139
|
+
* Resemble) — in that case only streamed chunks carry audio.
|
|
140
|
+
*/
|
|
141
|
+
audio?: string | null;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Whether this audio was served from cache.
|
|
145
|
+
*/
|
|
146
|
+
cached?: boolean;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Always `false` for audio chunk frames.
|
|
150
|
+
*/
|
|
151
|
+
isFinal?: boolean;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The text segment that this audio chunk corresponds to.
|
|
155
|
+
*/
|
|
156
|
+
text?: string | null;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Milliseconds from the start-of-speech request to the first audio frame. Only
|
|
160
|
+
* present on the first audio chunk of a synthesis request.
|
|
161
|
+
*/
|
|
162
|
+
timeToFirstAudioFrameMs?: number;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Frame type identifier.
|
|
166
|
+
*/
|
|
167
|
+
type?: 'audio_chunk';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Server-to-client frame indicating synthesis is complete for the current text.
|
|
172
|
+
*/
|
|
173
|
+
export interface FinalFrame {
|
|
174
|
+
/**
|
|
175
|
+
* Always `null` for the final frame.
|
|
176
|
+
*/
|
|
177
|
+
audio?: null;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Always `true`.
|
|
181
|
+
*/
|
|
182
|
+
isFinal?: true;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Empty string.
|
|
186
|
+
*/
|
|
187
|
+
text?: string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Present if this was the first response frame.
|
|
191
|
+
*/
|
|
192
|
+
timeToFirstAudioFrameMs?: number;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Frame type identifier.
|
|
196
|
+
*/
|
|
197
|
+
type?: 'final';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Server-to-client frame indicating an error during synthesis. The connection is
|
|
202
|
+
* closed shortly after.
|
|
203
|
+
*/
|
|
204
|
+
export interface ErrorFrame {
|
|
205
|
+
/**
|
|
206
|
+
* Error message describing what went wrong.
|
|
207
|
+
*/
|
|
208
|
+
error?: string;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Frame type identifier.
|
|
212
|
+
*/
|
|
213
|
+
type?: 'error';
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface TextToSpeechGenerateParams {
|
|
218
|
+
/**
|
|
219
|
+
* AWS Polly provider-specific parameters.
|
|
220
|
+
*/
|
|
221
|
+
aws?: TextToSpeechGenerateParams.Aws;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Azure Cognitive Services provider-specific parameters.
|
|
225
|
+
*/
|
|
226
|
+
azure?: TextToSpeechGenerateParams.Azure;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* When `true`, bypass the audio cache and generate fresh audio.
|
|
230
|
+
*/
|
|
231
|
+
disable_cache?: boolean;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* ElevenLabs provider-specific parameters.
|
|
235
|
+
*/
|
|
236
|
+
elevenlabs?: TextToSpeechGenerateParams.Elevenlabs;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Language code (e.g. `en-US`). Usage varies by provider.
|
|
240
|
+
*/
|
|
241
|
+
language?: string;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Minimax provider-specific parameters.
|
|
245
|
+
*/
|
|
246
|
+
minimax?: TextToSpeechGenerateParams.Minimax;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Determines the response format. `binary_output` returns raw audio bytes,
|
|
250
|
+
* `base64_output` returns base64-encoded audio in JSON.
|
|
251
|
+
*/
|
|
252
|
+
output_type?: 'binary_output' | 'base64_output';
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* TTS provider. Required unless `voice` is provided.
|
|
256
|
+
*/
|
|
257
|
+
provider?: 'aws' | 'telnyx' | 'azure' | 'elevenlabs' | 'minimax' | 'rime' | 'resemble';
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Resemble AI provider-specific parameters.
|
|
261
|
+
*/
|
|
262
|
+
resemble?: TextToSpeechGenerateParams.Resemble;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Rime provider-specific parameters.
|
|
266
|
+
*/
|
|
267
|
+
rime?: TextToSpeechGenerateParams.Rime;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Telnyx provider-specific parameters.
|
|
271
|
+
*/
|
|
272
|
+
telnyx?: TextToSpeechGenerateParams.Telnyx;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The text to convert to speech.
|
|
276
|
+
*/
|
|
277
|
+
text?: string;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Text type. Use `ssml` for SSML-formatted input (supported by AWS and Azure).
|
|
281
|
+
*/
|
|
282
|
+
text_type?: 'text' | 'ssml';
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Voice identifier in the format `provider.model_id.voice_id` or
|
|
286
|
+
* `provider.voice_id`. Examples: `telnyx.NaturalHD.Alloy`,
|
|
287
|
+
* `azure.en-US-AvaMultilingualNeural`, `aws.Polly.Generative.Lucia`. When
|
|
288
|
+
* provided, `provider`, `model_id`, and `voice_id` are extracted automatically and
|
|
289
|
+
* take precedence over individual parameters.
|
|
290
|
+
*/
|
|
291
|
+
voice?: string;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Provider-specific voice settings. Contents vary by provider — see
|
|
295
|
+
* provider-specific parameter objects below.
|
|
296
|
+
*/
|
|
297
|
+
voice_settings?: { [key: string]: unknown };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export namespace TextToSpeechGenerateParams {
|
|
301
|
+
/**
|
|
302
|
+
* AWS Polly provider-specific parameters.
|
|
303
|
+
*/
|
|
304
|
+
export interface Aws {
|
|
305
|
+
/**
|
|
306
|
+
* Language code (e.g. `en-US`, `es-ES`).
|
|
307
|
+
*/
|
|
308
|
+
language_code?: string;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* List of lexicon names to apply.
|
|
312
|
+
*/
|
|
313
|
+
lexicon_names?: Array<string>;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Audio output format.
|
|
317
|
+
*/
|
|
318
|
+
output_format?: string;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Audio sample rate.
|
|
322
|
+
*/
|
|
323
|
+
sample_rate?: string;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Input text type.
|
|
327
|
+
*/
|
|
328
|
+
text_type?: 'text' | 'ssml';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Azure Cognitive Services provider-specific parameters.
|
|
333
|
+
*/
|
|
334
|
+
export interface Azure {
|
|
335
|
+
/**
|
|
336
|
+
* Custom Azure API key. If not provided, the default Telnyx key is used.
|
|
337
|
+
*/
|
|
338
|
+
api_key?: string;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Custom Azure deployment ID.
|
|
342
|
+
*/
|
|
343
|
+
deployment_id?: string;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Azure audio effect to apply.
|
|
347
|
+
*/
|
|
348
|
+
effect?: string;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Voice gender preference.
|
|
352
|
+
*/
|
|
353
|
+
gender?: string;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Language code (e.g. `en-US`).
|
|
357
|
+
*/
|
|
358
|
+
language_code?: string;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Azure audio output format.
|
|
362
|
+
*/
|
|
363
|
+
output_format?: string;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Azure region (e.g. `eastus`, `westeurope`).
|
|
367
|
+
*/
|
|
368
|
+
region?: string;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Input text type. Use `ssml` for SSML-formatted input.
|
|
372
|
+
*/
|
|
373
|
+
text_type?: 'text' | 'ssml';
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* ElevenLabs provider-specific parameters.
|
|
378
|
+
*/
|
|
379
|
+
export interface Elevenlabs {
|
|
380
|
+
/**
|
|
381
|
+
* Custom ElevenLabs API key. If not provided, the default Telnyx key is used.
|
|
382
|
+
*/
|
|
383
|
+
api_key?: string;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Language code.
|
|
387
|
+
*/
|
|
388
|
+
language_code?: string;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* ElevenLabs voice settings (stability, similarity_boost, etc.).
|
|
392
|
+
*/
|
|
393
|
+
voice_settings?: { [key: string]: unknown };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Minimax provider-specific parameters.
|
|
398
|
+
*/
|
|
399
|
+
export interface Minimax {
|
|
400
|
+
/**
|
|
401
|
+
* Language code to boost pronunciation for.
|
|
402
|
+
*/
|
|
403
|
+
language_boost?: string;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Pitch adjustment.
|
|
407
|
+
*/
|
|
408
|
+
pitch?: number;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Audio output format.
|
|
412
|
+
*/
|
|
413
|
+
response_format?: string;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Speech speed multiplier.
|
|
417
|
+
*/
|
|
418
|
+
speed?: number;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Volume level.
|
|
422
|
+
*/
|
|
423
|
+
vol?: number;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Resemble AI provider-specific parameters.
|
|
428
|
+
*/
|
|
429
|
+
export interface Resemble {
|
|
430
|
+
/**
|
|
431
|
+
* Custom Resemble API key.
|
|
432
|
+
*/
|
|
433
|
+
api_key?: string;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Audio output format.
|
|
437
|
+
*/
|
|
438
|
+
format?: string;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Synthesis precision.
|
|
442
|
+
*/
|
|
443
|
+
precision?: string;
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Audio sample rate.
|
|
447
|
+
*/
|
|
448
|
+
sample_rate?: string;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Rime provider-specific parameters.
|
|
453
|
+
*/
|
|
454
|
+
export interface Rime {
|
|
455
|
+
/**
|
|
456
|
+
* Audio output format.
|
|
457
|
+
*/
|
|
458
|
+
response_format?: string;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Audio sampling rate in Hz.
|
|
462
|
+
*/
|
|
463
|
+
sampling_rate?: number;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Voice speed multiplier.
|
|
467
|
+
*/
|
|
468
|
+
voice_speed?: number;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Telnyx provider-specific parameters.
|
|
473
|
+
*/
|
|
474
|
+
export interface Telnyx {
|
|
475
|
+
/**
|
|
476
|
+
* Audio response format.
|
|
477
|
+
*/
|
|
478
|
+
response_format?: string;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Audio sampling rate in Hz.
|
|
482
|
+
*/
|
|
483
|
+
sampling_rate?: number;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Sampling temperature.
|
|
487
|
+
*/
|
|
488
|
+
temperature?: number;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Voice speed multiplier.
|
|
492
|
+
*/
|
|
493
|
+
voice_speed?: number;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export interface TextToSpeechListVoicesParams {
|
|
498
|
+
/**
|
|
499
|
+
* API key for providers that require one to list voices (e.g. ElevenLabs).
|
|
500
|
+
*/
|
|
501
|
+
api_key?: string;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Filter voices by provider. If omitted, voices from all providers are returned.
|
|
505
|
+
*/
|
|
506
|
+
provider?: 'aws' | 'telnyx' | 'azure' | 'elevenlabs' | 'minimax' | 'rime' | 'resemble';
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export declare namespace TextToSpeech {
|
|
510
|
+
export {
|
|
511
|
+
type TextToSpeechGenerateResponse as TextToSpeechGenerateResponse,
|
|
512
|
+
type TextToSpeechListVoicesResponse as TextToSpeechListVoicesResponse,
|
|
513
|
+
type StreamClientEvent as StreamClientEvent,
|
|
514
|
+
type StreamServerEvent as StreamServerEvent,
|
|
515
|
+
type TextToSpeechGenerateParams as TextToSpeechGenerateParams,
|
|
516
|
+
type TextToSpeechListVoicesParams as TextToSpeechListVoicesParams,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import * as WS from 'ws';
|
|
4
|
+
import { TextToSpeechEmitter, buildURL } from './internal-base';
|
|
5
|
+
import * as TextToSpeechAPI from './text-to-speech';
|
|
6
|
+
import { Telnyx } from '../../client';
|
|
7
|
+
|
|
8
|
+
export class TextToSpeechWS extends TextToSpeechEmitter {
|
|
9
|
+
url: URL;
|
|
10
|
+
socket: WS.WebSocket;
|
|
11
|
+
private client: Telnyx;
|
|
12
|
+
|
|
13
|
+
constructor(client: Telnyx, parameters?: null | undefined, options?: WS.ClientOptions | null | undefined) {
|
|
14
|
+
super();
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.url = buildURL(client, parameters);
|
|
17
|
+
this.socket = new WS.WebSocket(this.url, {
|
|
18
|
+
...options,
|
|
19
|
+
headers: {
|
|
20
|
+
...this.authHeaders(),
|
|
21
|
+
...options?.headers,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
this.socket.on('message', (wsEvent) => {
|
|
26
|
+
const event = (() => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(wsEvent.toString()) as TextToSpeechAPI.StreamServerEvent;
|
|
29
|
+
} catch (err) {
|
|
30
|
+
this._onError(null, 'could not parse websocket event', err);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
if (event) {
|
|
36
|
+
this._emit('event', event);
|
|
37
|
+
|
|
38
|
+
if (event.type === 'error') {
|
|
39
|
+
this._onError(event);
|
|
40
|
+
} else {
|
|
41
|
+
// @ts-ignore TS isn't smart enough to get the relationship right here
|
|
42
|
+
this._emit(event.type, event);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.socket.on('error', (err) => {
|
|
48
|
+
this._onError(null, err.message, err);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
send(event: TextToSpeechAPI.StreamClientEvent) {
|
|
53
|
+
try {
|
|
54
|
+
this.socket.send(JSON.stringify(event));
|
|
55
|
+
} catch (err) {
|
|
56
|
+
this._onError(null, 'could not send data', err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
close(props?: { code: number; reason: string }) {
|
|
61
|
+
try {
|
|
62
|
+
this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');
|
|
63
|
+
} catch (err) {
|
|
64
|
+
this._onError(null, 'could not close the connection', err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private authHeaders(): Record<string, string> {
|
|
69
|
+
if (this.client.apiKey) {
|
|
70
|
+
return { Authorization: `Bearer ${this.client.apiKey}` };
|
|
71
|
+
}
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|