ssml-builder-js 2.14.0 → 2.15.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-BDY2Q2JL.mjs";
37
37
  import {
38
38
  buildSsml,
39
39
  parseSsml,
40
40
  validateAzureSsml
41
- } from "./chunk-QFIBPCO4.mjs";
41
+ } from "./chunk-WXFLUCLR.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;
@@ -186,6 +203,8 @@ interface AzureValidationOptions {
186
203
  customVoiceDefinitions?: readonly AzureVoiceDefinition[];
187
204
  /** Host-side validation hook for URL-bearing SSML attributes. */
188
205
  urlValidator?: AzureUrlValidator;
206
+ /** Source path associated with a chunk being validated. */
207
+ sourceNodePath?: readonly string[];
189
208
  /** Alias for urlValidator retained for applications that use the longer name. */
190
209
  customUrlValidator?: AzureUrlValidator;
191
210
  /** Controls deduplication, caching, cancellation, and concurrency for URL checks. */
@@ -221,7 +240,8 @@ type AzureUrlValidationResult = boolean | {
221
240
  type AzureUrlValidator = (url: string, context: {
222
241
  tag: string;
223
242
  attribute: string;
224
- }) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
243
+ sourceNodePath?: readonly string[];
244
+ }, signal: AbortSignal) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
225
245
  interface AzureUrlValidationRunnerOptions {
226
246
  concurrency?: number;
227
247
  cache?: Map<string, AzureUrlValidationResult>;
@@ -229,4 +249,4 @@ interface AzureUrlValidationRunnerOptions {
229
249
  timeoutMs?: number;
230
250
  }
231
251
 
232
- export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlDiagnostic as a, SsmlDocument as b, SsmlElement as c };
252
+ 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;
@@ -186,6 +203,8 @@ interface AzureValidationOptions {
186
203
  customVoiceDefinitions?: readonly AzureVoiceDefinition[];
187
204
  /** Host-side validation hook for URL-bearing SSML attributes. */
188
205
  urlValidator?: AzureUrlValidator;
206
+ /** Source path associated with a chunk being validated. */
207
+ sourceNodePath?: readonly string[];
189
208
  /** Alias for urlValidator retained for applications that use the longer name. */
190
209
  customUrlValidator?: AzureUrlValidator;
191
210
  /** Controls deduplication, caching, cancellation, and concurrency for URL checks. */
@@ -221,7 +240,8 @@ type AzureUrlValidationResult = boolean | {
221
240
  type AzureUrlValidator = (url: string, context: {
222
241
  tag: string;
223
242
  attribute: string;
224
- }) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
243
+ sourceNodePath?: readonly string[];
244
+ }, signal: AbortSignal) => AzureUrlValidationResult | Promise<AzureUrlValidationResult>;
225
245
  interface AzureUrlValidationRunnerOptions {
226
246
  concurrency?: number;
227
247
  cache?: Map<string, AzureUrlValidationResult>;
@@ -229,4 +249,4 @@ interface AzureUrlValidationRunnerOptions {
229
249
  timeoutMs?: number;
230
250
  }
231
251
 
232
- export type { AzureValidationOptions as A, SsmlTextRange as S, SsmlDiagnostic as a, SsmlDocument as b, SsmlElement as c };
252
+ 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, 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, 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-8BvkB9gz.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,9 @@ 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[];
21
70
  }
22
71
  type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
23
72
  interface SsmlSynthesisBoundary {
@@ -82,6 +131,11 @@ interface SsmlSynthesisResult {
82
131
  start: number;
83
132
  end: number;
84
133
  };
134
+ /** MIME type of a result produced by an explicit merge operation. */
135
+ mimeType?: string;
136
+ }
137
+ interface MergedSynthesisResult extends SsmlSynthesisResult {
138
+ mimeType: string;
85
139
  }
86
140
  interface SsmlSynthesisChunk {
87
141
  ssml: string;
@@ -90,9 +144,15 @@ interface SsmlSynthesisChunk {
90
144
  end: number;
91
145
  };
92
146
  sourceNodePath?: string[];
147
+ sourceTextSegments?: SsmlSourceTextSegment[];
148
+ sourceMarkers?: SsmlSourceMarker[];
93
149
  }
