ssml-builder-js 2.14.0 → 2.16.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/dist/elements.mjs CHANGED
@@ -33,12 +33,12 @@ import {
33
33
  registerSsmlCompletionProvider,
34
34
  resolveExpressAsStyles,
35
35
  updateEditableText
36
- } from "./chunk-UZSCXPC5.mjs";
36
+ } from "./chunk-F2EMU3HM.mjs";
37
37
  import {
38
38
  buildSsml,
39
39
  parseSsml,
40
40
  validateAzureSsml
41
- } from "./chunk-QFIBPCO4.mjs";
41
+ } from "./chunk-HI74FTKY.mjs";
42
42
  import "./chunk-6S5ODO6A.mjs";
43
43
 
44
44
  // packages/ssml-editor-react/src/ssmlInsertions.ts
@@ -150,6 +150,23 @@ interface SsmlDocument {
150
150
  content?: string;
151
151
  attributes?: SsmlAttributes;
152
152
  }
153
+ interface SsmlSourceTextSegment {
154
+ text: string;
155
+ range: {
156
+ start: number;
157
+ end: number;
158
+ };
159
+ sourceNodePath: string[];
160
+ }
161
+ interface SsmlSourceMarker {
162
+ kind: "mark" | "bookmark";
163
+ name: string;
164
+ originalTextRange: {
165
+ start: number;
166
+ end: number;
167
+ };
168
+ sourceNodePath: string[];
169
+ }
153
170
 
