@openclaw/volcengine-provider 2026.11.3 → 2026.11.5-beta.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"entries":[{"output":"api.js","source":"extensions/volcengine/api.ts"},{"output":"capability-catalog.js","source":"extensions/volcengine/capability-catalog.ts"},{"output":"index.js","source":"extensions/volcengine/index.ts"},{"output":"models.js","source":"extensions/volcengine/models.ts"},{"output":"provider-discovery.js","source":"extensions/volcengine/provider-discovery.ts"},{"output":"speech-provider.js","source":"extensions/volcengine/speech-provider.ts"}],"chunks":[{"output":".setup/models-BWaO4fQH.mjs","sha256":"91c11c620900aa1ccbd38618faa10dc230e8ec005480ca0e0cf08424fc51c492","facadeSource":null,"sources":["extensions/volcengine/models.ts","extensions/volcengine/openclaw.plugin.json"]},{"output":"api.js","sha256":"6ac92a0d4ad2210500f156a72a3dbf58417a9df79c177e7dde78bdb5f8caf5b1","facadeSource":"extensions/volcengine/api.ts","sources":["extensions/volcengine/api.ts"]},{"output":"capability-catalog.js","sha256":"4debdfb60fc3de183c072f5fdc3d5273b71d5bddd2b5f7621b76a351afa4aaec","facadeSource":"extensions/volcengine/capability-catalog.ts","sources":["extensions/volcengine/capability-catalog.ts"]},{"output":"index.js","sha256":"67c75790410474d035c824b840a1b166122141d175fb4d1a822666a63a4e7710","facadeSource":"extensions/volcengine/index.ts","sources":["extensions/volcengine/index.ts"]},{"output":"models.js","sha256":"1c2a4a7c23ba4f5b1c3e98784671dbf9ff2b3aa53519c250d9aa2707e5e0733a","facadeSource":"extensions/volcengine/models.ts","sources":[]},{"output":"provider-discovery.js","sha256":"91f92d813fe903d85217aca5deecf5a6b7bc66f10ee4816c4dcc25b3bbfd2248","facadeSource":"extensions/volcengine/provider-discovery.ts","sources":["extensions/volcengine/provider-discovery.ts"]},{"output":"speech-provider.js","sha256":"728f1133da5b3da740e73ee0c0b3caeca5e9d137bfbcb6f06125563c5f6b09f4","facadeSource":"extensions/volcengine/speech-provider.ts","sources":["extensions/volcengine/speech-provider.ts"]}],"unrenderedSources":[]}
package/dist/api.js CHANGED
@@ -10,12 +10,10 @@ const VOLCENGINE_UNSUPPORTED_TOOL_SCHEMA_KEYWORDS = [
10
10
  "minContains",
11
11
  "maxContains"
12
12
  ];
13
- function mergeUnsupportedToolSchemaKeywords(existing) {
14
- const merged = uniqueStrings([...existing ?? [], ...VOLCENGINE_UNSUPPORTED_TOOL_SCHEMA_KEYWORDS]);
15
- return existing?.length === merged.length && existing.every((value, index) => value === merged[index]) ? existing : merged;
16
- }
17
13
  function applyVolcengineToolSchemaCompat(model) {
18
- return applyModelCompatPatch(model, { unsupportedToolSchemaKeywords: mergeUnsupportedToolSchemaKeywords(model.compat?.unsupportedToolSchemaKeywords) });
14
+ const existing = model.compat?.unsupportedToolSchemaKeywords;
15
+ const merged = uniqueStrings([...existing ?? [], ...VOLCENGINE_UNSUPPORTED_TOOL_SCHEMA_KEYWORDS]);
16
+ return applyModelCompatPatch(model, { unsupportedToolSchemaKeywords: existing?.length === merged.length && existing.every((value, index) => value === merged[index]) ? existing : merged });
19
17
  }
20
18
  //#endregion
21
19
  export { DOUBAO_BASE_URL, DOUBAO_CODING_BASE_URL, DOUBAO_CODING_MODEL_CATALOG, DOUBAO_MODEL_CATALOG, VOLCENGINE_UNSUPPORTED_TOOL_SCHEMA_KEYWORDS, applyVolcengineToolSchemaCompat };