94
150
  interface SynthesizeChunksOptions {
95
151
  onProgress?: (event: SynthesisProgressEvent) => void;
152
+ outputFormat?: AzureTtsOutputFormat | string;
153
+ signal?: AbortSignal;
154
+ timeoutMs?: number;
155
+ sourceNodePath?: string[];
96
156
  }
97
157
  interface SynthesisProgressEvent {
98
158
  /** 1-based completed chunk count retained for backward compatibility. */
@@ -122,7 +182,9 @@ interface AzureTtsClientOptions {
122
182
  onProgress?: (event: SynthesisProgressEvent) => void;
123
183
  }
124
184
 
185
+ type SynthesisErrorKind = "validation-error" | "azure-api-error" | "merge-error" | "unsupported-format-error" | "cancelled" | "timeout";
125
186
  declare class AzureTtsError extends Error {
187
+ readonly kind: "azure-api-error";
126
188
  readonly status: number;
127
189
  readonly statusText: string;
128
190
  readonly responseBody: string;
@@ -133,19 +195,35 @@ declare class AzureTtsSdkError extends AzureTtsError {
133
195
  readonly errorDetails: string;
134
196
  constructor(errorDetails: string);
135
197
  }
198
+ declare class SynthesisCancelledError extends Error {
199
+ readonly kind: "cancelled";
200
+ constructor(message?: string);
201
+ }
202
+ declare class SynthesisTimeoutError extends Error {
203
+ readonly kind: "timeout";
204
+ constructor(message: string);
205
+ }
206
+ declare class MergeError extends Error {
207
+ readonly kind: "merge-error";
208
+ readonly cause: unknown;
209
+ constructor(message: string, cause?: unknown);
210
+ }
136
211
  /** Thrown when audio buffers require container re-multiplexing before they can be merged. */
137
212
  declare class UnsupportedMergeFormatError extends Error {
213
+ readonly kind: "unsupported-format-error";
138
214
  readonly format: string;
139
215
  constructor(format: string);
140
216
  }
217
+ type AzureTtsSynthesisError = AzureTtsError | MergeError | UnsupportedMergeFormatError | SynthesisCancelledError | SynthesisTimeoutError;
141
218
 
142
219
  interface SsmlValidationError {
143
- readonly kind: "validation";
220
+ readonly kind: "validation-error";
144
221
  readonly message: string;
145
222
  readonly diagnostics: readonly SsmlDiagnostic[];
146
223
  }
224
+ type SsmlSynthesisError = SsmlValidationError | AzureTtsSynthesisError;
147
225
  declare class ChunkValidationError extends Error {
148
- readonly kind: "chunk-validation";
226
+ readonly kind: "validation-error";
149
227
  readonly chunkIndex: number;
150
228
  readonly diagnostics: readonly SsmlDiagnostic[];
151
229
  constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
@@ -155,12 +233,19 @@ type Result<T, E> = {
155
233
  readonly success: true;
156
234
  readonly status: "success";
157
235
  readonly value: T;
158
- } | {
236
+ } | (E extends {
237
+ readonly kind: infer Kind extends SynthesisErrorKind;
238
+ } ? {
159
239
  readonly ok: false;
160
240
  readonly success: false;
161
- readonly status: "validation-error" | "azure-api-error";
241
+ readonly status: Kind;
162
242
  readonly error: E;
163
- };
243
+ } : {
244
+ readonly ok: false;
245
+ readonly success: false;
246
+ readonly status: SynthesisErrorKind;
247
+ readonly error: E;
248
+ });
164
249
  type SynthesisResult<T, E> = Result<T, E>;
165
250
  type Success<T> = Extract<Result<T, never>, {
166
251
  readonly ok: true;
@@ -171,22 +256,24 @@ type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
171
256
  type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
172
257
  readonly status: "azure-api-error";
173
258
  }>;
174
- type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
259
+ type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, SsmlSynthesisError>;
175
260
  interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
176
261
  /** Optional nested form for callers that want to keep validation settings grouped. */
177
262
  validation?: AzureValidationOptions;
263
+ signal?: AbortSignal;
178
264
  }
179
265
  interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
180
266
  validation?: AzureValidationOptions;
181
267
  outputFormat?: string;
268
+ signal?: AbortSignal;
269
+ timeoutMs?: number;
270
+ sourceNodePath?: string[];
182
271
  onProgress?: (event: SynthesisProgressEvent) => void;
183
272
  }
