@ssml-builder-js/azure-tts-client 2.16.0 → 2.18.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 +21 -0
- package/dist/index.d.mts +223 -127
- package/dist/index.d.ts +223 -127
- package/dist/index.js +552 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +549 -98
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +29 -4
- package/src/errors.ts +44 -2
- package/src/index.ts +19 -2
- package/src/outputFormats.ts +3 -0
- package/src/safe.ts +280 -42
- package/src/synthesis.ts +380 -57
- package/src/types.ts +85 -1
- package/src/voiceCatalog.ts +4 -0
- package/test/v217-pipeline.test.ts +125 -0
- package/test/v218-pipeline.test.ts +91 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ssml-builder-js/azure-tts-client
|
|
2
2
|
|
|
3
|
+
## 2.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add fingerprint-validated resume chunks, detailed chunk execution states, unified job timeout and Retry-After limits, injectable client defaults, and strict RAW audio specification validation.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @ssml-builder-js/ssml-core@2.18.0
|
|
12
|
+
|
|
13
|
+
## 2.17.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- Add resilient chunk synthesis with aggregate validation diagnostics, custom merge/post-merge hooks, Retry-After-aware retries, structured timeouts, cancellation/resume partial results, expanded audio specifications, and voice-capability-aware Visual Editor controls.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
- @ssml-builder-js/ssml-core@2.17.0
|
|
23
|
+
|
|
3
24
|
## 2.16.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SsmlDiagnostic, AzureValidationOptions, SsmlTextRange, SsmlSourceTextSegment, SsmlSourceMarker } from '@ssml-builder-js/ssml-core';
|
|
2
2
|
import * as SpeechSDK from 'microsoft-cognitiveservices-speech-sdk';
|
|
3
3
|
|
|
4
4
|
declare const DEFAULT_OUTPUT_FORMAT = "audio-16khz-128kbitrate-mono-mp3";
|
|
@@ -46,9 +46,152 @@ declare const OUTPUT_FORMATS: {
|
|
|
46
46
|
type AzureTtsOutputFormat = keyof typeof OUTPUT_FORMATS;
|
|
47
47
|
declare function resolveMimeType(outputFormat: string): string;
|
|
48
48
|
|
|
49
|
+
type SynthesisErrorKind = "validation-error" | "azure-api-error" | "merge-error" | "audio-format-mismatch" | "unsupported-format-error" | "cancelled" | "timeout";
|
|
50
|
+
declare class AzureTtsError extends Error {
|
|
51
|
+
readonly kind: "azure-api-error";
|
|
52
|
+
readonly status: number;
|
|
53
|
+
readonly statusText: string;
|
|
54
|
+
readonly responseBody: string;
|
|
55
|
+
readonly requestId: string | null;
|
|
56
|
+
readonly retryAfterMs?: number;
|
|
57
|
+
constructor(status: number, statusText: string, responseBody: string, requestId: string | null, responseHeaders?: Headers | Readonly<Record<string, string>>);
|
|
58
|
+
}
|
|
59
|
+
/** Reads Retry-After from an error-like value, returning milliseconds when present. */
|
|
60
|
+
declare function getRetryAfterDelayMs(error: unknown): number | undefined;
|
|
61
|
+
declare class AzureTtsSdkError extends AzureTtsError {
|
|
62
|
+
readonly errorDetails: string;
|
|
63
|
+
constructor(errorDetails: string);
|
|
64
|
+
}
|
|
65
|
+
declare class SynthesisCancelledError extends Error {
|
|
66
|
+
readonly kind: "cancelled";
|
|
67
|
+
constructor(message?: string);
|
|
68
|
+
}
|
|
69
|
+
declare class SynthesisTimeoutError extends Error {
|
|
70
|
+
readonly kind: "timeout";
|
|
71
|
+
constructor(message: string);
|
|
72
|
+
}
|
|
73
|
+
declare class MergeError extends Error {
|
|
74
|
+
readonly kind: "merge-error";
|
|
75
|
+
readonly cause: unknown;
|
|
76
|
+
constructor(message: string, cause?: unknown);
|
|
77
|
+
}
|
|
78
|
+
/** Thrown when chunk headers describe incompatible audio streams. */
|
|
79
|
+
declare class AudioFormatMismatchError extends Error {
|
|
80
|
+
readonly kind: "audio-format-mismatch";
|
|
81
|
+
readonly inputSpecs: readonly AudioSpecification[];
|
|
82
|
+
constructor(message: string, inputSpecs?: readonly AudioSpecification[]);
|
|
83
|
+
}
|
|
84
|
+
/** Thrown when audio buffers require container re-multiplexing before they can be merged. */
|
|
85
|
+
declare class UnsupportedMergeFormatError extends Error {
|
|
86
|
+
readonly kind: "unsupported-format-error";
|
|
87
|
+
readonly format: string;
|
|
88
|
+
constructor(format: string);
|
|
89
|
+
}
|
|
90
|
+
type AzureTtsSynthesisError = AzureTtsError | MergeError | AudioFormatMismatchError | UnsupportedMergeFormatError | SynthesisCancelledError | SynthesisTimeoutError;
|
|
91
|
+
|
|
92
|
+
declare class AzureTtsClient {
|
|
93
|
+
#private;
|
|
94
|
+
constructor(options: AzureTtsClientOptions);
|
|
95
|
+
synthesize(ssml: string): Promise<ArrayBuffer>;
|
|
96
|
+
synthesizeSsml(ssml: string, options?: Partial<TtsConfig>): Promise<SsmlSynthesisResult>;
|
|
97
|
+
synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
98
|
+
synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
99
|
+
synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
100
|
+
synthesizeSsmlChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface SsmlValidationError {
|
|
104
|
+
readonly kind: "validation-error";
|
|
105
|
+
readonly message: string;
|
|
106
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
107
|
+
}
|
|
108
|
+
type SsmlSynthesisError = SsmlValidationError | AzureTtsSynthesisError;
|
|
109
|
+
declare class ChunkValidationError extends Error {
|
|
110
|
+
readonly kind: "validation-error";
|
|
111
|
+
readonly chunkIndex: number;
|
|
112
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
113
|
+
constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
|
|
114
|
+
}
|
|
115
|
+
interface ChunkDiagnostics {
|
|
116
|
+
readonly chunkIndex: number;
|
|
117
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
118
|
+
}
|
|
119
|
+
declare class BatchChunkValidationError extends ChunkValidationError {
|
|
120
|
+
readonly chunkDiagnostics: readonly ChunkDiagnostics[];
|
|
121
|
+
readonly totalErrorCount: number;
|
|
122
|
+
readonly errorCount: number;
|
|
123
|
+
readonly totalErrors: number;
|
|
124
|
+
constructor(chunkDiagnostics: readonly ChunkDiagnostics[]);
|
|
125
|
+
}
|
|
126
|
+
type Result<T, E> = {
|
|
127
|
+
readonly ok: true;
|
|
128
|
+
readonly success: true;
|
|
129
|
+
readonly status: "success";
|
|
130
|
+
readonly value: T;
|
|
131
|
+
} | (E extends {
|
|
132
|
+
readonly kind: infer Kind extends SynthesisErrorKind;
|
|
133
|
+
} ? {
|
|
134
|
+
readonly ok: false;
|
|
135
|
+
readonly success: false;
|
|
136
|
+
readonly status: Kind;
|
|
137
|
+
readonly error: E;
|
|
138
|
+
readonly partialResult?: PartialChunkSynthesisResult;
|
|
139
|
+
} : {
|
|
140
|
+
readonly ok: false;
|
|
141
|
+
readonly success: false;
|
|
142
|
+
readonly status: SynthesisErrorKind;
|
|
143
|
+
readonly error: E;
|
|
144
|
+
readonly partialResult?: PartialChunkSynthesisResult;
|
|
145
|
+
});
|
|
146
|
+
type SynthesisResult<T, E> = Result<T, E>;
|
|
147
|
+
type Success<T> = Extract<Result<T, never>, {
|
|
148
|
+
readonly ok: true;
|
|
149
|
+
}>;
|
|
150
|
+
type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
|
|
151
|
+
readonly status: "validation-error";
|
|
152
|
+
}>;
|
|
153
|
+
type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
|
|
154
|
+
readonly status: "azure-api-error";
|
|
155
|
+
}>;
|
|
156
|
+
type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, SsmlSynthesisError>;
|
|
157
|
+
interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
|
|
158
|
+
/** Optional nested form for callers that want to keep validation settings grouped. */
|
|
159
|
+
validation?: AzureValidationOptions;
|
|
160
|
+
signal?: AbortSignal;
|
|
161
|
+
timeouts?: SynthesisTimeouts;
|
|
162
|
+
}
|
|
163
|
+
interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
|
|
164
|
+
validation?: AzureValidationOptions;
|
|
165
|
+
outputFormat?: string;
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
timeoutMs?: number;
|
|
168
|
+
timeouts?: SynthesisTimeouts;
|
|
169
|
+
sourceNodePath?: string[];
|
|
170
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
171
|
+
concurrency?: number;
|
|
172
|
+
retryOptions?: RetryOptions;
|
|
173
|
+
cancelOnFailure?: boolean;
|
|
174
|
+
resumeChunks?: readonly SynthesizedChunk[];
|
|
175
|
+
resumeChunkIndices?: readonly number[];
|
|
176
|
+
customMerger?: CustomAudioMerger;
|
|
177
|
+
outputMimeType?: string;
|
|
178
|
+
postMergeValidator?: PostMergeValidator;
|
|
179
|
+
resumeValidation?: ResumeValidationMode;
|
|
180
|
+
}
|
|
181
|
+
type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, BatchChunkValidationError> | Result<never, SsmlSynthesisError | ChunkValidationError>;
|
|
182
|
+
interface SynthesisClient {
|
|
183
|
+
synthesizeSsml(ssml: string, options?: Partial<SynthesizeChunksOptions>): Promise<SsmlSynthesisResult>;
|
|
184
|
+
synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
185
|
+
}
|
|
186
|
+
/** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
|
|
187
|
+
declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
188
|
+
/** Validates every chunk before synthesis and returns a chunk-addressable result. */
|
|
189
|
+
declare function synthesizeSsmlChunksSafe(client: Pick<AzureTtsClient, "synthesizeSsml" | "synthesizeChunks"> | SynthesisClient, chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
190
|
+
|
|
49
191
|
interface TtsConfig {
|
|
50
192
|
signal?: AbortSignal;
|
|
51
193
|
timeoutMs?: number;
|
|
194
|
+
timeouts?: SynthesisTimeouts;
|
|
52
195
|
endpoint?: string;
|
|
53
196
|
subscriptionKey: string;
|
|
54
197
|
region: string;
|
|
@@ -68,21 +211,39 @@ interface TtsConfig {
|
|
|
68
211
|
sourceMarkers?: SsmlSourceMarker[];
|
|
69
212
|
concurrency?: number;
|
|
70
213
|
retryOptions?: RetryOptions;
|
|
214
|
+
cancelOnFailure?: boolean;
|
|
215
|
+
resumeChunks?: readonly SynthesizedChunk[];
|
|
216
|
+
resumeChunkIndices?: readonly number[];
|
|
217
|
+
customMerger?: CustomAudioMerger;
|
|
218
|
+
outputMimeType?: string;
|
|
219
|
+
postMergeValidator?: PostMergeValidator;
|
|
220
|
+
resumeValidation?: ResumeValidationMode;
|
|
71
221
|
}
|
|
72
222
|
type MappingStatus = "exact" | "fallback" | "unmapped";
|
|
73
223
|
interface AudioSpecification {
|
|
74
224
|
format: string;
|
|
75
225
|
mimeType: string;
|
|
76
|
-
codec: "pcm" | "mp3" | "opus" | "silk" | "unknown";
|
|
226
|
+
codec: "pcm" | "mulaw" | "alaw" | "siren" | "mp3" | "opus" | "silk" | "unknown";
|
|
77
227
|
sampleRate: number;
|
|
78
228
|
channels: number;
|
|
79
229
|
bitrate?: number;
|
|
230
|
+
bitDepth?: number;
|
|
231
|
+
container?: string;
|
|
232
|
+
isVbr?: boolean;
|
|
80
233
|
isCompressed: boolean;
|
|
81
234
|
}
|
|
235
|
+
type ResumeValidationMode = "strict" | "disabled";
|
|
236
|
+
interface SynthesisTimeouts {
|
|
237
|
+
urlValidationMs?: number;
|
|
238
|
+
perChunkMs?: number;
|
|
239
|
+
chunkWithRetriesMs?: number;
|
|
240
|
+
totalJobMs?: number;
|
|
241
|
+
}
|
|
82
242
|
interface RetryOptions {
|
|
83
243
|
maxRetries: number;
|
|
84
244
|
initialDelayMs: number;
|
|
85
245
|
maxDelayMs: number;
|
|
246
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
86
247
|
}
|
|
87
248
|
type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
|
|
88
249
|
interface SsmlSynthesisBoundary {
|
|
@@ -172,10 +333,51 @@ interface SynthesizeChunksOptions {
|
|
|
172
333
|
outputFormat?: AzureTtsOutputFormat | string;
|
|
173
334
|
signal?: AbortSignal;
|
|
174
335
|
timeoutMs?: number;
|
|
336
|
+
timeouts?: SynthesisTimeouts;
|
|
175
337
|
sourceNodePath?: string[];
|
|
176
338
|
concurrency?: number;
|
|
177
339
|
retryOptions?: RetryOptions;
|
|
340
|
+
cancelOnFailure?: boolean;
|
|
341
|
+
resumeChunks?: readonly SynthesizedChunk[];
|
|
342
|
+
resumeChunkIndices?: readonly number[];
|
|
343
|
+
customMerger?: CustomAudioMerger;
|
|
344
|
+
outputMimeType?: string;
|
|
345
|
+
postMergeValidator?: PostMergeValidator;
|
|
346
|
+
resumeValidation?: ResumeValidationMode;
|
|
347
|
+
}
|
|
348
|
+
interface CustomMergerContext {
|
|
349
|
+
format: string;
|
|
350
|
+
outputMimeType: string;
|
|
351
|
+
inputSpecs: readonly AudioSpecification[];
|
|
352
|
+
signal: AbortSignal;
|
|
353
|
+
}
|
|
354
|
+
type CustomAudioMerger = (buffers: ArrayBuffer[], context: CustomMergerContext) => Promise<ArrayBuffer> | ArrayBuffer;
|
|
355
|
+
type PostMergeValidator = (result: MergedSynthesisResult, context: CustomMergerContext) => boolean | undefined | Promise<boolean | undefined>;
|
|
356
|
+
interface SynthesizedChunk extends SsmlSynthesisResult {
|
|
357
|
+
chunkIndex: number;
|
|
358
|
+
/** Fingerprint of the SSML and synthesis settings used to create this chunk. */
|
|
359
|
+
fingerprint: string;
|
|
360
|
+
}
|
|
361
|
+
type ChunkExecutionStatus = "succeeded" | "failed" | "cancelled" | "pending";
|
|
362
|
+
interface ChunkExecutionState {
|
|
363
|
+
chunkIndex: number;
|
|
364
|
+
status: ChunkExecutionStatus;
|
|
365
|
+
error?: AzureTtsError | SsmlValidationError;
|
|
366
|
+
isOriginalFailure?: boolean;
|
|
367
|
+
canResume: boolean;
|
|
368
|
+
result?: SsmlSynthesisResult;
|
|
369
|
+
}
|
|
370
|
+
interface PartialChunkSynthesisResult {
|
|
371
|
+
synthesizedChunks: readonly SynthesizedChunk[];
|
|
372
|
+
completedChunks: readonly SynthesizedChunk[];
|
|
373
|
+
pendingChunkIndices: readonly number[];
|
|
374
|
+
failedChunkIndices: readonly number[];
|
|
375
|
+
cancelledChunkIndices: readonly number[];
|
|
376
|
+
chunkStates: readonly ChunkExecutionState[];
|
|
377
|
+
totalChunks: number;
|
|
178
378
|
}
|
|
379
|
+
/** Alias for applications that use the shorter result name. */
|
|
380
|
+
type PartialSynthesisResult = PartialChunkSynthesisResult;
|
|
179
381
|
interface SynthesisProgressEvent {
|
|
180
382
|
/** 1-based completed chunk count retained for backward compatibility. */
|
|
181
383
|
currentChunk: number;
|
|
@@ -199,6 +401,7 @@ interface AzureTtsLogger {
|
|
|
199
401
|
interface AzureTtsClientOptions {
|
|
200
402
|
signal?: AbortSignal;
|
|
201
403
|
timeoutMs?: number;
|
|
404
|
+
timeouts?: SynthesisTimeouts;
|
|
202
405
|
subscriptionKey: string;
|
|
203
406
|
region: string;
|
|
204
407
|
endpoint?: string;
|
|
@@ -207,123 +410,11 @@ interface AzureTtsClientOptions {
|
|
|
207
410
|
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
208
411
|
concurrency?: number;
|
|
209
412
|
retryOptions?: RetryOptions;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
readonly status: number;
|
|
216
|
-
readonly statusText: string;
|
|
217
|
-
readonly responseBody: string;
|
|
218
|
-
readonly requestId: string | null;
|
|
219
|
-
constructor(status: number, statusText: string, responseBody: string, requestId: string | null);
|
|
220
|
-
}
|
|
221
|
-
declare class AzureTtsSdkError extends AzureTtsError {
|
|
222
|
-
readonly errorDetails: string;
|
|
223
|
-
constructor(errorDetails: string);
|
|
224
|
-
}
|
|
225
|
-
declare class SynthesisCancelledError extends Error {
|
|
226
|
-
readonly kind: "cancelled";
|
|
227
|
-
constructor(message?: string);
|
|
228
|
-
}
|
|
229
|
-
declare class SynthesisTimeoutError extends Error {
|
|
230
|
-
readonly kind: "timeout";
|
|
231
|
-
constructor(message: string);
|
|
232
|
-
}
|
|
233
|
-
declare class MergeError extends Error {
|
|
234
|
-
readonly kind: "merge-error";
|
|
235
|
-
readonly cause: unknown;
|
|
236
|
-
constructor(message: string, cause?: unknown);
|
|
237
|
-
}
|
|
238
|
-
/** Thrown when chunk headers describe incompatible audio streams. */
|
|
239
|
-
declare class AudioFormatMismatchError extends Error {
|
|
240
|
-
readonly kind: "audio-format-mismatch";
|
|
241
|
-
readonly inputSpecs: readonly AudioSpecification[];
|
|
242
|
-
constructor(message: string, inputSpecs?: readonly AudioSpecification[]);
|
|
243
|
-
}
|
|
244
|
-
/** Thrown when audio buffers require container re-multiplexing before they can be merged. */
|
|
245
|
-
declare class UnsupportedMergeFormatError extends Error {
|
|
246
|
-
readonly kind: "unsupported-format-error";
|
|
247
|
-
readonly format: string;
|
|
248
|
-
constructor(format: string);
|
|
249
|
-
}
|
|
250
|
-
type AzureTtsSynthesisError = AzureTtsError | MergeError | AudioFormatMismatchError | UnsupportedMergeFormatError | SynthesisCancelledError | SynthesisTimeoutError;
|
|
251
|
-
|
|
252
|
-
interface SsmlValidationError {
|
|
253
|
-
readonly kind: "validation-error";
|
|
254
|
-
readonly message: string;
|
|
255
|
-
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
256
|
-
}
|
|
257
|
-
type SsmlSynthesisError = SsmlValidationError | AzureTtsSynthesisError;
|
|
258
|
-
declare class ChunkValidationError extends Error {
|
|
259
|
-
readonly kind: "validation-error";
|
|
260
|
-
readonly chunkIndex: number;
|
|
261
|
-
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
262
|
-
constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
|
|
263
|
-
}
|
|
264
|
-
type Result<T, E> = {
|
|
265
|
-
readonly ok: true;
|
|
266
|
-
readonly success: true;
|
|
267
|
-
readonly status: "success";
|
|
268
|
-
readonly value: T;
|
|
269
|
-
} | (E extends {
|
|
270
|
-
readonly kind: infer Kind extends SynthesisErrorKind;
|
|
271
|
-
} ? {
|
|
272
|
-
readonly ok: false;
|
|
273
|
-
readonly success: false;
|
|
274
|
-
readonly status: Kind;
|
|
275
|
-
readonly error: E;
|
|
276
|
-
} : {
|
|
277
|
-
readonly ok: false;
|
|
278
|
-
readonly success: false;
|
|
279
|
-
readonly status: SynthesisErrorKind;
|
|
280
|
-
readonly error: E;
|
|
281
|
-
});
|
|
282
|
-
type SynthesisResult<T, E> = Result<T, E>;
|
|
283
|
-
type Success<T> = Extract<Result<T, never>, {
|
|
284
|
-
readonly ok: true;
|
|
285
|
-
}>;
|
|
286
|
-
type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
|
|
287
|
-
readonly status: "validation-error";
|
|
288
|
-
}>;
|
|
289
|
-
type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
|
|
290
|
-
readonly status: "azure-api-error";
|
|
291
|
-
}>;
|
|
292
|
-
type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, SsmlSynthesisError>;
|
|
293
|
-
interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
|
|
294
|
-
/** Optional nested form for callers that want to keep validation settings grouped. */
|
|
295
|
-
validation?: AzureValidationOptions;
|
|
296
|
-
signal?: AbortSignal;
|
|
297
|
-
}
|
|
298
|
-
interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
|
|
299
|
-
validation?: AzureValidationOptions;
|
|
300
|
-
outputFormat?: string;
|
|
301
|
-
signal?: AbortSignal;
|
|
302
|
-
timeoutMs?: number;
|
|
303
|
-
sourceNodePath?: string[];
|
|
304
|
-
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
305
|
-
concurrency?: number;
|
|
306
|
-
retryOptions?: RetryOptions;
|
|
307
|
-
}
|
|
308
|
-
type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, SsmlSynthesisError | ChunkValidationError>;
|
|
309
|
-
interface SynthesisClient {
|
|
310
|
-
synthesizeSsml(ssml: string, options?: Partial<SynthesizeChunksOptions>): Promise<SsmlSynthesisResult>;
|
|
311
|
-
synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
312
|
-
}
|
|
313
|
-
/** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
|
|
314
|
-
declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
315
|
-
/** Validates every chunk before synthesis and returns a chunk-addressable result. */
|
|
316
|
-
declare function synthesizeSsmlChunksSafe(client: Pick<AzureTtsClient, "synthesizeSsml" | "synthesizeChunks"> | SynthesisClient, chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
317
|
-
|
|
318
|
-
declare class AzureTtsClient {
|
|
319
|
-
#private;
|
|
320
|
-
constructor(options: AzureTtsClientOptions);
|
|
321
|
-
synthesize(ssml: string): Promise<ArrayBuffer>;
|
|
322
|
-
synthesizeSsml(ssml: string, options?: Partial<TtsConfig>): Promise<SsmlSynthesisResult>;
|
|
323
|
-
synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
324
|
-
synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
325
|
-
synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
326
|
-
synthesizeSsmlChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
413
|
+
cancelOnFailure?: boolean;
|
|
414
|
+
customMerger?: CustomAudioMerger;
|
|
415
|
+
outputMimeType?: string;
|
|
416
|
+
postMergeValidator?: PostMergeValidator;
|
|
417
|
+
resumeValidation?: ResumeValidationMode;
|
|
327
418
|
}
|
|
328
419
|
|
|
329
420
|
type MergeAudioFormat = "wav" | "mp3" | "raw";
|
|
@@ -333,14 +424,15 @@ interface MergeAudioOptions {
|
|
|
333
424
|
outputMimeType?: string;
|
|
334
425
|
}
|
|
335
426
|
type InputAudioSpecs = AudioSpecification[];
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
427
|
+
/**
|
|
428
|
+
* Creates a deterministic, runtime-independent fingerprint for a synthesis chunk.
|
|
429
|
+
* The complete SSML is included so changes to voice, language, prosody, or text
|
|
430
|
+
* invalidate a cached result even when those settings are nested in the markup.
|
|
431
|
+
*/
|
|
432
|
+
declare function computeChunkFingerprint(ssml: string, outputFormat?: string): string;
|
|
342
433
|
interface MergeSynthesisOptions extends MergeAudioOptions {
|
|
343
|
-
customMerger?:
|
|
434
|
+
customMerger?: CustomAudioMerger;
|
|
435
|
+
postMergeValidator?: PostMergeValidator;
|
|
344
436
|
}
|
|
345
437
|
type AsyncMergeSynthesisOptions = MergeSynthesisOptions & {
|
|
346
438
|
customMerger: NonNullable<MergeSynthesisOptions["customMerger"]>;
|
|
@@ -352,10 +444,12 @@ declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | und
|
|
|
352
444
|
declare function canMergeAudioFormat(format: string): boolean;
|
|
353
445
|
/** Merges audio buffers while preserving the invariants of supported containers. */
|
|
354
446
|
declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], options: MergeAudioOptions): ArrayBuffer;
|
|
447
|
+
/** Synthesizes one SSML document, optionally retrying transient failures within the job deadline. */
|
|
355
448
|
declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
356
449
|
/** Synthesizes chunks with bounded concurrency, retries transient failures, and merges in chunk order. */
|
|
357
450
|
declare function synthesizeSsmlChunks(chunks: readonly (SsmlSynthesisChunk | string)[], config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
358
451
|
declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: AsyncMergeSynthesisOptions): Promise<MergedSynthesisResult>;
|
|
452
|
+
declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: MergeSynthesisOptions): MergedSynthesisResult | Promise<MergedSynthesisResult>;
|
|
359
453
|
declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: MergeAudioOptions): MergedSynthesisResult;
|
|
360
454
|
/** Backward-compatible audio-only synthesis helper. */
|
|
361
455
|
declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
|
|
@@ -380,6 +474,8 @@ interface FetchedAzureVoiceCatalogMetadata {
|
|
|
380
474
|
generatedAt: string;
|
|
381
475
|
apiVersion: string;
|
|
382
476
|
regions: readonly string[];
|
|
477
|
+
expiresAt?: string;
|
|
478
|
+
regionDiffs?: Readonly<Record<string, readonly string[]>>;
|
|
383
479
|
}
|
|
384
480
|
interface AzureVoiceCatalog {
|
|
385
481
|
voices: readonly AzureVoiceCatalogVoice[];
|
|
@@ -388,4 +484,4 @@ interface AzureVoiceCatalog {
|
|
|
388
484
|
/** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
|
|
389
485
|
declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
|
|
390
486
|
|
|
391
|
-
export { AudioFormatMismatchError, type AudioSpecification, type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, type AzureTtsOutputFormat, AzureTtsSdkError, type AzureTtsSynthesisError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, ChunkValidationError, type CustomMergerContext, DEFAULT_OUTPUT_FORMAT, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type InputAudioSpecs, type MappingStatus, type MergeAudioFormat, type MergeAudioOptions, MergeError, type MergeSynthesisOptions, type MergedSynthesisResult, type Result, type RetryOptions, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisChunk, type SsmlSynthesisChunksSafeResult, type SsmlSynthesisError, type SsmlSynthesisResult, type SsmlSynthesisSafeResult, type SsmlSynthesisViseme, type Success, SynthesisCancelledError, type SynthesisChunkStatus, type SynthesisErrorKind, type SynthesisProgressEvent, type SynthesisResult, SynthesisTimeoutError, type SynthesizeChunksOptions, type SynthesizeSsmlChunksSafeOptions, type SynthesizeSsmlSafeOptions, type TtsConfig, UnsupportedMergeFormatError, type ValidationErrorResult, canMergeAudioFormat, fetchAzureVoiceCatalog, inspectAudioSpecification, mergeAudioBuffers, mergeSynthesisResults, resolveMergeAudioFormat, resolveMimeType, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlChunksSafe, synthesizeSsmlSafe };
|
|
487
|
+
export { AudioFormatMismatchError, type AudioSpecification, type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, type AzureTtsOutputFormat, AzureTtsSdkError, type AzureTtsSynthesisError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, BatchChunkValidationError, type ChunkDiagnostics, type ChunkExecutionState, type ChunkExecutionStatus, ChunkValidationError, type CustomAudioMerger, type CustomMergerContext, DEFAULT_OUTPUT_FORMAT, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type InputAudioSpecs, type MappingStatus, type MergeAudioFormat, type MergeAudioOptions, MergeError, type MergeSynthesisOptions, type MergedSynthesisResult, type PartialChunkSynthesisResult, type PartialSynthesisResult, type PostMergeValidator, type Result, type ResumeValidationMode, type RetryOptions, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisChunk, type SsmlSynthesisChunksSafeResult, type SsmlSynthesisError, type SsmlSynthesisResult, type SsmlSynthesisSafeResult, type SsmlSynthesisViseme, type Success, SynthesisCancelledError, type SynthesisChunkStatus, type SynthesisErrorKind, type SynthesisProgressEvent, type SynthesisResult, SynthesisTimeoutError, type SynthesisTimeouts, type SynthesizeChunksOptions, type SynthesizeSsmlChunksSafeOptions, type SynthesizeSsmlSafeOptions, type SynthesizedChunk, type TtsConfig, UnsupportedMergeFormatError, type ValidationErrorResult, canMergeAudioFormat, computeChunkFingerprint, fetchAzureVoiceCatalog, getRetryAfterDelayMs, inspectAudioSpecification, mergeAudioBuffers, mergeSynthesisResults, resolveMergeAudioFormat, resolveMimeType, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlChunksSafe, synthesizeSsmlSafe };
|