@ssml-builder-js/azure-tts-client 2.12.0 → 2.14.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 +22 -0
- package/dist/index.d.mts +151 -1
- package/dist/index.d.ts +151 -1
- package/dist/index.js +485 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +475 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/client.ts +48 -2
- package/src/errors.ts +11 -0
- package/src/index.ts +26 -1
- package/src/safe.ts +200 -0
- package/src/synthesis.ts +349 -5
- package/src/types.ts +60 -0
- package/src/voiceCatalog.ts +15 -0
- package/test/v213-pipeline.test.ts +72 -0
- package/test/v214-pipeline.test.ts +110 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @ssml-builder-js/azure-tts-client
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add safe container-aware audio merging, preflight-validated SSML chunk synthesis with structured progress events, source mapping metadata, controlled URL validation, and voice capability details in the Visual Editor.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @ssml-builder-js/ssml-core@2.14.0
|
|
13
|
+
|
|
14
|
+
## 2.13.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- Add structured SSML chunk metadata and background-audio replication policies, merged synthesis synchronization offsets, safe preflight synthesis with custom URL validation, chunk progress reporting, source tracking, and extensible Japanese-localized Visual Editor controls.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
- @ssml-builder-js/ssml-core@2.13.0
|
|
24
|
+
|
|
3
25
|
## 2.12.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SsmlTextRange, SsmlDiagnostic, AzureValidationOptions } from '@ssml-builder-js/ssml-core';
|
|
2
|
+
|
|
1
3
|
interface TtsConfig {
|
|
2
4
|
signal?: AbortSignal;
|
|
3
5
|
timeoutMs?: number;
|
|
@@ -5,19 +7,61 @@ interface TtsConfig {
|
|
|
5
7
|
subscriptionKey: string;
|
|
6
8
|
region: string;
|
|
7
9
|
outputFormat?: string;
|
|
10
|
+
/** Original plain-text range represented by this synthesis request. */
|
|
11
|
+
sourceTextRange?: {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
};
|
|
15
|
+
/** Reports chunk lifecycle events when using chunk synthesis. */
|
|
16
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
17
|
+
/** Metadata used to map synchronization events back to the source document. */
|
|
18
|
+
chunkIndex?: number;
|
|
19
|
+
sourceNodePath?: string[];
|
|
8
20
|
}
|
|
21
|
+
type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
|
|
9
22
|
interface SsmlSynthesisBoundary {
|
|
10
23
|
text: string;
|
|
11
24
|
audioOffsetMs: number;
|
|
12
25
|
durationMs: number;
|
|
26
|
+
textRange?: {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
};
|
|
30
|
+
/** Chunk that produced this event. */
|
|
31
|
+
chunkIndex?: number;
|
|
32
|
+
/** Path of the source SSML node, when available. */
|
|
33
|
+
sourceNodePath?: string[];
|
|
34
|
+
/** Original text range represented by this event. */
|
|
35
|
+
originalTextRange?: SsmlTextRange;
|
|
36
|
+
/** Audio offset within the originating chunk before merge. */
|
|
37
|
+
chunkAudioOffsetMs?: number;
|
|
38
|
+
requestId?: string;
|
|
13
39
|
}
|
|
14
40
|
interface SsmlSynthesisViseme {
|
|
15
41
|
visemeId: number;
|
|
16
42
|
audioOffsetMs: number;
|
|
43
|
+
textRange?: {
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
};
|
|
47
|
+
chunkIndex?: number;
|
|
48
|
+
sourceNodePath?: string[];
|
|
49
|
+
originalTextRange?: SsmlTextRange;
|
|
50
|
+
chunkAudioOffsetMs?: number;
|
|
51
|
+
requestId?: string;
|
|
17
52
|
}
|
|
18
53
|
interface SsmlSynthesisBookmark {
|
|
19
54
|
name: string;
|
|
20
55
|
audioOffsetMs: number;
|
|
56
|
+
textRange?: {
|
|
57
|
+
start: number;
|
|
58
|
+
end: number;
|
|
59
|
+
};
|
|
60
|
+
chunkIndex?: number;
|
|
61
|
+
sourceNodePath?: string[];
|
|
62
|
+
originalTextRange?: SsmlTextRange;
|
|
63
|
+
chunkAudioOffsetMs?: number;
|
|
64
|
+
requestId?: string;
|
|
21
65
|
}
|
|
22
66
|
/** Audio and Azure Speech synchronization events emitted for one SSML request. */
|
|
23
67
|
interface SsmlSynthesisResult {
|
|
@@ -30,6 +74,35 @@ interface SsmlSynthesisResult {
|
|
|
30
74
|
wordBoundaries?: SsmlSynthesisBoundary[];
|
|
31
75
|
visemes?: SsmlSynthesisViseme[];
|
|
32
76
|
bookmarks?: SsmlSynthesisBookmark[];
|
|
77
|
+
/** Request identifier returned by Azure Speech, when available. */
|
|
78
|
+
requestId?: string;
|
|
79
|
+
/** Original plain-text range represented by the result. */
|
|
80
|
+
textRange?: {
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
interface SsmlSynthesisChunk {
|
|
86
|
+
ssml: string;
|
|
87
|
+
originalTextRange?: {
|
|
88
|
+
start: number;
|
|
89
|
+
end: number;
|
|
90
|
+
};
|
|
91
|
+
sourceNodePath?: string[];
|
|
92
|
+
}
|
|
93
|
+
interface SynthesizeChunksOptions {
|
|
94
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
95
|
+
}
|
|
96
|
+
interface SynthesisProgressEvent {
|
|
97
|
+
/** 1-based completed chunk count retained for backward compatibility. */
|
|
98
|
+
currentChunk: number;
|
|
99
|
+
totalChunks: number;
|
|
100
|
+
percent: number;
|
|
101
|
+
chunkIndex: number;
|
|
102
|
+
originalTextRange?: SsmlTextRange;
|
|
103
|
+
status: SynthesisChunkStatus;
|
|
104
|
+
durationMs: number;
|
|
105
|
+
error?: unknown;
|
|
33
106
|
}
|
|
34
107
|
interface AzureTtsLogger {
|
|
35
108
|
debug?: (...args: unknown[]) => void;
|
|
@@ -45,6 +118,7 @@ interface AzureTtsClientOptions {
|
|
|
45
118
|
endpoint?: string;
|
|
46
119
|
outputFormat?: string;
|
|
47
120
|
logger?: AzureTtsLogger;
|
|
121
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
48
122
|
}
|
|
49
123
|
|
|
50
124
|
declare class AzureTtsError extends Error {
|
|
@@ -58,15 +132,88 @@ declare class AzureTtsSdkError extends AzureTtsError {
|
|
|
58
132
|
readonly errorDetails: string;
|
|
59
133
|
constructor(errorDetails: string);
|
|
60
134
|
}
|
|
135
|
+
/** Thrown when audio buffers require container re-multiplexing before they can be merged. */
|
|
136
|
+
declare class UnsupportedMergeFormatError extends Error {
|
|
137
|
+
readonly format: string;
|
|
138
|
+
constructor(format: string);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface SsmlValidationError {
|
|
142
|
+
readonly kind: "validation";
|
|
143
|
+
readonly message: string;
|
|
144
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
145
|
+
}
|
|
146
|
+
declare class ChunkValidationError extends Error {
|
|
147
|
+
readonly kind: "chunk-validation";
|
|
148
|
+
readonly chunkIndex: number;
|
|
149
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
150
|
+
constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
|
|
151
|
+
}
|
|
152
|
+
type Result<T, E> = {
|
|
153
|
+
readonly ok: true;
|
|
154
|
+
readonly success: true;
|
|
155
|
+
readonly status: "success";
|
|
156
|
+
readonly value: T;
|
|
157
|
+
} | {
|
|
158
|
+
readonly ok: false;
|
|
159
|
+
readonly success: false;
|
|
160
|
+
readonly status: "validation-error" | "azure-api-error";
|
|
161
|
+
readonly error: E;
|
|
162
|
+
};
|
|
163
|
+
type SynthesisResult<T, E> = Result<T, E>;
|
|
164
|
+
type Success<T> = Extract<Result<T, never>, {
|
|
165
|
+
readonly ok: true;
|
|
166
|
+
}>;
|
|
167
|
+
type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
|
|
168
|
+
readonly status: "validation-error";
|
|
169
|
+
}>;
|
|
170
|
+
type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
|
|
171
|
+
readonly status: "azure-api-error";
|
|
172
|
+
}>;
|
|
173
|
+
type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
|
|
174
|
+
interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
|
|
175
|
+
/** Optional nested form for callers that want to keep validation settings grouped. */
|
|
176
|
+
validation?: AzureValidationOptions;
|
|
177
|
+
}
|
|
178
|
+
interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
|
|
179
|
+
validation?: AzureValidationOptions;
|
|
180
|
+
outputFormat?: string;
|
|
181
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
182
|
+
}
|
|
183
|
+
type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, AzureTtsError>;
|
|
184
|
+
interface SynthesisClient {
|
|
185
|
+
synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
|
|
186
|
+
synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: {
|
|
187
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
188
|
+
}): Promise<SsmlSynthesisResult>;
|
|
189
|
+
}
|
|
190
|
+
/** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
|
|
191
|
+
declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
192
|
+
/** Validates every chunk before synthesis and returns a chunk-addressable result. */
|
|
193
|
+
declare function synthesizeSsmlChunksSafe(client: Pick<AzureTtsClient, "synthesizeSsml" | "synthesizeChunks"> | SynthesisClient, chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
61
194
|
|
|
62
195
|
declare class AzureTtsClient {
|
|
63
196
|
#private;
|
|
64
197
|
constructor(options: AzureTtsClientOptions);
|
|
65
198
|
synthesize(ssml: string): Promise<ArrayBuffer>;
|
|
66
199
|
synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
|
|
200
|
+
synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
201
|
+
synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
202
|
+
synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
203
|
+
synthesizeSsmlChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
67
204
|
}
|
|
68
205
|
|
|
206
|
+
type MergeAudioFormat = "wav" | "mp3" | "raw";
|
|
207
|
+
/** Returns whether the named output format can be safely concatenated without re-multiplexing. */
|
|
208
|
+
declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | undefined;
|
|
209
|
+
declare function canMergeAudioFormat(format: string): boolean;
|
|
210
|
+
/** Merges audio buffers while preserving the invariants of supported containers. */
|
|
211
|
+
declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], format: string): ArrayBuffer;
|
|
69
212
|
declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
213
|
+
/** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
|
|
214
|
+
declare function synthesizeSsmlChunks(chunks: readonly (SsmlSynthesisChunk | string)[], config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
215
|
+
/** Concatenates audio buffers and shifts all synchronization events by prior chunk durations. */
|
|
216
|
+
declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], format?: string): SsmlSynthesisResult;
|
|
70
217
|
/** Backward-compatible audio-only synthesis helper. */
|
|
71
218
|
declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
|
|
72
219
|
|
|
@@ -79,6 +226,9 @@ interface AzureVoiceCatalogVoice {
|
|
|
79
226
|
locale: string;
|
|
80
227
|
secondaryLocales?: readonly string[];
|
|
81
228
|
styles?: readonly string[];
|
|
229
|
+
supportedTags?: readonly string[];
|
|
230
|
+
unsupportedTags?: readonly string[];
|
|
231
|
+
models?: readonly string[];
|
|
82
232
|
regions: readonly string[];
|
|
83
233
|
status?: "ga" | "preview" | "deprecated";
|
|
84
234
|
}
|
|
@@ -95,4 +245,4 @@ interface AzureVoiceCatalog {
|
|
|
95
245
|
/** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
|
|
96
246
|
declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
|
|
97
247
|
|
|
98
|
-
export { AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, AzureTtsSdkError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisResult, type SsmlSynthesisViseme, type TtsConfig, fetchAzureVoiceCatalog, synthesizeSpeech, synthesizeSsml };
|
|
248
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SsmlTextRange, SsmlDiagnostic, AzureValidationOptions } from '@ssml-builder-js/ssml-core';
|
|
2
|
+
|
|
1
3
|
interface TtsConfig {
|
|
2
4
|
signal?: AbortSignal;
|
|
3
5
|
timeoutMs?: number;
|
|
@@ -5,19 +7,61 @@ interface TtsConfig {
|
|
|
5
7
|
subscriptionKey: string;
|
|
6
8
|
region: string;
|
|
7
9
|
outputFormat?: string;
|
|
10
|
+
/** Original plain-text range represented by this synthesis request. */
|
|
11
|
+
sourceTextRange?: {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
};
|
|
15
|
+
/** Reports chunk lifecycle events when using chunk synthesis. */
|
|
16
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
17
|
+
/** Metadata used to map synchronization events back to the source document. */
|
|
18
|
+
chunkIndex?: number;
|
|
19
|
+
sourceNodePath?: string[];
|
|
8
20
|
}
|
|
21
|
+
type SynthesisChunkStatus = "pending" | "synthesizing" | "success" | "failed";
|
|
9
22
|
interface SsmlSynthesisBoundary {
|
|
10
23
|
text: string;
|
|
11
24
|
audioOffsetMs: number;
|
|
12
25
|
durationMs: number;
|
|
26
|
+
textRange?: {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
};
|
|
30
|
+
/** Chunk that produced this event. */
|
|
31
|
+
chunkIndex?: number;
|
|
32
|
+
/** Path of the source SSML node, when available. */
|
|
33
|
+
sourceNodePath?: string[];
|
|
34
|
+
/** Original text range represented by this event. */
|
|
35
|
+
originalTextRange?: SsmlTextRange;
|
|
36
|
+
/** Audio offset within the originating chunk before merge. */
|
|
37
|
+
chunkAudioOffsetMs?: number;
|
|
38
|
+
requestId?: string;
|
|
13
39
|
}
|
|
14
40
|
interface SsmlSynthesisViseme {
|
|
15
41
|
visemeId: number;
|
|
16
42
|
audioOffsetMs: number;
|
|
43
|
+
textRange?: {
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
};
|
|
47
|
+
chunkIndex?: number;
|
|
48
|
+
sourceNodePath?: string[];
|
|
49
|
+
originalTextRange?: SsmlTextRange;
|
|
50
|
+
chunkAudioOffsetMs?: number;
|
|
51
|
+
requestId?: string;
|
|
17
52
|
}
|
|
18
53
|
interface SsmlSynthesisBookmark {
|
|
19
54
|
name: string;
|
|
20
55
|
audioOffsetMs: number;
|
|
56
|
+
textRange?: {
|
|
57
|
+
start: number;
|
|
58
|
+
end: number;
|
|
59
|
+
};
|
|
60
|
+
chunkIndex?: number;
|
|
61
|
+
sourceNodePath?: string[];
|
|
62
|
+
originalTextRange?: SsmlTextRange;
|
|
63
|
+
chunkAudioOffsetMs?: number;
|
|
64
|
+
requestId?: string;
|
|
21
65
|
}
|
|
22
66
|
/** Audio and Azure Speech synchronization events emitted for one SSML request. */
|
|
23
67
|
interface SsmlSynthesisResult {
|
|
@@ -30,6 +74,35 @@ interface SsmlSynthesisResult {
|
|
|
30
74
|
wordBoundaries?: SsmlSynthesisBoundary[];
|
|
31
75
|
visemes?: SsmlSynthesisViseme[];
|
|
32
76
|
bookmarks?: SsmlSynthesisBookmark[];
|
|
77
|
+
/** Request identifier returned by Azure Speech, when available. */
|
|
78
|
+
requestId?: string;
|
|
79
|
+
/** Original plain-text range represented by the result. */
|
|
80
|
+
textRange?: {
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
interface SsmlSynthesisChunk {
|
|
86
|
+
ssml: string;
|
|
87
|
+
originalTextRange?: {
|
|
88
|
+
start: number;
|
|
89
|
+
end: number;
|
|
90
|
+
};
|
|
91
|
+
sourceNodePath?: string[];
|
|
92
|
+
}
|
|
93
|
+
interface SynthesizeChunksOptions {
|
|
94
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
95
|
+
}
|
|
96
|
+
interface SynthesisProgressEvent {
|
|
97
|
+
/** 1-based completed chunk count retained for backward compatibility. */
|
|
98
|
+
currentChunk: number;
|
|
99
|
+
totalChunks: number;
|
|
100
|
+
percent: number;
|
|
101
|
+
chunkIndex: number;
|
|
102
|
+
originalTextRange?: SsmlTextRange;
|
|
103
|
+
status: SynthesisChunkStatus;
|
|
104
|
+
durationMs: number;
|
|
105
|
+
error?: unknown;
|
|
33
106
|
}
|
|
34
107
|
interface AzureTtsLogger {
|
|
35
108
|
debug?: (...args: unknown[]) => void;
|
|
@@ -45,6 +118,7 @@ interface AzureTtsClientOptions {
|
|
|
45
118
|
endpoint?: string;
|
|
46
119
|
outputFormat?: string;
|
|
47
120
|
logger?: AzureTtsLogger;
|
|
121
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
48
122
|
}
|
|
49
123
|
|
|
50
124
|
declare class AzureTtsError extends Error {
|
|
@@ -58,15 +132,88 @@ declare class AzureTtsSdkError extends AzureTtsError {
|
|
|
58
132
|
readonly errorDetails: string;
|
|
59
133
|
constructor(errorDetails: string);
|
|
60
134
|
}
|
|
135
|
+
/** Thrown when audio buffers require container re-multiplexing before they can be merged. */
|
|
136
|
+
declare class UnsupportedMergeFormatError extends Error {
|
|
137
|
+
readonly format: string;
|
|
138
|
+
constructor(format: string);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface SsmlValidationError {
|
|
142
|
+
readonly kind: "validation";
|
|
143
|
+
readonly message: string;
|
|
144
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
145
|
+
}
|
|
146
|
+
declare class ChunkValidationError extends Error {
|
|
147
|
+
readonly kind: "chunk-validation";
|
|
148
|
+
readonly chunkIndex: number;
|
|
149
|
+
readonly diagnostics: readonly SsmlDiagnostic[];
|
|
150
|
+
constructor(chunkIndex: number, diagnostics: readonly SsmlDiagnostic[]);
|
|
151
|
+
}
|
|
152
|
+
type Result<T, E> = {
|
|
153
|
+
readonly ok: true;
|
|
154
|
+
readonly success: true;
|
|
155
|
+
readonly status: "success";
|
|
156
|
+
readonly value: T;
|
|
157
|
+
} | {
|
|
158
|
+
readonly ok: false;
|
|
159
|
+
readonly success: false;
|
|
160
|
+
readonly status: "validation-error" | "azure-api-error";
|
|
161
|
+
readonly error: E;
|
|
162
|
+
};
|
|
163
|
+
type SynthesisResult<T, E> = Result<T, E>;
|
|
164
|
+
type Success<T> = Extract<Result<T, never>, {
|
|
165
|
+
readonly ok: true;
|
|
166
|
+
}>;
|
|
167
|
+
type ValidationErrorResult = Extract<Result<never, SsmlValidationError>, {
|
|
168
|
+
readonly status: "validation-error";
|
|
169
|
+
}>;
|
|
170
|
+
type AzureApiErrorResult = Extract<Result<never, AzureTtsError>, {
|
|
171
|
+
readonly status: "azure-api-error";
|
|
172
|
+
}>;
|
|
173
|
+
type SsmlSynthesisSafeResult = Result<SsmlSynthesisResult, never> | Result<never, SsmlValidationError> | Result<never, AzureTtsError>;
|
|
174
|
+
interface SynthesizeSsmlSafeOptions extends AzureValidationOptions {
|
|
175
|
+
/** Optional nested form for callers that want to keep validation settings grouped. */
|
|
176
|
+
validation?: AzureValidationOptions;
|
|
177
|
+
}
|
|
178
|
+
interface SynthesizeSsmlChunksSafeOptions extends AzureValidationOptions {
|
|
179
|
+
validation?: AzureValidationOptions;
|
|
180
|
+
outputFormat?: string;
|
|
181
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
182
|
+
}
|
|
183
|
+
type SsmlSynthesisChunksSafeResult = Result<SsmlSynthesisResult, never> | Result<never, ChunkValidationError> | Result<never, AzureTtsError>;
|
|
184
|
+
interface SynthesisClient {
|
|
185
|
+
synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
|
|
186
|
+
synthesizeChunks?(chunks: readonly (SsmlSynthesisChunk | string)[], options?: {
|
|
187
|
+
onProgress?: (event: SynthesisProgressEvent) => void;
|
|
188
|
+
}): Promise<SsmlSynthesisResult>;
|
|
189
|
+
}
|
|
190
|
+
/** Validates SSML before invoking Azure and converts validation/API failures to one result shape. */
|
|
191
|
+
declare function synthesizeSsmlSafe(client: Pick<AzureTtsClient, "synthesizeSsml"> | SynthesisClient, ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
192
|
+
/** Validates every chunk before synthesis and returns a chunk-addressable result. */
|
|
193
|
+
declare function synthesizeSsmlChunksSafe(client: Pick<AzureTtsClient, "synthesizeSsml" | "synthesizeChunks"> | SynthesisClient, chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
61
194
|
|
|
62
195
|
declare class AzureTtsClient {
|
|
63
196
|
#private;
|
|
64
197
|
constructor(options: AzureTtsClientOptions);
|
|
65
198
|
synthesize(ssml: string): Promise<ArrayBuffer>;
|
|
66
199
|
synthesizeSsml(ssml: string): Promise<SsmlSynthesisResult>;
|
|
200
|
+
synthesizeChunks(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeChunksOptions): Promise<SsmlSynthesisResult>;
|
|
201
|
+
synthesizeSsmlSafe(ssml: string, options?: SynthesizeSsmlSafeOptions): Promise<SsmlSynthesisSafeResult>;
|
|
202
|
+
synthesizeChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
203
|
+
synthesizeSsmlChunksSafe(chunks: readonly (SsmlSynthesisChunk | string)[], options?: SynthesizeSsmlChunksSafeOptions): Promise<SsmlSynthesisChunksSafeResult>;
|
|
67
204
|
}
|
|
68
205
|
|
|
206
|
+
type MergeAudioFormat = "wav" | "mp3" | "raw";
|
|
207
|
+
/** Returns whether the named output format can be safely concatenated without re-multiplexing. */
|
|
208
|
+
declare function resolveMergeAudioFormat(format: string): MergeAudioFormat | undefined;
|
|
209
|
+
declare function canMergeAudioFormat(format: string): boolean;
|
|
210
|
+
/** Merges audio buffers while preserving the invariants of supported containers. */
|
|
211
|
+
declare function mergeAudioBuffers(buffers: readonly ArrayBuffer[], format: string): ArrayBuffer;
|
|
69
212
|
declare function synthesizeSsml(ssml: string, config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
213
|
+
/** Synthesizes chunks sequentially, annotates synchronization events, and merges the results. */
|
|
214
|
+
declare function synthesizeSsmlChunks(chunks: readonly (SsmlSynthesisChunk | string)[], config: TtsConfig): Promise<SsmlSynthesisResult>;
|
|
215
|
+
/** Concatenates audio buffers and shifts all synchronization events by prior chunk durations. */
|
|
216
|
+
declare function mergeSynthesisResults(results: readonly SsmlSynthesisResult[], format?: string): SsmlSynthesisResult;
|
|
70
217
|
/** Backward-compatible audio-only synthesis helper. */
|
|
71
218
|
declare function synthesizeSpeech(ssml: string, config: TtsConfig): Promise<ArrayBuffer>;
|
|
72
219
|
|
|
@@ -79,6 +226,9 @@ interface AzureVoiceCatalogVoice {
|
|
|
79
226
|
locale: string;
|
|
80
227
|
secondaryLocales?: readonly string[];
|
|
81
228
|
styles?: readonly string[];
|
|
229
|
+
supportedTags?: readonly string[];
|
|
230
|
+
unsupportedTags?: readonly string[];
|
|
231
|
+
models?: readonly string[];
|
|
82
232
|
regions: readonly string[];
|
|
83
233
|
status?: "ga" | "preview" | "deprecated";
|
|
84
234
|
}
|
|
@@ -95,4 +245,4 @@ interface AzureVoiceCatalog {
|
|
|
95
245
|
/** Fetches and deduplicates the current Azure Speech voice catalog for one or more regions. */
|
|
96
246
|
declare function fetchAzureVoiceCatalog(options: FetchAzureVoiceCatalogOptions): Promise<AzureVoiceCatalog>;
|
|
97
247
|
|
|
98
|
-
export { AzureTtsClient, type AzureTtsClientOptions, AzureTtsError, type AzureTtsLogger, AzureTtsSdkError, type AzureVoiceCatalog, type AzureVoiceCatalogVoice, type FetchAzureVoiceCatalogOptions, type FetchedAzureVoiceCatalogMetadata, type SsmlSynthesisBookmark, type SsmlSynthesisBoundary, type SsmlSynthesisResult, type SsmlSynthesisViseme, type TtsConfig, fetchAzureVoiceCatalog, synthesizeSpeech, synthesizeSsml };
|
|
248
|
+
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 };
|