package/dist/models.js CHANGED
@@ -1,2 +1 @@
1
- import { a as VOLCENGINE_PROVIDER_CATALOG, i as DOUBAO_MODEL_CATALOG, n as DOUBAO_CODING_BASE_URL, r as DOUBAO_CODING_MODEL_CATALOG, t as DOUBAO_BASE_URL } from "./.setup/models-BWaO4fQH.mjs";
2
- export { DOUBAO_BASE_URL, DOUBAO_CODING_BASE_URL, DOUBAO_CODING_MODEL_CATALOG, DOUBAO_MODEL_CATALOG, VOLCENGINE_PROVIDER_CATALOG };
1
+ export { t as DOUBAO_BASE_URL, n as DOUBAO_CODING_BASE_URL, r as DOUBAO_CODING_MODEL_CATALOG, i as DOUBAO_MODEL_CATALOG, a as VOLCENGINE_PROVIDER_CATALOG } from "./.setup/models-BWaO4fQH.mjs";
@@ -1,12 +1,48 @@
1
- import { volcengineTTS } from "./tts.js";
2
- import { asFiniteNumberInRange, asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
1
+ import { asFiniteNumberInRange, asOptionalRecord, isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ import * as crypto from "node:crypto";
3
3
  import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input";
4
- import { parseSpeechDirectiveNumberOverride, resolveSpeechProviderApiKey } from "openclaw/plugin-sdk/speech-provider";
4
+ import { createSpeechDirectiveParser, resolveSpeechProviderApiKey } from "openclaw/plugin-sdk/speech-provider";
5
5
  //#region extensions/volcengine/speech-provider.ts
6
6
  const DEFAULT_VOICE = "en_female_anna_mars_bigtts";
7
7
  const DEFAULT_CLUSTER = "volcano_tts";
8
8
  const DEFAULT_RESOURCE_ID = "seed-tts-1.0";
9
9
  const DEFAULT_APP_KEY = "aGjiRDfUWi";
10
+ const VOLCENGINE_TTS_RESPONSE_MAX_BYTES = 16777216;
11
+ const BYTEPLUS_SEED_TTS_URL = "https://voice.ap-southeast-1.bytepluses.com/api/v3/tts/unidirectional";
12
+ const VOLCENGINE_LEGACY_TTS_URL = "https://openspeech.bytedance.com/api/v1/tts";
13
+ function parseJsonObject(text, providerName) {
14
+ try {
15
+ const parsed = JSON.parse(text);
16
+ if (!isRecord(parsed)) throw new Error("expected JSON object");
17
+ return parsed;
18
+ } catch (err) {
19
+ const detail = err instanceof Error ? err.message : String(err);
20
+ throw new Error(`${providerName} TTS: failed to parse response JSON: ${detail}`, { cause: err });
21
+ }
22
+ }
23
+ function toTtsResponse(parsed) {
24
+ const header = asOptionalRecord(parsed.header);
25
+ return {
26
+ code: typeof parsed.code === "number" ? parsed.code : typeof header?.code === "number" ? header.code : void 0,
27
+ message: typeof parsed.message === "string" ? parsed.message : typeof header?.message === "string" ? header.message : void 0,
28
+ data: typeof parsed.data === "string" ? parsed.data : void 0
29
+ };
30
+ }
31
+ function parseSeedTtsFrames(text) {
32
+ const trimmed = text.trim();
33
+ if (!trimmed) return [];
34
+ try {
35
+ return [toTtsResponse(parseJsonObject(trimmed, "BytePlus Seed Speech"))];
36
+ } catch {}
37
+ const frames = [];
38
+ for (const line of trimmed.split(/\r?\n/)) {
39
+ const item = line.trim();
40
+ if (!item) continue;
41
+ const json = item.startsWith("data:") ? item.slice(5).trim() : item;
42
+ frames.push(toTtsResponse(parseJsonObject(json, "BytePlus Seed Speech")));
43
+ }
44
+ return frames;
45
+ }
10
46
  const VOLCENGINE_VOICES = [
11
47
  "en_female_anna_mars_bigtts",
12
48
  "en_male_adam_mars_bigtts",
@@ -27,7 +63,7 @@ function normalizeSpeedRatio(value) {
27
63
  }
28
64
  function normalizeVolcengineProviderConfig(rawConfig) {
29
65
  const providers = asOptionalRecord(rawConfig.providers);
30
- const raw = asOptionalRecord(providers?.volcengine) ?? asOptionalRecord(rawConfig.volcengine);
66
+ const raw = asOptionalRecord(providers?.volcengine);
31
67
  return {
32
68
  apiKey: normalizeResolvedSecretInputString({
33
69
  value: raw?.apiKey,
@@ -57,48 +93,34 @@ function resolveLegacyVolcengineCredentials(config) {
57
93
  };
58
94
  }
59
95
  function readProviderConfig(config) {
60
- return normalizeVolcengineProviderConfig({ volcengine: {
96
+ return normalizeVolcengineProviderConfig({ providers: { volcengine: {
61
97
  ...config,
62
98
  token: normalizeOptionalString(config.token)
63
- } });
99
+ } } });
64
100
  }
65
- function parseDirectiveToken(ctx) {
66
- switch (ctx.key) {
67
- case "voice":
68
- case "volcengine_voice":
69
- case "volcenginevoice":
70
- if (!ctx.policy.allowVoice) return { handled: true };
71
- return {
72
- handled: true,
73
- overrides: {
74
- ...ctx.currentOverrides,
75
- voice: ctx.value
76
- }
77
- };
78
- case "speed":
79
- case "speedratio":
80
- case "speed_ratio": return parseSpeechDirectiveNumberOverride({
81
- ctx,
82
- overrideKey: "speedRatio",
101
+ const parseDirectiveToken = createSpeechDirectiveParser({
102
+ voice: ["allowVoice", [
103
+ "voice",
104
+ "volcengine_voice",
105
+ "volcenginevoice"
106
+ ]],
107
+ speedRatio: [
108
+ "allowVoiceSettings",
109
+ [
110
+ "speed",
111
+ "speedratio",
112
+ "speed_ratio"
113
+ ],
114
+ { number: {
83
115
  range: {
84
116
  min: .2,
85
117
  max: 3
86
118
  },
87
- warning: (value) => `invalid Volcengine speedRatio "${value}"`,
88
- mergeCurrentOverrides: true
89
- });
90
- case "emotion":
91
- if (!ctx.policy.allowVoiceSettings) return { handled: true };
92
- return {
93
- handled: true,
94
- overrides: {
95
- ...ctx.currentOverrides,
96
- emotion: ctx.value
97
- }
98
- };
99
- default: return { handled: false };
100
- }
101
- }
119
+ warning: (value) => `invalid Volcengine speedRatio "${value}"`
120
+ } }
121
+ ],
122
+ emotion: ["allowVoiceSettings", ["emotion"]]
123
+ });
102
124
  function buildVolcengineSpeechProvider() {
103
125
  const isConfigured = ({ providerConfig }) => {
104
126
  const cfg = readProviderConfig(providerConfig);
@@ -129,22 +151,101 @@ function buildVolcengineSpeechProvider() {
129
151
  if (!apiKey && (!appId || !token)) throw new Error("Volcengine TTS credentials missing. Set VOLCENGINE_TTS_API_KEY, BYTEPLUS_SEED_SPEECH_API_KEY, or legacy VOLCENGINE_TTS_APPID and VOLCENGINE_TTS_TOKEN.");
130
152
  const isVoiceNote = req.target === "voice-note";
131
153
  const encoding = isVoiceNote ? "ogg_opus" : "mp3";
132
- return {
133
- audioBuffer: await volcengineTTS({
134
- text: req.text,
135
- apiKey,
136
- appId,
154
+ const voice = normalizeOptionalString(overrides?.voice) ?? cfg.voice;
155
+ const { cluster, resourceId, appKey } = cfg;
156
+ const baseUrl = cfg.baseUrl ?? (apiKey ? BYTEPLUS_SEED_TTS_URL : VOLCENGINE_LEGACY_TTS_URL);
157
+ const speedRatio = normalizeSpeedRatio(overrides?.speedRatio) ?? cfg.speedRatio ?? 1;
158
+ const emotion = normalizeOptionalString(overrides?.emotion) ?? cfg.emotion;
159
+ const { text, timeoutMs } = req;
160
+ const { canonicalizeBase64 } = await import("openclaw/plugin-sdk/media-runtime");
161
+ const { readResponseWithLimit } = await import("openclaw/plugin-sdk/response-limit-runtime");
162
+ const { fetchWithSsrFGuard } = await import("openclaw/plugin-sdk/ssrf-runtime");
163
+ const providerName = apiKey ? "BytePlus Seed Speech" : "Volcengine";
164
+ const payload = apiKey ? {
165
+ user: { uid: "openclaw" },
166
+ req_params: {
167
+ text,
168
+ speaker: voice,
169
+ audio_params: {
170
+ format: encoding,
171
+ sample_rate: 24e3
172
+ },
173
+ ...speedRatio !== 1 ? { speed_ratio: speedRatio } : {},
174
+ ...emotion ? { emotion } : {}
175
+ }
176
+ } : {
177
+ app: {
178
+ appid: appId,
137
179
  token,
138
- voice: normalizeOptionalString(overrides?.voice) ?? cfg.voice,
139
- cluster: cfg.cluster,
140
- resourceId: cfg.resourceId,
141
- appKey: cfg.appKey,
142
- baseUrl: cfg.baseUrl,
143
- speedRatio: normalizeSpeedRatio(overrides?.speedRatio) ?? cfg.speedRatio,
144
- emotion: normalizeOptionalString(overrides?.emotion) ?? cfg.emotion,
180
+ cluster
181
+ },
182
+ user: { uid: "openclaw" },
183
+ audio: {
184
+ voice_type: voice,
145
185
  encoding,
146
- timeoutMs: req.timeoutMs
147
- }),
186
+ speed_ratio: speedRatio,
187
+ volume_ratio: 1,
188
+ pitch_ratio: 1,
189
+ ...emotion ? { emotion } : {}
190
+ },
191
+ request: {
192
+ reqid: crypto.randomUUID(),
193
+ text,
194
+ text_type: "plain",
195
+ operation: "query"
196
+ }
197
+ };
198
+ const { response, release } = await fetchWithSsrFGuard({
199
+ url: baseUrl,
200
+ init: {
201
+ method: "POST",
202
+ headers: {
203
+ "Content-Type": "application/json",
204
+ ...apiKey ? {
205
+ Connection: "keep-alive",
206
+ "X-Api-Key": apiKey,
207
+ "X-Api-Resource-Id": resourceId,
208
+ "X-Api-App-Key": appKey
209
+ } : { Authorization: `Bearer;${token}` }
210
+ },
211
+ body: JSON.stringify(payload)
212
+ },
213
+ timeoutMs,
214
+ policy: { hostnameAllowlist: [new URL(baseUrl).hostname] },
215
+ auditContext: "volcengine.tts"
216
+ });
217
+ let audioBuffer;
218
+ try {
219
+ const responseText = new TextDecoder("utf-8", { fatal: true }).decode(await readResponseWithLimit(response, VOLCENGINE_TTS_RESPONSE_MAX_BYTES, { onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`${providerName} TTS response exceeds ${maxBytes} bytes`) }));
220
+ if (!apiKey) {
221
+ const body = toTtsResponse(parseJsonObject(responseText, providerName));
222
+ if (!response.ok || body.code !== 3e3 || !body.data) throw new Error(`Volcengine TTS error ${body.code ?? response.status}: ${body.message ?? "unknown"}`);
223
+ const canonicalAudio = canonicalizeBase64(body.data);
224
+ if (!canonicalAudio) throw new Error("Volcengine TTS returned malformed base64 audio data");
225
+ audioBuffer = Buffer.from(canonicalAudio, "base64");
226
+ } else {
227
+ const frames = parseSeedTtsFrames(responseText);
228
+ const chunks = [];
229
+ for (const frame of frames) {
230
+ if (frame.code === 0) {
231
+ if (frame.data) {
232
+ const canonicalAudio = canonicalizeBase64(frame.data);
233
+ if (!canonicalAudio) throw new Error("BytePlus Seed Speech TTS returned malformed base64 audio data");
234
+ chunks.push(Buffer.from(canonicalAudio, "base64"));
235
+ }
236
+ continue;
237
+ }
238
+ if (frame.code === 2e7) continue;
239
+ throw new Error(`BytePlus Seed Speech TTS error ${frame.code ?? response.status}: ${frame.message ?? "unknown"}`);
240
+ }
241
+ if (!response.ok || chunks.length === 0) throw new Error(`BytePlus Seed Speech TTS error ${response.status}: no audio data`);
242
+ audioBuffer = Buffer.concat(chunks);
243
+ }
244
+ } finally {
245
+ await release();
246
+ }
247
+ return {
248
+ audioBuffer,
148
249
  outputFormat: encoding === "ogg_opus" ? "opus" : "mp3",
149
250
  fileExtension: encoding === "ogg_opus" ? ".opus" : ".mp3",
150
251
  voiceCompatible: isVoiceNote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/volcengine-provider",
3
- "version": "2026.11.3",
3
+ "version": "2026.11.5-beta.2",
4
4
  "description": "OpenClaw Volcengine provider plugin.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,10 +18,10 @@
18
18
  "minHostVersion": ">=2026.7.2"
19
19
  },
20
20
  "compat": {
21
- "pluginApi": ">=2026.11.3"
21
+ "pluginApi": ">=2026.11.5-beta.2"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.11.3",
24
+ "openclawVersion": "2026.11.5-beta.2",
25
25
  "bundledDist": false
26
26
  },
27
27
  "release": {
@@ -40,7 +40,7 @@
40
40
  "assets/activity.svg"
41
41
  ],
42
42
  "peerDependencies": {
43
- "openclaw": ">=2026.11.3"
43
+ "openclaw": ">=2026.11.5-beta.2"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "openclaw": {
package/dist/tts.js DELETED
@@ -1,135 +0,0 @@
1
- import { asOptionalRecord, isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
2
- import * as crypto from "node:crypto";
3
- //#region extensions/volcengine/tts.ts
4
- const DEFAULT_SEED_VOICE = "en_female_anna_mars_bigtts";
5
- const DEFAULT_LEGACY_VOICE = "zh_female_xiaohe_uranus_bigtts";
6
- const DEFAULT_CLUSTER = "volcano_tts";
7
- const DEFAULT_SEED_TTS_RESOURCE_ID = "seed-tts-1.0";
8
- const DEFAULT_SEED_TTS_APP_KEY = "aGjiRDfUWi";
9
- const VOLCENGINE_TTS_RESPONSE_MAX_BYTES = 16777216;
10
- const BYTEPLUS_SEED_TTS_URL = "https://voice.ap-southeast-1.bytepluses.com/api/v3/tts/unidirectional";
11
- const VOLCENGINE_LEGACY_TTS_URL = "https://openspeech.bytedance.com/api/v1/tts";
12
- function parseJsonObject(text, providerName) {
13
- try {
14
- const parsed = JSON.parse(text);
15
- if (!isRecord(parsed)) throw new Error("expected JSON object");
16
- return parsed;
17
- } catch (err) {
18
- const detail = err instanceof Error ? err.message : String(err);
19
- throw new Error(`${providerName} TTS: failed to parse response JSON: ${detail}`, { cause: err });
20
- }
21
- }
22
- function toTtsResponse(parsed) {
23
- const header = asOptionalRecord(parsed.header);
24
- return {
25
- code: typeof parsed.code === "number" ? parsed.code : typeof header?.code === "number" ? header.code : void 0,
26
- message: typeof parsed.message === "string" ? parsed.message : typeof header?.message === "string" ? header.message : void 0,
27
- data: typeof parsed.data === "string" ? parsed.data : void 0
28
- };
29
- }
30
- function parseSeedTtsFrames(text) {
31
- const trimmed = text.trim();
32
- if (!trimmed) return [];
33
- try {
34
- return [toTtsResponse(parseJsonObject(trimmed, "BytePlus Seed Speech"))];
35
- } catch {}
36
- const frames = [];
37
- for (const line of trimmed.split(/\r?\n/)) {
38
- const item = line.trim();
39
- if (!item) continue;
40
- const json = item.startsWith("data:") ? item.slice(5).trim() : item;
41
- frames.push(toTtsResponse(parseJsonObject(json, "BytePlus Seed Speech")));
42
- }
43
- return frames;
44
- }
45
- async function volcengineTTS(params) {
46
- if (!params.apiKey && (!params.appId || !params.token)) throw new Error("Volcengine TTS credentials missing. Set a BytePlus Seed Speech API key or legacy AppID/token.");
47
- const { text, apiKey, appId, token, voice = apiKey ? DEFAULT_SEED_VOICE : DEFAULT_LEGACY_VOICE, cluster = DEFAULT_CLUSTER, resourceId = DEFAULT_SEED_TTS_RESOURCE_ID, appKey = DEFAULT_SEED_TTS_APP_KEY, baseUrl = apiKey ? BYTEPLUS_SEED_TTS_URL : VOLCENGINE_LEGACY_TTS_URL, speedRatio = 1, emotion, encoding = "ogg_opus", timeoutMs = 3e4 } = params;
48
- const { canonicalizeBase64 } = await import("openclaw/plugin-sdk/media-runtime");
49
- const { readResponseWithLimit } = await import("openclaw/plugin-sdk/response-limit-runtime");
50
- const { fetchWithSsrFGuard } = await import("openclaw/plugin-sdk/ssrf-runtime");
51
- const providerName = apiKey ? "BytePlus Seed Speech" : "Volcengine";
52
- const payload = apiKey ? {
53
- user: { uid: "openclaw" },
54
- req_params: {
55
- text,
56
- speaker: voice,
57
- audio_params: {
58
- format: encoding === "wav" ? "pcm" : encoding,
59
- sample_rate: 24e3
60
- },
61
- ...speedRatio !== 1 ? { speed_ratio: speedRatio } : {},
62
- ...emotion ? { emotion } : {}
63
- }
64
- } : {
65
- app: {
66
- appid: appId,
67
- token,
68
- cluster
69
- },
70
- user: { uid: "openclaw" },
71
- audio: {
72
- voice_type: voice,
73
- encoding,
74
- speed_ratio: speedRatio,
75
- volume_ratio: 1,
76
- pitch_ratio: 1,
77
- ...emotion ? { emotion } : {}
78
- },
79
- request: {
80
- reqid: crypto.randomUUID(),
81
- text,
82
- text_type: "plain",
83
- operation: "query"
84
- }
85
- };
86
- const { response, release } = await fetchWithSsrFGuard({
87
- url: baseUrl,
88
- init: {
89
- method: "POST",
90
- headers: {
91
- "Content-Type": "application/json",
92
- ...apiKey ? {
93
- Connection: "keep-alive",
94
- "X-Api-Key": apiKey,
95
- "X-Api-Resource-Id": resourceId,
96
- "X-Api-App-Key": appKey
97
- } : { Authorization: `Bearer;${token}` }
98
- },
99
- body: JSON.stringify(payload)
100
- },
101
- timeoutMs,
102
- policy: { hostnameAllowlist: [new URL(baseUrl).hostname] },
103
- auditContext: "volcengine.tts"
104
- });
105
- try {
106
- const responseText = new TextDecoder("utf-8", { fatal: true }).decode(await readResponseWithLimit(response, VOLCENGINE_TTS_RESPONSE_MAX_BYTES, { onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`${providerName} TTS response exceeds ${maxBytes} bytes`) }));
107
- if (!apiKey) {
108
- const body = toTtsResponse(parseJsonObject(responseText, providerName));
109
- if (!response.ok || body.code !== 3e3 || !body.data) throw new Error(`Volcengine TTS error ${body.code ?? response.status}: ${body.message ?? "unknown"}`);
110
- const canonicalAudio = canonicalizeBase64(body.data);
111
- if (!canonicalAudio) throw new Error("Volcengine TTS returned malformed base64 audio data");
112
- return Buffer.from(canonicalAudio, "base64");
113
- }
114
- const frames = parseSeedTtsFrames(responseText);
115
- const chunks = [];
116
- for (const frame of frames) {
117
- if (frame.code === 0) {
118
- if (frame.data) {
119
- const canonicalAudio = canonicalizeBase64(frame.data);
120
- if (!canonicalAudio) throw new Error("BytePlus Seed Speech TTS returned malformed base64 audio data");
121
- chunks.push(Buffer.from(canonicalAudio, "base64"));
122
- }
123
- continue;
124
- }
125
- if (frame.code === 2e7) continue;
126
- throw new Error(`BytePlus Seed Speech TTS error ${frame.code ?? response.status}: ${frame.message ?? "unknown"}`);
127
- }
128
- if (!response.ok || chunks.length === 0) throw new Error(`BytePlus Seed Speech TTS error ${response.status}: no audio data`);
129
- return Buffer.concat(chunks);
130
- } finally {
131
- await release();
132
- }
133
- }
134
- //#endregion
135
- export { volcengineTTS };