Skip to content

Commit 553acdf

Browse files
authored
feat(gateway): add tts.speak method returning synthesized audio inline (#100770)
* feat(gateway): add tts.speak method returning synthesized audio inline * test(gateway): type tts.speak synthesis mock for failure shapes * fix(gateway): restore lowercase normalizer import used by talk catalog * test(gateway): shift advertised-method window for tts.speak * fix(gateway): ready tts speak for landing * docs(changelog): record tts speak gateway API * test(agents): stabilize fast auto startup synchronization * test(crabbox): stabilize sparse checkout exit guard
1 parent 3ad7777 commit 553acdf

17 files changed

Lines changed: 320 additions & 47 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Docs: https://docs.openclaw.ai
1818
- **Control UI sidebar navigation:** show a small customizable pinned destination set, keep the remaining pages under More, move Settings to the footer, and persist sidebar customization in the browser. (#100296)
1919
- **Control UI sidebar usage:** remove the provider usage quota row from the expanded sidebar while keeping usage details available in the chat composer and Usage page. Thanks @shakkernerd.
2020
- **Android chat code highlighting:** render fenced Kotlin, Swift, TypeScript, JavaScript, Python, Bash, and JSON blocks with bounded, theme-aware syntax colors while preserving plain rendering for unknown, partial, or oversized blocks. (#100217)
21+
- **Gateway TTS playback:** add an operator-scoped `tts.speak` RPC that returns configured-provider speech as inline whole-clip audio for remote clients. (#100708, #100770)
2122

2223
### Fixes
2324

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4801,6 +4801,50 @@ public struct TalkSpeakResult: Codable, Sendable {
48014801
}
48024802
}
48034803

4804+
public struct TtsSpeakParams: Codable, Sendable {
4805+
public let text: String
4806+
4807+
public init(
4808+
text: String)
4809+
{
4810+
self.text = text
4811+
}
4812+
4813+
private enum CodingKeys: String, CodingKey {
4814+
case text
4815+
}
4816+
}
4817+
4818+
public struct TtsSpeakResult: Codable, Sendable {
4819+
public let audiobase64: String
4820+
public let provider: String
4821+
public let outputformat: String?
4822+
public let mimetype: String?
4823+
public let fileextension: String?
4824+
4825+
public init(
4826+
audiobase64: String,
4827+
provider: String,
4828+
outputformat: String?,
4829+
mimetype: String?,
4830+
fileextension: String?)
4831+
{
4832+
self.audiobase64 = audiobase64
4833+
self.provider = provider
4834+
self.outputformat = outputformat
4835+
self.mimetype = mimetype
4836+
self.fileextension = fileextension
4837+
}
4838+
4839+
private enum CodingKeys: String, CodingKey {
4840+
case audiobase64 = "audioBase64"
4841+
case provider
4842+
case outputformat = "outputFormat"
4843+
case mimetype = "mimeType"
4844+
case fileextension = "fileExtension"
4845+
}
4846+
}
4847+
48044848
public struct ChannelsStatusParams: Codable, Sendable {
48054849
public let probe: Bool?
48064850
public let timeoutms: Int?

‎docs/gateway/protocol.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ methods. Treat this as feature discovery, not a full enumeration of
404404
- `tts.enable` and `tts.disable` toggle TTS prefs state.
405405
- `tts.setProvider` updates the preferred TTS provider.
406406
- `tts.convert` runs one-shot text-to-speech conversion.
407+
- `tts.speak` (`operator.write`) renders non-empty `text` with the configured general TTS provider chain and returns one whole clip inline as `audioBase64`, plus `provider` and optional `outputFormat`, `mimeType`, and `fileExtension` metadata. Unlike `tts.convert`, it does not return a Gateway-local path; unlike `talk.speak`, it does not require a Talk provider. Text above `messages.tts.maxTextLength` returns `INVALID_REQUEST`; synthesis failures return `UNAVAILABLE`.
407408

408409
</Accordion>
409410

‎docs/tools/tts.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ Reply -> TTS enabled?
800800
Provider-owned settings keyed by speech provider id. Legacy direct blocks (`messages.tts.openai`, `.elevenlabs`, `.microsoft`, `.edge`) are rewritten by `openclaw doctor --fix`; commit only `messages.tts.providers.<id>`.
801801
</ParamField>
802802
<ParamField path="maxTextLength" type="number" default="4096">
803-
Hard cap for TTS input characters. `/tts audio` and `tts.convert` fail if exceeded.
803+
Hard cap for TTS input characters. `/tts audio`, `tts.convert`, and `tts.speak` fail if exceeded.
804804
</ParamField>
805805
<ParamField path="timeoutMs" type="number" default="30000">
806806
Request timeout in milliseconds. A per-call `timeoutMs` (agent tool, gateway) wins when set; otherwise an explicitly configured `messages.tts.timeoutMs` wins over any plugin-authored provider default.

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ import {
140140
TalkSpeakParamsSchema,
141141
type TalkSpeakResult,
142142
TalkSpeakResultSchema,
143+
type TtsSpeakParams,
144+
TtsSpeakParamsSchema,
145+
type TtsSpeakResult,
146+
TtsSpeakResultSchema,
143147
type ChannelsStatusParams,
144148
ChannelsStatusParamsSchema,
145149
type ChannelsStatusResult,
@@ -907,6 +911,8 @@ export const validateTalkSessionOkResult =
907911
lazyCompile<TalkSessionOkResult>(TalkSessionOkResultSchema);
908912
export const validateTalkSpeakParams = lazyCompile<TalkSpeakParams>(TalkSpeakParamsSchema);
909913
export const validateTalkSpeakResult = lazyCompile<TalkSpeakResult>(TalkSpeakResultSchema);
914+
export const validateTtsSpeakParams = lazyCompile<TtsSpeakParams>(TtsSpeakParamsSchema);
915+
export const validateTtsSpeakResult = lazyCompile<TtsSpeakResult>(TtsSpeakResultSchema);
910916
export const validateChannelsStatusParams = lazyCompile<ChannelsStatusParams>(
911917
ChannelsStatusParamsSchema,
912918
);
@@ -1272,6 +1278,8 @@ export {
12721278
TalkSessionOkResultSchema,
12731279
TalkSpeakParamsSchema,
12741280
TalkSpeakResultSchema,
1281+
TtsSpeakParamsSchema,
1282+
TtsSpeakResultSchema,
12751283
ChannelsStatusParamsSchema,
12761284
ChannelsStatusResultSchema,
12771285
ChannelsStartParamsSchema,
@@ -1467,6 +1475,8 @@ export type {
14671475
TalkSessionOkResult,
14681476
TalkSpeakParams,
14691477
TalkSpeakResult,
1478+
TtsSpeakParams,
1479+
TtsSpeakResult,
14701480
TalkModeParams,
14711481
ChannelsStatusParams,
14721482
ChannelsStatusResult,

‎packages/gateway-protocol/src/schema/channels.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ export const TalkSpeakParamsSchema = Type.Object(
4848
{ additionalProperties: false },
4949
);
5050

51+
/**
52+
* One-shot text-to-speech request rendered with the configured TTS provider
53+
* chain (unlike `talk.speak`, which pins the Talk-mode provider).
54+
*/
55+
export const TtsSpeakParamsSchema = Type.Object(
56+
{
57+
text: NonEmptyString,
58+
},
59+
{ additionalProperties: false },
60+
);
61+
5162
/** Supported Talk session shapes exposed to clients and providers. */
5263
const TalkModeSchema = Type.Union([
5364
Type.Literal("realtime"),
@@ -699,6 +710,18 @@ export const TalkSpeakResultSchema = Type.Object(
699710
{ additionalProperties: false },
700711
);
701712

713+
/** Text-to-speech result for `tts.speak` with encoded audio and provider metadata. */
714+
export const TtsSpeakResultSchema = Type.Object(
715+
{
716+
audioBase64: NonEmptyString,
717+
provider: NonEmptyString,
718+
outputFormat: Type.Optional(Type.String()),
719+
mimeType: Type.Optional(Type.String()),
720+
fileExtension: Type.Optional(Type.String()),
721+
},
722+
{ additionalProperties: false },
723+
);
724+
702725
/** Channel status request, optionally probing one channel before returning. */
703726
export const ChannelsStatusParamsSchema = Type.Object(
704727
{

‎packages/gateway-protocol/src/schema/protocol-schemas.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ import {
127127
TalkSessionTurnParamsSchema,
128128
TalkSpeakParamsSchema,
129129
TalkSpeakResultSchema,
130+
TtsSpeakParamsSchema,
131+
TtsSpeakResultSchema,
130132
ChannelsStatusParamsSchema,
131133
ChannelsStatusResultSchema,
132134
TalkModeParamsSchema,
@@ -537,6 +539,8 @@ export const ProtocolSchemas = {
537539
TalkSessionOkResult: TalkSessionOkResultSchema,
538540
TalkSpeakParams: TalkSpeakParamsSchema,
539541
TalkSpeakResult: TalkSpeakResultSchema,
542+
TtsSpeakParams: TtsSpeakParamsSchema,
543+
TtsSpeakResult: TtsSpeakResultSchema,
540544
ChannelsStatusParams: ChannelsStatusParamsSchema,
541545
ChannelsStatusResult: ChannelsStatusResultSchema,
542546
ChannelsStartParams: ChannelsStartParamsSchema,

‎packages/gateway-protocol/src/schema/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ export type TalkSessionCloseParams = SchemaType<"TalkSessionCloseParams">;
180180
export type TalkSessionOkResult = SchemaType<"TalkSessionOkResult">;
181181
export type TalkSpeakParams = SchemaType<"TalkSpeakParams">;
182182
export type TalkSpeakResult = SchemaType<"TalkSpeakResult">;
183+
export type TtsSpeakParams = SchemaType<"TtsSpeakParams">;
184+
export type TtsSpeakResult = SchemaType<"TtsSpeakResult">;
183185

184186
/** Channel control and web-login payloads. */
185187
export type ChannelsStatusParams = SchemaType<"ChannelsStatusParams">;

‎src/agents/embedded-agent-runner/run.fast-mode-auto.test.ts‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
resetAgentEventsForTest,
55
type AgentEventPayload,
66
} from "../../infra/agent-events.js";
7+
import { createDeferred } from "../../shared/deferred.js";
78
import { makeAttemptResult } from "./run.overflow-compaction.fixture.js";
89
import {
910
loadRunOverflowCompactionHarness,
@@ -94,9 +95,11 @@ describe("runEmbeddedAgent fast auto progress", () => {
9495
resolve(successAttempt("ollama", "glm-5.1:cloud"));
9596
};
9697
});
98+
const attemptStarted = createDeferred();
9799
mockedRunEmbeddedAttempt.mockImplementationOnce(async (params) => {
98100
attemptParams = params as FastModeAttemptParams;
99101
resolveAttemptFastMode(params);
102+
attemptStarted.resolve();
100103
return attemptDone;
101104
});
102105

@@ -115,9 +118,9 @@ describe("runEmbeddedAgent fast auto progress", () => {
115118
},
116119
});
117120

118-
await vi.waitFor(() => {
119-
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
120-
});
121+
await vi.advanceTimersByTimeAsync(0);
122+
await attemptStarted.promise;
123+
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
121124
await vi.advanceTimersByTimeAsync(31_000);
122125

123126
expect(events.map((event) => event.data?.summary).filter(Boolean)).toHaveLength(0);
@@ -190,9 +193,11 @@ describe("runEmbeddedAgent fast auto progress", () => {
190193
resolve(successAttempt("ollama", "glm-5.1:cloud"));
191194
};
192195
});
196+
const attemptStarted = createDeferred();
193197
mockedRunEmbeddedAttempt.mockImplementationOnce(async (params) => {
194198
attemptParams = params as FastModeAttemptParams;
195199
resolveAttemptFastMode(params);
200+
attemptStarted.resolve();
196201
return attemptDone;
197202
});
198203

@@ -211,9 +216,9 @@ describe("runEmbeddedAgent fast auto progress", () => {
211216
},
212217
});
213218

214-
await vi.waitFor(() => {
215-
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
216-
});
219+
await vi.advanceTimersByTimeAsync(0);
220+
await attemptStarted.promise;
221+
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
217222
await vi.advanceTimersByTimeAsync(31_000);
218223
await attemptParams?.onAgentEvent?.({
219224
stream: "tool",
@@ -266,9 +271,11 @@ describe("runEmbeddedAgent fast auto progress", () => {
266271
resolve(successAttempt("ollama", "glm-5.1:cloud"));
267272
};
268273
});
274+
const attemptStarted = createDeferred();
269275
mockedRunEmbeddedAttempt.mockImplementationOnce(async (params) => {
270276
attemptParams = params as FastModeAttemptParams;
271277
resolveAttemptFastMode(params);
278+
attemptStarted.resolve();
272279
return attemptDone;
273280
});
274281

@@ -298,9 +305,9 @@ describe("runEmbeddedAgent fast auto progress", () => {
298305
},
299306
});
300307

301-
await vi.waitFor(() => {
302-
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
303-
});
308+
await vi.advanceTimersByTimeAsync(0);
309+
await attemptStarted.promise;
310+
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
304311
await vi.advanceTimersByTimeAsync(61_000);
305312
await attemptParams?.onAgentEvent?.({
306313
stream: "tool",
@@ -341,9 +348,11 @@ describe("runEmbeddedAgent fast auto progress", () => {
341348
resolve(successAttempt("ollama", "glm-5.1:cloud"));
342349
};
343350
});
351+
const attemptStarted = createDeferred();
344352
mockedRunEmbeddedAttempt.mockImplementationOnce(async (params) => {
345353
attemptParams = params as FastModeAttemptParams;
346354
resolveAttemptFastMode(params);
355+
attemptStarted.resolve();
347356
return attemptDone;
348357
});
349358

@@ -368,9 +377,9 @@ describe("runEmbeddedAgent fast auto progress", () => {
368377
},
369378
});
370379

371-
await vi.waitFor(() => {
372-
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
373-
});
380+
await vi.advanceTimersByTimeAsync(0);
381+
await attemptStarted.promise;
382+
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
374383
await vi.advanceTimersByTimeAsync(61_000);
375384
await attemptParams?.onAgentEvent?.({
376385
stream: "tool",

‎src/gateway/methods/core-descriptors.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export const CORE_GATEWAY_METHOD_SPECS: readonly CoreGatewayMethodSpec[] = [
258258
// reads. Strong user/tenant isolation requires separate Gateways; see operator-scopes.md.
259259
{ name: "agents.workspace.list", scope: "operator.read" },
260260
{ name: "agents.workspace.get", scope: "operator.read" },
261+
{ name: "tts.speak", scope: "operator.write" },
261262
] as const;
262263

263264
const CORE_GATEWAY_METHOD_SPEC_BY_NAME: ReadonlyMap<string, CoreGatewayMethodSpec> = new Map(

0 commit comments

Comments
 (0)