154
171
  interface SsmlTextRange {
155
172
  start: number;
@@ -166,6 +183,18 @@ interface SsmlDiagnostic {
166
183
  message: string;
167
184
  severity: SsmlDiagnosticSeverity;
168
185
  source: SsmlDiagnosticSource;
186
+ /** Structured location and source metadata; message parsing is not required. */
187
+ targetNodePath?: string[];
188
+ /** Alias retained for callers using the shorter terminology. */
189
+ nodePath?: string[];
190
+ range?: {
191
+ start: number;
192
+ end: number;
193
+ };
194
+ tagName?: string;
195
+ attributeName?: string;
196
+ voiceName?: string;
197
+ chunkIndex?: number;
169
198
  }
170
199
  interface AzureVoiceDefinition {
171
200
  name: string;
@@ -186,6 +215,9 @@ interface AzureValidationOptions {
186
215
  customVoiceDefinitions?: readonly AzureVoiceDefinition[];
187
216
  /** Host-side validation hook for URL-bearing SSML attributes. */
188
217
  urlValidator?: AzureUrlValidator;
218
+ /** Source path associated with a chunk being validated. */
219
+ sourceNodePath?: readonly string[];
220
+ chunkIndex?: number;
189
221
  /** Alias for urlValidator retained for applications that use the longer name. */
190
222
  customUrlValidator?: AzureUrlValidator;
191
223
  /** Controls deduplication, caching, cancellation, and concurrency for URL checks. */
@@ -195,6 +227,8 @@ interface AzureValidationOptions {
195
227
  urlValidatorTimeoutMs?: number;
196
228
  urlValidatorSignal?: AbortSignal;
197
229
  urlValidatorCache?: Map<string, AzureUrlValidationResult>;
230
+ /** Shared runner used by chunk orchestration to deduplicate in-flight checks. */
231
+ urlValidatorRunner?: AzureUrlValidator;
198
232
  languageAliases?: Record<string, string | readonly string[]>;
199
233
  maxLength?: number;
200
234
  /** Maximum XML element nesting depth, counting `<speak>` as depth 1. */
@@ -221,7 +255,8 @@ type AzureUrlValidationResult = boolean | {
221
255
  type AzureUrlValidator = (url: string, context: {
222
256
  tag: string;
223
257
  attribute: string;
224
- }) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
258
+ sourceNodePath?: readonly string[];
259
+ }, signal: AbortSignal) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
225
260
  interface AzureUrlValidationRunnerOptions {
226
261
  concurrency?: number;
227
262
  cache?: Map<string, AzureUrlValidationResult>;
@@ -229,4 +264,4 @@ interface AzureUrlValidationRunnerOptions {
229
264
  timeoutMs?: number;
230
265
  }
231
266
 
232
- export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlDiagnostic as a, SsmlDocument as b, SsmlElement as c };
267
+ export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlSourceTextSegment as a, SsmlSourceMarker as b, SsmlDiagnostic as c, SsmlDocument as d, SsmlElement as e };
@@ -150,6 +150,23 @@ interface SsmlDocument {
150
150
  content?: string;
151
151
  attributes?: SsmlAttributes;
152
152
  }
153
+ interface SsmlSourceTextSegment {
154
+ text: string;
155
+ range: {
156
+ start: number;
157
+ end: number;
158
+ };
159
+ sourceNodePath: string[];
160
+ }
161
+ interface SsmlSourceMarker {
162
+ kind: "mark" | "bookmark";
163
+ name: string;
164
+ originalTextRange: {
165
+ start: number;
166
+ end: number;
167
+ };
168
+ sourceNodePath: string[];
169
+ }
153
170
 
154
171
  interface SsmlTextRange {
155
172
  start: number;
@@ -166,6 +183,18 @@ interface SsmlDiagnostic {
166
183
  message: string;
167
184
  severity: SsmlDiagnosticSeverity;
168
185
  source: SsmlDiagnosticSource;
186
+ /** Structured location and source metadata; message parsing is not required. */
187
+ targetNodePath?: string[];
188
+ /** Alias retained for callers using the shorter terminology. */
189
+ nodePath?: string[];
190
+ range?: {
191
+ start: number;
192
+ end: number;
193
+ };
194
+ tagName?: string;
195
+ attributeName?: string;
196
+ voiceName?: string;
197
+ chunkIndex?: number;
169
198
  }
170
199
  interface AzureVoiceDefinition {
171
200
  name: string;
@@ -186,6 +215,9 @@ interface AzureValidationOptions {
186
215
  customVoiceDefinitions?: readonly AzureVoiceDefinition[];
187
216
  /** Host-side validation hook for URL-bearing SSML attributes. */
188
217
  urlValidator?: AzureUrlValidator;
218
+ /** Source path associated with a chunk being validated. */
219
+ sourceNodePath?: readonly string[];
220
+ chunkIndex?: number;
189
221
  /** Alias for urlValidator retained for applications that use the longer name. */
190
222
  customUrlValidator?: AzureUrlValidator;
191
223
  /** Controls deduplication, caching, cancellation, and concurrency for URL checks. */
@@ -195,6 +227,8 @@ interface AzureValidationOptions {
195
227
  urlValidatorTimeoutMs?: number;
196
228
  urlValidatorSignal?: AbortSignal;
197
229
  urlValidatorCache?: Map<string, AzureUrlValidationResult>;
230
+ /** Shared runner used by chunk orchestration to deduplicate in-flight checks. */
231
+ urlValidatorRunner?: AzureUrlValidator;
198
232
  languageAliases?: Record<string, string | readonly string[]>;
199
233
  maxLength?: number;
200
234
  /** Maximum XML element nesting depth, counting `<speak>` as depth 1. */
@@ -221,7 +255,8 @@ type AzureUrlValidationResult = boolean | {
221
255
  type AzureUrlValidator = (url: string, context: {
222
256
  tag: string;
223
257
  attribute: string;
224
- }) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
258
+ sourceNodePath?: readonly string[];
259
+ }, signal: AbortSignal) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
225
260
  interface AzureUrlValidationRunnerOptions {
226
261
  concurrency?: number;
227
262
  cache?: Map<string, AzureUrlValidationResult>;
@@ -229,4 +264,4 @@ interface AzureUrlValidationRunnerOptions {
229
264
  timeoutMs?: number;
230
265
  }
231
266
 
232
- export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlDiagnostic as a, SsmlDocument as b, SsmlElement as c };
267
+ export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlSourceTextSegment as a, SsmlSourceMarker as b, SsmlDiagnostic as c, SsmlDocument as d, SsmlElement as e };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,51 @@
1
- export { AudioElement, AzureDiagnosticCode, AzureLanguageNormalizationOptions, AzureSsmlValidationOptions, AzureUrlValidationResult, AzureUrlValidationRunnerOptions, AzureUrlValidator, AzureValidationOptions, AzureVoiceCatalogMetadata, AzureVoiceDefinition, AzureVoiceMetadata, BookmarkElement, BreakElement, BuildPartialSsmlOptions, CustomElement, EmphasisElement, ExpressAsElement, ExtractSsmlTranslatableTextOptions, FromPlainTextToSsmlOptions, LangElement, LexiconElement, MapSsmlTextNodesOptions, MarkElement, MsttsAudioDurationElement, MsttsEmbeddingElement, MsttsSilenceElement, MsttsTtsEmbeddingElement, MsttsVisemeElement, MsttsVoiceConversionElement, NamedElement, ParagraphElement, PhonemeElement, ProsodyElement, SayAsElement, SentenceElement, SplitSsmlOptions, SsmlAttributeValue, SsmlAttributes, SsmlBackgroundAudioNode, SsmlBreakElement, SsmlChunk, SsmlChunkContext, SsmlDiagnostic, SsmlDiagnosticSeverity, SsmlDiagnosticSource, SsmlDialogNode, SsmlDocument, SsmlElement, SsmlElementBase, SsmlEmbeddingNode, SsmlExpressAsElement, SsmlNode, SsmlPartialContext, SsmlPartialProsody, SsmlPartialVoice, SsmlPhonemeElement, SsmlProsodyElement, SsmlSayAsElement, SsmlStructureIntegrityResult, SsmlStructureMismatch, SsmlText, SsmlTextNodeContext, SsmlTextRange, SsmlTtsEmbeddingNode, SsmlTurnNode, SsmlValidationError, SsmlVoiceConversionNode, SsmlVoiceElement, SubElement, VoiceElement, WordElement, areAzureLanguagesEquivalent, buildPartialSsml, buildSsml, createAzureUrlValidatorRunner, extractSsmlText, extractSsmlTranslatableText, fromPlainTextToSsml, getAzureVoiceCatalogMetadata, getBuiltInVoiceCatalogMetadata, isValidAzureAudioDuration, mapSsmlTextNodes, normalizeAzureLanguage, parseSsml, splitSsmlDocument, validateAzureSsml, validateSsml, validateSsmlStructureIntegrity } from './core.mjs';
2
- import { S as SsmlTextRange, a as SsmlDiagnostic, A as AzureValidationOptions } from './index.d-CUXRwSw0.mjs';
1
+ export { AudioElement, AzureDiagnosticCode, AzureLanguageNormalizationOptions, AzureSsmlValidationOptions, AzureUrlValidationResult, AzureUrlValidationRunnerOptions, AzureUrlValidator, AzureValidationOptions, AzureVoiceCatalogMetadata, AzureVoiceDefinition, AzureVoiceMetadata, BookmarkElement, BreakElement, BuildPartialSsmlOptions, CustomElement, Diagnostic, EmphasisElement, ExpressAsElement, ExtractSsmlTranslatableTextOptions, FromPlainTextToSsmlOptions, LangElement, LexiconElement, MapSsmlTextNodesOptions, MarkElement, MsttsAudioDurationElement, MsttsEmbeddingElement, MsttsSilenceElement, MsttsTtsEmbeddingElement, MsttsVisemeElement, MsttsVoiceConversionElement, NamedElement, ParagraphElement, PhonemeElement, ProsodyElement, SayAsElement, SentenceElement, SplitSsmlOptions, SsmlAttributeValue, SsmlAttributes, SsmlBackgroundAudioNode, SsmlBreakElement, SsmlChunk, SsmlChunkContext, SsmlDiagnostic, SsmlDiagnosticSeverity, SsmlDiagnosticSource, SsmlDialogNode, SsmlDocument, SsmlElement, SsmlElementBase, SsmlEmbeddingNode, SsmlExpressAsElement, SsmlNode, SsmlPartialContext, SsmlPartialProsody, SsmlPartialVoice, SsmlPhonemeElement, SsmlProsodyElement, SsmlSayAsElement, SsmlSourceMap, SsmlSourceMarker, SsmlSourceTextSegment, SsmlStructureIntegrityResult, SsmlStructureMismatch, SsmlText, SsmlTextNodeContext, SsmlTextRange, SsmlTtsEmbeddingNode, SsmlTurnNode, SsmlValidationError, SsmlVoiceConversionNode, SsmlVoiceElement, SubElement, VoiceElement, WordElement, areAzureLanguagesEquivalent, buildPartialSsml, buildSsml, createAzureUrlValidatorRunner, extractSsmlText, extractSsmlTranslatableText, fromPlainTextToSsml, getAzureVoiceCatalogMetadata, getBuiltInVoiceCatalogMetadata, getSsmlSourceMap, isValidAzureAudioDuration, mapSsmlTextNodes, normalizeAzureLanguage, parseSsml, splitSsmlDocument, validateAzureSsml, validateAzureSsmlChunks, validateSsml, validateSsmlStructureIntegrity } from './core.mjs';
2
+ import { S as SsmlTextRange, a as SsmlSourceTextSegment, b as SsmlSourceMarker, c as SsmlDiagnostic, A as AzureValidationOptions } from './index.d-DR5Qz43p.mjs';
3
+ import * as SpeechSDK from 'microsoft-cognitiveservices-speech-sdk';
4
+
5
+ declare const DEFAULT_OUTPUT_FORMAT = "audio-16khz-128kbitrate-mono-mp3";
6
+ declare const OUTPUT_FORMATS: {
7
+ "raw-8khz-8bit-mono-mulaw": SpeechSDK.SpeechSynthesisOutputFormat.Raw8Khz8BitMonoMULaw;
8
+ "riff-16khz-16kbps-mono-siren": SpeechSDK.SpeechSynthesisOutputFormat.Riff16Khz16KbpsMonoSiren;
9
+ "audio-16khz-16kbps-mono-siren": SpeechSDK.SpeechSynthesisOutputFormat.Audio16Khz16KbpsMonoSiren;
10
+ "audio-16khz-32kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
11
+ "audio-16khz-128kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio16Khz128KBitRateMonoMp3;
12
+ "audio-16khz-64kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio16Khz64KBitRateMonoMp3;
13
+ "audio-24khz-48kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3;
14
+ "audio-24khz-96kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio24Khz96KBitRateMonoMp3;
15
+ "audio-24khz-160kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3;
16
+ "raw-16khz-16bit-mono-truesilk": SpeechSDK.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoTrueSilk;
17
+ "riff-16khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm;
18
+ "riff-8khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff8Khz16BitMonoPcm;
19
+ "riff-24khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm;
20
+ "riff-8khz-8bit-mono-mulaw": SpeechSDK.SpeechSynthesisOutputFormat.Riff8Khz8BitMonoMULaw;
21
+ "raw-16khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoPcm;
22
+ "raw-24khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm;
23
+ "raw-8khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm;
24
+ "ogg-16khz-16bit-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Ogg16Khz16BitMonoOpus;
25
+ "ogg-24khz-16bit-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Ogg24Khz16BitMonoOpus;
26
+ "raw-48khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw48Khz16BitMonoPcm;
27
+ "riff-48khz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff48Khz16BitMonoPcm;
28
+ "audio-48khz-96kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio48Khz96KBitRateMonoMp3;
29
+ "audio-48khz-192kbitrate-mono-mp3": SpeechSDK.SpeechSynthesisOutputFormat.Audio48Khz192KBitRateMonoMp3;
30
+ "ogg-48khz-16bit-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Ogg48Khz16BitMonoOpus;
31
+ "webm-16khz-16bit-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Webm16Khz16BitMonoOpus;
32
+ "webm-24khz-16bit-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Webm24Khz16BitMonoOpus;
33
+ "webm-24khz-16bit-24kbps-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Webm24Khz16Bit24KbpsMonoOpus;
34
+ "raw-24khz-16bit-mono-truesilk": SpeechSDK.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoTrueSilk;
35
+ "raw-8khz-8bit-mono-alaw": SpeechSDK.SpeechSynthesisOutputFormat.Raw8Khz8BitMonoALaw;
36
+ "riff-8khz-8bit-mono-alaw": SpeechSDK.SpeechSynthesisOutputFormat.Riff8Khz8BitMonoALaw;
37
+ "audio-16khz-16bit-32kbps-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Audio16Khz16Bit32KbpsMonoOpus;
38
+ "audio-24khz-16bit-48kbps-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Audio24Khz16Bit48KbpsMonoOpus;
39
+ "audio-24khz-16bit-24kbps-mono-opus": SpeechSDK.SpeechSynthesisOutputFormat.Audio24Khz16Bit24KbpsMonoOpus;
40
+ "raw-22050hz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw22050Hz16BitMonoPcm;
41
+ "riff-22050hz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff22050Hz16BitMonoPcm;
42
+ "raw-44100hz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Raw44100Hz16BitMonoPcm;
43
+ "riff-44100hz-16bit-mono-pcm": SpeechSDK.SpeechSynthesisOutputFormat.Riff44100Hz16BitMonoPcm;
44
+ "amr-wb-16000hz": SpeechSDK.SpeechSynthesisOutputFormat.AmrWb16000Hz;
45
+ "g722-16khz-64kbps": SpeechSDK.SpeechSynthesisOutputFormat.G72216Khz64Kbps;
46
+ };
47
+ type AzureTtsOutputFormat = keyof typeof OUTPUT_FORMATS;
48
+ declare function resolveMimeType(outputFormat: string): string;
3
49
 
4
50
  interface TtsConfig {
5
51
  signal?: AbortSignal;
@@ -18,6 +64,26 @@ interface TtsConfig {
18
64
  /** Metadata used to map synchronization events back to the source document. */
19
65
  chunkIndex?: number;
20
66
  sourceNodePath?: string[];
67
+ /** Exact source text segments used to map individual Azure events. */
68
+ sourceTextSegments?: SsmlSourceTextSegment[];
69
+ sourceMarkers?: SsmlSourceMarker[];
70
+ concurrency?: number;
71
+ retryOptions?: RetryOptions;
72
+ }
73
+ type MappingStatus = "exact" | "fallback" | "unmapped";
74
+ interface AudioSpecification {
75
+ format: string;
76
+ mimeType: string;
77
+ codec: "pcm" | "mp3" | "opus" | "silk" | "unknown";
78
+ sampleRate: number;
79
+ channels: number;
80
+ bitrate?: number;
81
+ isCompressed: boolean;
82
+ }
83
+ interface RetryOptions {
84
+ maxRetries: number;
85
+ initialDelayMs: number;
86
+ maxDelayMs: number;
21
87
  }
22
88
  type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
23
89
  interface SsmlSynthesisBoundary {
@@ -37,6 +103,7 @@ interface SsmlSynthesisBoundary {
37
103
  /** Audio offset within the originating chunk before merge. */
38
104
  chunkAudioOffsetMs?: number;
39
105
  requestId?: string;
106
+ mappingStatus: MappingStatus;
40
107
  }
41
108
  interface SsmlSynthesisViseme {
42
109
  visemeId: number;
@@ -50,6 +117,7 @@ interface SsmlSynthesisViseme {
50
117
  originalTextRange?: SsmlTextRange;
51
118
  chunkAudioOffsetMs?: number;
52
119
  requestId?: string;
120
+ mappingStatus: MappingStatus;
53
121
  }
54
122
  interface SsmlSynthesisBookmark {
55
123
  name: string;
@@ -63,6 +131,7 @@ interface SsmlSynthesisBookmark {
63
131
  originalTextRange?: SsmlTextRange;
64
132
  chunkAudioOffsetMs?: number;
65
133
  requestId?: string;
134
+ mappingStatus: MappingStatus;
66
135
  }
67
136
  /** Audio and Azure Speech synchronization events emitted for one SSML request. */
68
137
  interface SsmlSynthesisResult {
@@ -82,6 +151,12 @@ interface SsmlSynthesisResult {
82
151
  start: number;
83
152
  end: number;
84
153
  };
154
+ /** MIME type of a result produced by an explicit merge operation. */
155
+ mimeType?: string;
156
+ audioSpec?: AudioSpecification;
157
+ }
158
+ interface MergedSynthesisResult extends SsmlSynthesisResult {
159
+ mimeType: string;
85
160
  }
86
161
  interface SsmlSynthesisChunk {
87
162
  ssml: string;
@@ -90,9 +165,17 @@ interface SsmlSynthesisChunk {
90
165
  end: number;
91
166
  };
92
167
  sourceNodePath?: string[];
168
+ sourceTextSegments?: SsmlSourceTextSegment[];
169
+ sourceMarkers?: SsmlSourceMarker[];
93
170
  }
94
171
  interface SynthesizeChunksOptions {
95
172
  onProgress?: (event: SynthesisProgressEvent) => void;
173
+ outputFormat?: AzureTtsOutputFormat | string;
174
+ signal?: AbortSignal;
175
+ timeoutMs?: number;
176
+ sourceNodePath?: string[];
177
+ concurrency?: number;
178
+ retryOptions?: RetryOptions;
96
179
  }
97
180
  interface SynthesisProgressEvent {
98
181
  /** 1-based completed chunk count retained for backward compatibility. */
@@ -104,6 +187,9 @@ interface SynthesisProgressEvent {
104
187
  status: SynthesisChunkStatus;
105
188
  durationMs: number;
106
189
  error?: unknown;
190
+ retryAttempt?: number;
191
+ nextRetryDelayMs?: number;
192
+ isRetrying?: boolean;
107
193
  }
108
194
  interface AzureTtsLogger {
109
195
  debug?: (...args: unknown[]) => void;
@@ -120,9 +206,13 @@ interface AzureTtsClientOptions {
120
206
  outputFormat?: string;
121
207
  logger?: AzureTtsLogger;
122
208
  onProgress?: (event: SynthesisProgressEvent) => void;
209
+ concurrency?: number;
210
+ retryOptions?: RetryOptions;
123
211
  }
124
212
 
213
+ type SynthesisErrorKind = "validation-error" | "azure-api-error" | "merge-error" | "audio-format-mismatch" | "unsupported-format-error" | "cancelled" | "timeout";
125
214
  declare class AzureTtsError extends Error {
215
+ readonly kind: "azure-api-error";
126
216
  readonly status: number;
127
217
  readonly statusText: string;
128
218
  readonly responseBody: string;
@@ -133,19 +223,41 @@ declare class AzureTtsSdkError extends AzureTtsError {
133
223
  readonly errorDetails: string;
134
224
  constructor(errorDetails: string);
135
225
  }
226
+ declare class SynthesisCancelledError extends Error {
227
+ readonly kind: "cancelled";
228
+ constructor(message?: string);
229
+ }
230
+ declare class SynthesisTimeoutError extends Error {
231
+ readonly kind: "timeout";
232
+ constructor(message: string);
233
+ }
234
+ declare class MergeError extends Error {
235
+ readonly kind: "merge-error";
236
+ readonly cause: unknown;
237
+ constructor(message: string, cause?: unknown);
238
+ }
239
+ /** Thrown when chunk headers describe incompatible audio streams. */
240
+ declare class AudioFormatMismatchError extends Error {
241
+ readonly kind: "audio-format-mismatch";
242
+ readonly inputSpecs: readonly AudioSpecification[];
243
+ constructor(message: string, inputSpecs?: readonly AudioSpecification[]);
244
+ }
136
245
  /** Thrown when audio buffers require container re-multiplexing before they can be merged. */
137
246
  declare class UnsupportedMergeFormatError extends Error {
247
+ readonly kind: "unsupported-format-error";
138
248
  readonly format: string;
139
249
  constructor(format: string);
140
250
  }
251
+ type AzureTtsSynthesisError = AzureTtsError | MergeError | AudioFormatMismatchError | UnsupportedMergeFormatError | SynthesisCancelledError | SynthesisTimeoutError;
141
252
 
142
253
  interface SsmlValidationError {
143
- readonly kind: "validation";
254
+ readonly kind: "validation-error";
144
255
  readonly message: string;
145
256
  readonly diagnostics: readonly SsmlDiagnostic[];
146
257
  }
258
+ type SsmlSynthesisError = SsmlValidationError | AzureTtsSynthesisError;
147
259
  declare class ChunkValidationError extends Error {
148
- readonly kind: "chunk-validation";
260
+ readonly kind: "validation-error";
149
261
  readonly chunkIndex: number;
150
262
  readonly diagnostics: readonly SsmlDiagnostic[];
151
263
  constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
@@ -155,12 +267,19 @@ type Result<T, E> = {
155
267
  readonly success: true;
156
268
  readonly status: "success";
157
269
  readonly value: T;
158
- } | {
270
+ } | (E extends {
271
+ readonly kind: infer Kind extends SynthesisErrorKind;
272
+ } ? {
159
273
  readonly ok: false;
160
274
  readonly success: false;
161
- readonly status: "validation-error" | "azure-api-error";
275
+ readonly status: Kind;
162
276
  readonly error: E;
163
- };
277
+ } : {
278
+ readonly ok: false;
279
+ readonly success: false;
280
+ readonly status: SynthesisErrorKind;
281
+ readonly error: E;
282
+ });
164
283
  type SynthesisResult<T, E> = Result<T, E>;
165
284
  type Success<T> = Extract<Result<T, never>, {
166
285
  readonly ok: true;
@@ -171,22 +290,26 @@ type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
171
290
  type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
172
291
  readonly status: "azure-api-error";
173
292
  }>;
174
- type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
293
+ type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, SsmlSynthesisError>;
175
294
  interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
176
295
  /** Optional nested form for callers that want to keep validation settings grouped. */
177
296
  validation?: AzureValidationOptions;
297
+ signal?: AbortSignal;
178
298
  }
179
299
  interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
180
300
  validation?: AzureValidationOptions;
181
301
  outputFormat?: string;
302
+ signal?: AbortSignal;
303
+ timeoutMs?: number;
304
+ sourceNodePath?: string[];
182
305
  onProgress?: (event: SynthesisProgressEvent) => void;
306
+ concurrency?: number;
307
+ retryOptions?: RetryOptions;
183
308
  }
184
- type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, AzureTtsError>;
309
+ type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, SsmlSynthesisError | ChunkValidationError>;
185
310
  interface SynthesisClient {
186
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
187
- synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: {
188
- onProgress?: (event: SynthesisProgressEvent) => void;
189
- }): Promise<SsmlSynthesisResult>;
311
+ synthesizeSsml(ssml: string, options?: Partial<SynthesizeChunksOptions>): Promise<SsmlSynthesisResult>;
312
+ synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
190
313
  }
191
314
  /** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
192
315
  declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
@@ -197,7 +320,7 @@ declare class AzureTtsClient {
197
320
  #private;
198
321
  constructor(options: AzureTtsClientOptions);
199
322
  synthesize(ssml: string): Promise<ArrayBuffer>;
200
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
323
+ synthesizeSsml(ssml: string, options?: Partial<TtsConfig>): Promise<SsmlSynthesisResult>;
201
324
  synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
202
325
  synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
203
326
  synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
@@ -205,16 +328,36 @@ declare class AzureTtsClient {
205
328
  }
206
329
 
207
330
  type MergeAudioFormat = "wav" | "mp3" | "raw";
331
+ interface MergeAudioOptions {
332
+ format: AzureTtsOutputFormat;
333
+ signal?: AbortSignal;
334
+ outputMimeType?: string;
335
+ }
336
+ type InputAudioSpecs = AudioSpecification[];
337
+ interface CustomMergerContext {
338
+ format: string;
339
+ outputMimeType: string;
340
+ inputSpecs: InputAudioSpecs;
341
+ signal: AbortSignal;
342
+ }
343
+ interface MergeSynthesisOptions extends MergeAudioOptions {
344
+ customMerger?: (buffers: ArrayBuffer[], context: CustomMergerContext) => Promise<ArrayBuffer> | ArrayBuffer;
345
+ }
346
+ type AsyncMergeSynthesisOptions = MergeSynthesisOptions & {
347
+ customMerger: NonNullable<MergeSynthesisOptions["customMerger"]>;
348
+ };
349
+ /** Extracts the stream specification from a WAV/MP3 header and output-format fallback. */
350
+ declare function inspectAudioSpecification(buffer: ArrayBuffer, format: string): AudioSpecification;
208
351
  /** Returns whether the named output format can be safely concatenated without re-multiplexing. */
209
352
  declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | undefined;
210
353
  declare function canMergeAudioFormat(format: string): boolean;
211
354
  /** Merges audio buffers while preserving the invariants of supported containers. */
212
- declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], format: string): ArrayBuffer;
355
+ declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], options: MergeAudioOptions): ArrayBuffer;
213
356
  declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
214
- /** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
357
+ /** Synthesizes chunks with bounded concurrency, retries transient failures, and merges in chunk order. */
215
358
  declare function synthesizeSsmlChunks(chunks: readonly (SsmlSynthesisChunk | string)[], config: TtsConfig): Promise<SsmlSynthesisResult>;
216
- /** Concatenates audio buffers and shifts all synchronization events by prior chunk durations. */
217
- declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], format?: string): SsmlSynthesisResult;
359
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: AsyncMergeSynthesisOptions): Promise<MergedSynthesisResult>;
360
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: MergeAudioOptions): MergedSynthesisResult;
218
361
  /** Backward-compatible audio-only synthesis helper. */
219
362
  declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
220
363
 
@@ -246,4 +389,4 @@ interface AzureVoiceCatalog {
246
389
  /** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
247
390
  declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
248
391
 
249
- export { type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, AzureTtsSdkError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, ChunkValidationError, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type MergeAudioFormat, type Result, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisChunk, type SsmlSynthesisChunksSafeResult, type SsmlSynthesisResult, type SsmlSynthesisSafeResult, type SsmlSynthesisViseme, type Success, type SynthesisChunkStatus, type SynthesisProgressEvent, type SynthesisResult, type SynthesizeChunksOptions, type SynthesizeSsmlChunksSafeOptions, type SynthesizeSsmlSafeOptions, type TtsConfig, UnsupportedMergeFormatError, type ValidationErrorResult, canMergeAudioFormat, fetchAzureVoiceCatalog, mergeAudioBuffers, mergeSynthesisResults, resolveMergeAudioFormat, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlChunksSafe, synthesizeSsmlSafe };
392
+ 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 };