184
- type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, AzureTtsError>;
273
+ type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, SsmlSynthesisError | ChunkValidationError>;
185
274
  interface SynthesisClient {
186
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
187
- synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: {
188
- onProgress?: (event: SynthesisProgressEvent) => void;
189
- }): Promise<SsmlSynthesisResult>;
275
+ synthesizeSsml(ssml: string, options?: Partial<SynthesizeChunksOptions>): Promise<SsmlSynthesisResult>;
276
+ synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
190
277
  }
191
278
  /** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
192
279
  declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
@@ -197,7 +284,7 @@ declare class AzureTtsClient {
197
284
  #private;
198
285
  constructor(options: AzureTtsClientOptions);
199
286
  synthesize(ssml: string): Promise<ArrayBuffer>;
200
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
287
+ synthesizeSsml(ssml: string, options?: Partial<TtsConfig>): Promise<SsmlSynthesisResult>;
201
288
  synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
202
289
  synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
203
290
  synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
@@ -205,16 +292,25 @@ declare class AzureTtsClient {
205
292
  }
206
293
 
207
294
  type MergeAudioFormat = "wav" | "mp3" | "raw";
295
+ interface MergeAudioOptions {
296
+ format: AzureTtsOutputFormat;
297
+ }
298
+ interface MergeSynthesisOptions extends MergeAudioOptions {
299
+ customMerger?: (buffers: ArrayBuffer[], format: string) => Promise<ArrayBuffer> | ArrayBuffer;
300
+ }
301
+ type AsyncMergeSynthesisOptions = MergeSynthesisOptions & {
302
+ customMerger: NonNullable<MergeSynthesisOptions["customMerger"]>;
303
+ };
208
304
  /** Returns whether the named output format can be safely concatenated without re-multiplexing. */
209
305
  declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | undefined;
210
306
  declare function canMergeAudioFormat(format: string): boolean;
211
307
  /** Merges audio buffers while preserving the invariants of supported containers. */
212
- declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], format: string): ArrayBuffer;
308
+ declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], options: MergeAudioOptions): ArrayBuffer;
213
309
  declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
214
310
  /** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
215
311
  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;
312
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: AsyncMergeSynthesisOptions): Promise<MergedSynthesisResult>;
313
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: MergeAudioOptions): MergedSynthesisResult;
218
314
  /** Backward-compatible audio-only synthesis helper. */
219
315
  declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
220
316
 
@@ -246,4 +342,4 @@ interface AzureVoiceCatalog {
246
342
  /** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
247
343
  declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
248
344
 
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 };
345
+ export { type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, type AzureTtsOutputFormat, AzureTtsSdkError, type AzureTtsSynthesisError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, ChunkValidationError, DEFAULT_OUTPUT_FORMAT, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type MergeAudioFormat, type MergeAudioOptions, MergeError, type MergeSynthesisOptions, type MergedSynthesisResult, type Result, 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, mergeAudioBuffers, mergeSynthesisResults, resolveMergeAudioFormat, resolveMimeType, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlChunksSafe, synthesizeSsmlSafe };
package/dist/index.d.ts 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.js';
2
- import { S as SsmlTextRange, a as SsmlDiagnostic, A as AzureValidationOptions } from './index.d-CUXRwSw0.js';
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, 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, validateSsml, validateSsmlStructureIntegrity } from './core.js';
2
+ import { S as SsmlTextRange, a as SsmlSourceTextSegment, b as SsmlSourceMarker, c as SsmlDiagnostic, A as AzureValidationOptions } from './index.d-8BvkB9gz.js';
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,9 @@ 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[];
21
70
  }
22
71
  type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
23
72
  interface SsmlSynthesisBoundary {
@@ -82,6 +131,11 @@ interface SsmlSynthesisResult {
82
131
  start: number;
83
132
  end: number;
84
133
  };
134
+ /** MIME type of a result produced by an explicit merge operation. */
135
+ mimeType?: string;
136
+ }
137
+ interface MergedSynthesisResult extends SsmlSynthesisResult {
138
+ mimeType: string;
85
139
  }
