
























@@ -5,7 +5,8 @@ import type {
55SpeechProviderOverrides,
66SpeechProviderPlugin,
77} from "openclaw/plugin-sdk/speech-core";
8-import { asFiniteNumber, asObject, trimToUndefined } from "openclaw/plugin-sdk/speech-core";
8+import { asObject, trimToUndefined } from "openclaw/plugin-sdk/speech-core";
9+import { asFiniteNumberInRange } from "openclaw/plugin-sdk/string-coerce-runtime";
910import { volcengineTTS, type VolcengineTtsEncoding } from "./tts.js";
10111112const DEFAULT_VOICE = "en_female_anna_mars_bigtts";
@@ -45,6 +46,10 @@ type VolcengineTtsProviderOverrides = {
4546emotion?: string;
4647};
474849+function normalizeSpeedRatio(value: unknown): number | undefined {
50+return asFiniteNumberInRange(value, { min: 0.2, max: 3 });
51+}
52+4853function normalizeVolcengineProviderConfig(
4954rawConfig: Record<string, unknown>,
5055): VolcengineTtsProviderConfig {
@@ -77,7 +82,7 @@ function normalizeVolcengineProviderConfig(
7782trimToUndefined(process.env.VOLCENGINE_TTS_APP_KEY) ??
7883DEFAULT_APP_KEY,
7984baseUrl: trimToUndefined(raw?.baseUrl) ?? trimToUndefined(process.env.VOLCENGINE_TTS_BASE_URL),
80-speedRatio: asFiniteNumber(raw?.speedRatio),
85+speedRatio: normalizeSpeedRatio(raw?.speedRatio),
8186emotion: trimToUndefined(raw?.emotion),
8287};
8388}
@@ -105,7 +110,7 @@ function readProviderConfig(config: SpeechProviderConfig): VolcengineTtsProvider
105110resourceId: trimToUndefined(config.resourceId) ?? normalized.resourceId,
106111appKey: trimToUndefined(config.appKey) ?? normalized.appKey,
107112baseUrl: trimToUndefined(config.baseUrl) ?? normalized.baseUrl,
108-speedRatio: asFiniteNumber(config.speedRatio) ?? normalized.speedRatio,
113+speedRatio: normalizeSpeedRatio(config.speedRatio) ?? normalized.speedRatio,
109114emotion: trimToUndefined(config.emotion) ?? normalized.emotion,
110115};
111116}
@@ -118,7 +123,7 @@ function readVolcengineOverrides(
118123}
119124return {
120125voice: trimToUndefined(overrides.voice),
121-speedRatio: asFiniteNumber(overrides.speedRatio),
126+speedRatio: normalizeSpeedRatio(overrides.speedRatio),
122127emotion: trimToUndefined(overrides.emotion),
123128};
124129}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。