






















@@ -51,6 +51,7 @@ import {
5151type SpeechVoiceOption,
5252type TtsDirectiveOverrides,
5353type TtsDirectiveParseResult,
54+type TtsConfigResolutionContext,
5455} from "../api.js";
55565657export type {
@@ -409,8 +410,11 @@ export function getResolvedSpeechProviderConfig(
409410return resolveLazyProviderConfig(config, canonical, cfg);
410411}
411412412-export function resolveTtsConfig(cfg: OpenClawConfig, agentId?: string): ResolvedTtsConfig {
413-const raw: TtsConfig = resolveEffectiveTtsConfig(cfg, agentId);
413+export function resolveTtsConfig(
414+cfg: OpenClawConfig,
415+contextOrAgentId?: string | TtsConfigResolutionContext,
416+): ResolvedTtsConfig {
417+const raw: TtsConfig = resolveEffectiveTtsConfig(cfg, contextOrAgentId);
414418const providerSource = raw.provider ? "config" : "default";
415419const timeoutMs = raw.timeoutMs ?? DEFAULT_TIMEOUT_MS;
416420const auto = resolveConfiguredTtsAutoMode(raw);
@@ -470,11 +474,17 @@ function resolveEffectiveTtsAutoState(params: {
470474cfg: OpenClawConfig;
471475sessionAuto?: string;
472476agentId?: string;
477+channelId?: string;
478+accountId?: string;
473479}): {
474480autoMode: TtsAutoMode;
475481prefsPath: string;
476482} {
477-const raw: TtsConfig = resolveEffectiveTtsConfig(params.cfg, params.agentId);
483+const raw: TtsConfig = resolveEffectiveTtsConfig(params.cfg, {
484+agentId: params.agentId,
485+channelId: params.channelId,
486+accountId: params.accountId,
487+});
478488const prefsPath = resolveTtsPrefsPathValue(raw.prefsPath);
479489const sessionAuto = normalizeTtsAutoMode(params.sessionAuto);
480490if (sessionAuto) {
@@ -654,11 +664,17 @@ export function resolveExplicitTtsOverrides(params: {
654664modelId?: string;
655665voiceId?: string;
656666agentId?: string;
667+channelId?: string;
668+accountId?: string;
657669}): TtsDirectiveOverrides {
658670const providerInput = params.provider?.trim();
659671const modelId = params.modelId?.trim();
660672const voiceId = params.voiceId?.trim();
661-const config = resolveTtsConfig(params.cfg, params.agentId);
673+const config = resolveTtsConfig(params.cfg, {
674+agentId: params.agentId,
675+channelId: params.channelId,
676+accountId: params.accountId,
677+});
662678const prefsPath = params.prefsPath ?? resolveTtsPrefsPath(config);
663679const selectedProvider =
664680canonicalizeSpeechProviderId(providerInput, params.cfg) ??
@@ -991,6 +1007,8 @@ function resolveTtsRequestSetup(params: {
9911007providerOverride?: TtsProvider;
9921008disableFallback?: boolean;
9931009agentId?: string;
1010+channelId?: string;
1011+accountId?: string;
9941012}):
9951013| {
9961014config: ResolvedTtsConfig;
@@ -1000,7 +1018,11 @@ function resolveTtsRequestSetup(params: {
10001018| {
10011019error: string;
10021020} {
1003-const config = resolveTtsConfig(params.cfg, params.agentId);
1021+const config = resolveTtsConfig(params.cfg, {
1022+agentId: params.agentId,
1023+channelId: params.channelId,
1024+accountId: params.accountId,
1025+});
10041026const prefsPath = params.prefsPath ?? resolveTtsPrefsPath(config);
10051027if (params.text.length > config.maxTextLength) {
10061028return {
@@ -1027,6 +1049,7 @@ export async function textToSpeech(params: {
10271049disableFallback?: boolean;
10281050timeoutMs?: number;
10291051agentId?: string;
1052+accountId?: string;
10301053}): Promise<TtsResult> {
10311054const synthesis = await synthesizeSpeech(params);
10321055if (!synthesis.success || !synthesis.audioBuffer || !synthesis.fileExtension) {
@@ -1077,6 +1100,7 @@ export async function synthesizeSpeech(params: {
10771100disableFallback?: boolean;
10781101timeoutMs?: number;
10791102agentId?: string;
1103+accountId?: string;
10801104}): Promise<TtsSynthesisResult> {
10811105const setup = resolveTtsRequestSetup({
10821106text: params.text,
@@ -1085,6 +1109,8 @@ export async function synthesizeSpeech(params: {
10851109providerOverride: params.overrides?.provider,
10861110disableFallback: params.disableFallback,
10871111agentId: params.agentId,
1112+channelId: params.channel,
1113+accountId: params.accountId,
10881114});
10891115if ("error" in setup) {
10901116return { success: false, error: setup.error };
@@ -1365,6 +1391,7 @@ export async function maybeApplyTtsToPayload(params: {
13651391inboundAudio?: boolean;
13661392ttsAuto?: string;
13671393agentId?: string;
1394+accountId?: string;
13681395}): Promise<ReplyPayload> {
13691396if (params.payload.isCompactionNotice) {
13701397return params.payload;
@@ -1373,11 +1400,17 @@ export async function maybeApplyTtsToPayload(params: {
13731400cfg: params.cfg,
13741401sessionAuto: params.ttsAuto,
13751402agentId: params.agentId,
1403+channelId: params.channel,
1404+accountId: params.accountId,
13761405});
13771406if (autoMode === "off") {
13781407return params.payload;
13791408}
1380-const config = resolveTtsConfig(params.cfg, params.agentId);
1409+const config = resolveTtsConfig(params.cfg, {
1410+agentId: params.agentId,
1411+channelId: params.channel,
1412+accountId: params.accountId,
1413+});
13811414const activeProvider = getTtsProvider(config, prefsPath);
1382141513831416const reply = resolveSendableOutboundReplyParts(params.payload);
@@ -1486,6 +1519,7 @@ export async function maybeApplyTtsToPayload(params: {
14861519channel: params.channel,
14871520overrides: directives.overrides,
14881521agentId: params.agentId,
1522+accountId: params.accountId,
14891523});
1490152414911525if (result.success && result.audioPath) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。