86
140
  interface SsmlSynthesisChunk {
87
141
  ssml: string;
@@ -90,9 +144,15 @@ interface SsmlSynthesisChunk {
90
144
  end: number;
91
145
  };
92
146
  sourceNodePath?: string[];
147
+ sourceTextSegments?: SsmlSourceTextSegment[];
148
+ sourceMarkers?: SsmlSourceMarker[];
93
149
  }
94
150
  interface SynthesizeChunksOptions {
95
151
  onProgress?: (event: SynthesisProgressEvent) => void;
152
+ outputFormat?: AzureTtsOutputFormat | string;
153
+ signal?: AbortSignal;
154
+ timeoutMs?: number;
155
+ sourceNodePath?: string[];
96
156
  }
97
157
  interface SynthesisProgressEvent {
98
158
  /** 1-based completed chunk count retained for backward compatibility. */
@@ -122,7 +182,9 @@ interface AzureTtsClientOptions {
122
182
  onProgress?: (event: SynthesisProgressEvent) => void;
123
183
  }
124
184
 
185
+ type SynthesisErrorKind = "validation-error" | "azure-api-error" | "merge-error" | "unsupported-format-error" | "cancelled" | "timeout";
125
186
  declare class AzureTtsError extends Error {
187
+ readonly kind: "azure-api-error";
126
188
  readonly status: number;
127
189
  readonly statusText: string;
128
190
  readonly responseBody: string;
@@ -133,19 +195,35 @@ declare class AzureTtsSdkError extends AzureTtsError {
133
195
  readonly errorDetails: string;
134
196
  constructor(errorDetails: string);
135
197
  }
198
+ declare class SynthesisCancelledError extends Error {
199
+ readonly kind: "cancelled";
200
+ constructor(message?: string);
201
+ }
202
+ declare class SynthesisTimeoutError extends Error {
203
+ readonly kind: "timeout";
204
+ constructor(message: string);
205
+ }
206
+ declare class MergeError extends Error {
207
+ readonly kind: "merge-error";
208
+ readonly cause: unknown;
209
+ constructor(message: string, cause?: unknown);
210
+ }
136
211
  /** Thrown when audio buffers require container re-multiplexing before they can be merged. */
137
212
  declare class UnsupportedMergeFormatError extends Error {
213
+ readonly kind: "unsupported-format-error";
138
214
  readonly format: string;
139
215
  constructor(format: string);
140
216
  }
217
+ type AzureTtsSynthesisError = AzureTtsError | MergeError | UnsupportedMergeFormatError | SynthesisCancelledError | SynthesisTimeoutError;
141
218
 
142
219
  interface SsmlValidationError {
143
- readonly kind: "validation";
220
+ readonly kind: "validation-error";
144
221
  readonly message: string;
145
222
  readonly diagnostics: readonly SsmlDiagnostic[];
146
223
  }
224
+ type SsmlSynthesisError = SsmlValidationError | AzureTtsSynthesisError;
147
225
  declare class ChunkValidationError extends Error {
148
- readonly kind: "chunk-validation";
226
+ readonly kind: "validation-error";
149
227
  readonly chunkIndex: number;
150
228
  readonly diagnostics: readonly SsmlDiagnostic[];
151
229
  constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
@@ -155,12 +233,19 @@ type Result<T, E> = {
155
233
  readonly success: true;
156
234
  readonly status: "success";
157
235
  readonly value: T;
158
- } | {
236
+ } | (E extends {
237
+ readonly kind: infer Kind extends SynthesisErrorKind;
238
+ } ? {
159
239
  readonly ok: false;
160
240
  readonly success: false;
161
- readonly status: "validation-error" | "azure-api-error";
241
+ readonly status: Kind;
162
242
  readonly error: E;
163
- };
243
+ } : {
244
+ readonly ok: false;
245
+ readonly success: false;
246
+ readonly status: SynthesisErrorKind;
247
+ readonly error: E;
248
+ });
164
249
  type SynthesisResult<T, E> = Result<T, E>;
165
250
  type Success<T> = Extract<Result<T, never>, {
166
251
  readonly ok: true;
@@ -171,22 +256,24 @@ type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
171
256
  type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
172
257
  readonly status: "azure-api-error";
173
258
  }>;
174
- type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
259
+ type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, SsmlSynthesisError>;
175
260
  interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
176
261
  /** Optional nested form for callers that want to keep validation settings grouped. */
177
262
  validation?: AzureValidationOptions;
263
+ signal?: AbortSignal;
178
264
  }
179
265
  interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
180
266
  validation?: AzureValidationOptions;
181
267
  outputFormat?: string;
268
+ signal?: AbortSignal;
269
+ timeoutMs?: number;
270
+ sourceNodePath?: string[];
182
271
  onProgress?: (event: SynthesisProgressEvent) => void;
183
272
  }
