@ssml-builder-js/azure-tts-client 2.19.0 → 2.19.1
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 +8 -0
- package/LICENSE +21 -0
- package/package.json +8 -8
- package/test/synthesis.test.ts +20 -0
- package/test/v219-pipeline.test.ts +136 -2
- package/dist/index.d.mts +0 -538
- package/dist/index.d.ts +0 -538
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2200
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @ssml-builder-js/azure-tts-client
|
|
2
2
|
|
|
3
|
+
## 2.19.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix vulnerable transitive dependency resolution and update the playground to a secure Next.js patch release.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @ssml-builder-js/ssml-core@2.19.1
|
|
10
|
+
|
|
3
11
|
## 2.19.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 nitta-a
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssml-builder-js/azure-tts-client",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.1",
|
|
4
4
|
"description": "Azure Text-to-Speech client using the Microsoft Speech SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"access": "public",
|
|
27
27
|
"registry": "https://registry.npmjs.org/"
|
|
28
28
|
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "tsup",
|
|
31
|
-
"typecheck": "tsc --noEmit",
|
|
32
|
-
"test": "node --experimental-strip-types --test test/*.test.ts"
|
|
33
|
-
},
|
|
34
29
|
"devDependencies": {
|
|
35
30
|
"typescript": "^6.0.3"
|
|
36
31
|
},
|
|
37
32
|
"dependencies": {
|
|
38
|
-
"@ssml-builder-js/ssml-core": "^2.19.
|
|
33
|
+
"@ssml-builder-js/ssml-core": "^2.19.1",
|
|
39
34
|
"microsoft-cognitiveservices-speech-sdk": "1.51.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"test": "node --experimental-strip-types --test test/*.test.ts"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
package/test/synthesis.test.ts
CHANGED
|
@@ -181,6 +181,26 @@ test("synthesizeSpeech aborts the SDK request on timeout and settles its promise
|
|
|
181
181
|
assert.equal(closeCount, 1);
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
+
test("synthesizeSsml enforces totalJobMs across the SDK request", async (t) => {
|
|
185
|
+
let closeCount = 0;
|
|
186
|
+
installHangingSynthesisMock(
|
|
187
|
+
t,
|
|
188
|
+
() => undefined,
|
|
189
|
+
() => (closeCount += 1),
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
await assert.rejects(
|
|
193
|
+
synthesizeSsml("<speak>Hello</speak>", {
|
|
194
|
+
endpoint,
|
|
195
|
+
subscriptionKey,
|
|
196
|
+
region,
|
|
197
|
+
timeouts: { totalJobMs: 10 },
|
|
198
|
+
}),
|
|
199
|
+
/exceeded the total job deadline/,
|
|
200
|
+
);
|
|
201
|
+
assert.equal(closeCount, 1);
|
|
202
|
+
});
|
|
203
|
+
|
|
184
204
|
const azureKey = process.env.AZURE_SPEECH_KEY;
|
|
185
205
|
const azureRegion = process.env.AZURE_SPEECH_REGION;
|
|
186
206
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import {
|
|
4
|
+
AudioFormatMismatchError,
|
|
5
|
+
AzureTtsError,
|
|
6
|
+
AzureTtsClient,
|
|
7
|
+
DeadlineController,
|
|
4
8
|
IncompleteChunkSetError,
|
|
5
9
|
inspectAudioSpecification,
|
|
10
|
+
serializeChunkError,
|
|
6
11
|
synthesizeSsmlChunksSafe,
|
|
7
12
|
synthesizeSsmlSafe,
|
|
8
13
|
computeChunkFingerprint,
|
|
@@ -88,6 +93,69 @@ test("fingerprints include the complete synthesis environment", () => {
|
|
|
88
93
|
);
|
|
89
94
|
});
|
|
90
95
|
|
|
96
|
+
test("fingerprints canonicalize headers and support explicit voice and language inputs", () => {
|
|
97
|
+
const options = {
|
|
98
|
+
region: "eastus",
|
|
99
|
+
endpoint: "https://eastus.example.test/tts",
|
|
100
|
+
customHeaders: { "x-tenant": "a", "x-request": "b" },
|
|
101
|
+
voice: "en-US-JennyNeural",
|
|
102
|
+
lang: "en-US",
|
|
103
|
+
schemaVersion: "legacy",
|
|
104
|
+
} as const;
|
|
105
|
+
assert.equal(
|
|
106
|
+
computeChunkFingerprint(validSsml("hello"), "audio-16khz-128kbitrate-mono-mp3", options),
|
|
107
|
+
computeChunkFingerprint(validSsml("hello"), "audio-16khz-128kbitrate-mono-mp3", {
|
|
108
|
+
...options,
|
|
109
|
+
customHeaders: { "x-request": "b", "x-tenant": "a" },
|
|
110
|
+
fingerprintSchemaVersion: "legacy",
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
assert.notEqual(
|
|
114
|
+
computeChunkFingerprint(validSsml("hello"), "audio-16khz-128kbitrate-mono-mp3", options),
|
|
115
|
+
computeChunkFingerprint(validSsml("hello"), "audio-16khz-128kbitrate-mono-mp3", {
|
|
116
|
+
...options,
|
|
117
|
+
voice: "en-US-AriaNeural",
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("serializes synthesis failures with stable codes and retry metadata", () => {
|
|
123
|
+
const retryable = serializeChunkError(
|
|
124
|
+
new AzureTtsError(503, "Service Unavailable", "", "request-1"),
|
|
125
|
+
"synthesis",
|
|
126
|
+
true,
|
|
127
|
+
);
|
|
128
|
+
assert.deepEqual(retryable, {
|
|
129
|
+
code: "AZURE_API_ERROR",
|
|
130
|
+
phase: "synthesis",
|
|
131
|
+
message: "Azure TTS request failed: 503 Service Unavailable",
|
|
132
|
+
isOriginalFailure: true,
|
|
133
|
+
isRetryable: true,
|
|
134
|
+
httpStatus: 503,
|
|
135
|
+
details: { statusText: "Service Unavailable", requestId: "request-1" },
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const incomplete = serializeChunkError(new IncompleteChunkSetError(3, [1, 2]), "merge", false);
|
|
139
|
+
assert.equal(incomplete.code, "MERGE_ERROR");
|
|
140
|
+
assert.equal(incomplete.isRetryable, false);
|
|
141
|
+
assert.deepEqual(incomplete.details, { totalChunks: 3, missingChunkIndices: [1, 2] });
|
|
142
|
+
assert.equal(serializeChunkError(new Error("request aborted"), "synthesis", false).code, "CANCELLED");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("DeadlineController distinguishes cancellation from expiry and cleans up", async () => {
|
|
146
|
+
const cancelled = new DeadlineController(1_000);
|
|
147
|
+
cancelled.abort();
|
|
148
|
+
assert.equal(cancelled.signal.aborted, true);
|
|
149
|
+
assert.throws(() => cancelled.throwIfExpired(), /cancelled/);
|
|
150
|
+
cancelled.dispose();
|
|
151
|
+
|
|
152
|
+
const expired = new DeadlineController(5);
|
|
153
|
+
await new Promise((resolve) => setTimeout(resolve, 15));
|
|
154
|
+
assert.equal(expired.timedOut, true);
|
|
155
|
+
assert.throws(() => expired.throwIfExpired(), /total job deadline/);
|
|
156
|
+
expired.dispose();
|
|
157
|
+
});
|
|
158
|
+
|
|
91
159
|
test("refuses to merge when resumeChunkIndices leave a chunk missing", async () => {
|
|
92
160
|
const fingerprint = computeChunkFingerprint(validSsml("one"));
|
|
93
161
|
const result = await synthesizeSsmlChunksSafe(
|
|
@@ -121,11 +189,77 @@ test("applies totalJobMs to one safe synthesis before the client resolves", asyn
|
|
|
121
189
|
if (!result.ok) assert.equal(result.error.kind, "timeout");
|
|
122
190
|
});
|
|
123
191
|
|
|
192
|
+
test("forwards v2.19 synthesis options through the safe chunk client path", async () => {
|
|
193
|
+
let received: Record<string, unknown> | undefined;
|
|
194
|
+
const result = await synthesizeSsmlChunksSafe(
|
|
195
|
+
{
|
|
196
|
+
synthesizeSsml: async () => ({ audioData: Uint8Array.of(1).buffer, durationMs: 1 }),
|
|
197
|
+
synthesizeChunks: async (_chunks, options) => {
|
|
198
|
+
received = options as Record<string, unknown>;
|
|
199
|
+
return { audioData: Uint8Array.of(2).buffer, durationMs: 2 };
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
[validSsml("chunk")],
|
|
203
|
+
{
|
|
204
|
+
customHeaders: { "x-tenant": "a" },
|
|
205
|
+
fingerprintSchemaVersion: "3",
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
assert.equal(result.ok, true);
|
|
209
|
+
assert.deepEqual(received?.customHeaders, { "x-tenant": "a" });
|
|
210
|
+
assert.equal(received?.fingerprintSchemaVersion, "3");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("AzureTtsClient includes default fingerprint settings when resuming chunks", async () => {
|
|
214
|
+
const ssml = validSsml("cached");
|
|
215
|
+
const headers = { "x-tenant": "a" };
|
|
216
|
+
const endpoint = "https://eastus.example.test/tts";
|
|
217
|
+
const cached = {
|
|
218
|
+
chunkIndex: 0,
|
|
219
|
+
fingerprint: computeChunkFingerprint(ssml, undefined, {
|
|
220
|
+
region: "eastus",
|
|
221
|
+
endpoint,
|
|
222
|
+
customHeaders: headers,
|
|
223
|
+
}),
|
|
224
|
+
audioData: new ArrayBuffer(0),
|
|
225
|
+
durationMs: 1,
|
|
226
|
+
};
|
|
227
|
+
const result = await new AzureTtsClient({
|
|
228
|
+
subscriptionKey: "subscription-key",
|
|
229
|
+
region: "eastus",
|
|
230
|
+
endpoint,
|
|
231
|
+
customHeaders: headers,
|
|
232
|
+
}).synthesizeChunks([ssml], { resumeChunks: [cached] });
|
|
233
|
+
|
|
234
|
+
assert.equal(result.durationMs, 1);
|
|
235
|
+
assert.equal(result.audioData.byteLength, 0);
|
|
236
|
+
});
|
|
237
|
+
|
|
124
238
|
test("validates Ogg and WebM codec headers", () => {
|
|
125
|
-
|
|
126
|
-
assert.
|
|
239
|
+
const ogg = inspectAudioSpecification(oggOpus(), "ogg-16khz-16bit-mono-opus");
|
|
240
|
+
assert.deepEqual(
|
|
241
|
+
{ codec: ogg.codec, sampleRate: ogg.sampleRate, channels: ogg.channels, container: ogg.container },
|
|
242
|
+
{ codec: "opus", sampleRate: 16_000, channels: 1, container: "ogg" },
|
|
243
|
+
);
|
|
244
|
+
const webm = inspectAudioSpecification(webmOpus(), "webm-24khz-16bit-mono-opus");
|
|
245
|
+
assert.deepEqual(
|
|
246
|
+
{ codec: webm.codec, sampleRate: webm.sampleRate, channels: webm.channels, mimeType: webm.mimeType },
|
|
247
|
+
{ codec: "opus", sampleRate: 24_000, channels: 1, mimeType: "audio/webm" },
|
|
248
|
+
);
|
|
127
249
|
assert.throws(() =>
|
|
128
250
|
inspectAudioSpecification(Uint8Array.of(0x4f, 0x67, 0x67, 0x53).buffer, "ogg-16khz-16bit-mono-opus"),
|
|
129
251
|
);
|
|
130
252
|
assert.throws(() => inspectAudioSpecification(Uint8Array.of(0x1a, 0x45, 0xdf).buffer, "webm-24khz-16bit-mono-opus"));
|
|
253
|
+
assert.throws(
|
|
254
|
+
() => inspectAudioSpecification(oggOpus(), "ogg-24khz-16bit-mono-opus"),
|
|
255
|
+
(error: unknown) => error instanceof AudioFormatMismatchError,
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test("validates RAW SILK and Opus framing headers", () => {
|
|
260
|
+
const silk = Uint8Array.from([...new TextEncoder().encode("#!SILK_V3"), 0x0a]).buffer;
|
|
261
|
+
assert.equal(inspectAudioSpecification(silk, "raw-16khz-16bit-mono-silk").codec, "silk");
|
|
262
|
+
assert.throws(() => inspectAudioSpecification(new ArrayBuffer(10), "raw-16khz-16bit-mono-silk"));
|
|
263
|
+
assert.equal(inspectAudioSpecification(Uint8Array.of(0, 0).buffer, "raw-48khz-16bit-mono-opus").codec, "opus");
|
|
264
|
+
assert.throws(() => inspectAudioSpecification(Uint8Array.of(0x1f, 0).buffer, "raw-48khz-16bit-mono-opus"));
|
|
131
265
|
});
|