184
- type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, AzureTtsError>;
273
+ type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, SsmlSynthesisError | ChunkValidationError>;
185
274
  interface SynthesisClient {
186
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
187
- synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: {
188
- onProgress?: (event: SynthesisProgressEvent) => void;
189
- }): Promise<SsmlSynthesisResult>;
275
+ synthesizeSsml(ssml: string, options?: Partial<SynthesizeChunksOptions>): Promise<SsmlSynthesisResult>;
276
+ synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
190
277
  }
191
278
  /** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
192
279
  declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
@@ -197,7 +284,7 @@ declare class AzureTtsClient {
197
284
  #private;
198
285
  constructor(options: AzureTtsClientOptions);
199
286
  synthesize(ssml: string): Promise<ArrayBuffer>;
200
- synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
287
+ synthesizeSsml(ssml: string, options?: Partial<TtsConfig>): Promise<SsmlSynthesisResult>;
201
288
  synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
202
289
  synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
203
290
  synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
@@ -205,16 +292,25 @@ declare class AzureTtsClient {
205
292
  }
206
293
 
207
294
  type MergeAudioFormat = "wav" | "mp3" | "raw";
295
+ interface MergeAudioOptions {
296
+ format: AzureTtsOutputFormat;
297
+ }
298
+ interface MergeSynthesisOptions extends MergeAudioOptions {
299
+ customMerger?: (buffers: ArrayBuffer[], format: string) => Promise<ArrayBuffer> | ArrayBuffer;
300
+ }
301
+ type AsyncMergeSynthesisOptions = MergeSynthesisOptions & {
302
+ customMerger: NonNullable<MergeSynthesisOptions["customMerger"]>;
303
+ };
208
304
  /** Returns whether the named output format can be safely concatenated without re-multiplexing. */
209
305
  declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | undefined;
210
306
  declare function canMergeAudioFormat(format: string): boolean;
211
307
  /** Merges audio buffers while preserving the invariants of supported containers. */
212
- declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], format: string): ArrayBuffer;
308
+ declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], options: MergeAudioOptions): ArrayBuffer;
213
309
  declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
214
310
  /** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
215
311
  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;
312
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: AsyncMergeSynthesisOptions): Promise<MergedSynthesisResult>;
313
+ declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], options: MergeAudioOptions): MergedSynthesisResult;
218
314
  /** Backward-compatible audio-only synthesis helper. */
219
315
  declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
220
316
 
@@ -246,4 +342,4 @@ interface AzureVoiceCatalog {
246
342
  /** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
247
343
  declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
248
344
 
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 };
345
+ export { type AzureApiErrorResult, type SsmlValidationError as AzureSsmlValidationError, AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, type AzureTtsOutputFormat, AzureTtsSdkError, type AzureTtsSynthesisError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, ChunkValidationError, DEFAULT_OUTPUT_FORMAT, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type MergeAudioFormat, type MergeAudioOptions, MergeError, type MergeSynthesisOptions, type MergedSynthesisResult, type Result, 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, mergeAudioBuffers, mergeSynthesisResults, resolveMergeAudioFormat, resolveMimeType, synthesizeSpeech, synthesizeSsml, synthesizeSsmlChunks, synthesizeSsmlChunksSafe, synthesizeSsmlSafe };