mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:10:43 +00:00
refactor: share speech provider HTTP errors
This commit is contained in:
@@ -493,18 +493,40 @@ API key auth, and dynamic model resolution.
|
||||
<Tabs>
|
||||
<Tab title="Speech (TTS)">
|
||||
```typescript
|
||||
import { postJsonRequest } from "openclaw/plugin-sdk/provider-http";
|
||||
import { assertOkOrThrowProviderError } from "openclaw/plugin-sdk/speech";
|
||||
|
||||
api.registerSpeechProvider({
|
||||
id: "acme-ai",
|
||||
label: "Acme Speech",
|
||||
isConfigured: ({ config }) => Boolean(config.messages?.tts),
|
||||
synthesize: async (req) => ({
|
||||
audioBuffer: Buffer.from(/* PCM data */),
|
||||
outputFormat: "mp3",
|
||||
fileExtension: ".mp3",
|
||||
voiceCompatible: false,
|
||||
}),
|
||||
synthesize: async (req) => {
|
||||
const { response, release } = await postJsonRequest({
|
||||
url: "https://api.example.com/v1/speech",
|
||||
headers: new Headers({ "Content-Type": "application/json" }),
|
||||
body: { text: req.text },
|
||||
timeoutMs: req.timeoutMs,
|
||||
fetchFn: fetch,
|
||||
auditContext: "acme speech",
|
||||
});
|
||||
try {
|
||||
await assertOkOrThrowProviderError(response, "Acme Speech API error");
|
||||
return {
|
||||
audioBuffer: Buffer.from(await response.arrayBuffer()),
|
||||
outputFormat: "mp3",
|
||||
fileExtension: ".mp3",
|
||||
voiceCompatible: false,
|
||||
};
|
||||
} finally {
|
||||
await release();
|
||||
}
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Use `assertOkOrThrowProviderError(...)` for provider HTTP failures so
|
||||
speech plugins share capped error-body reads, JSON error parsing, and
|
||||
request-id suffixes.
|
||||
</Tab>
|
||||
<Tab title="Realtime transcription">
|
||||
Prefer `createRealtimeTranscriptionWebSocketSession(...)` — the shared
|
||||
|
||||
@@ -218,8 +218,8 @@ For the plugin authoring guide, see [Plugin SDK overview](/plugins/sdk-overview)
|
||||
| `plugin-sdk/media-understanding` | Media understanding provider types plus provider-facing image/audio helper exports |
|
||||
| `plugin-sdk/text-runtime` | Shared text/markdown/logging helpers such as assistant-visible-text stripping, markdown render/chunking/table helpers, redaction helpers, directive-tag helpers, and safe-text utilities |
|
||||
| `plugin-sdk/text-chunking` | Outbound text chunking helper |
|
||||
| `plugin-sdk/speech` | Speech provider types plus provider-facing directive, registry, and validation helpers |
|
||||
| `plugin-sdk/speech-core` | Shared speech provider types, registry, directive, and normalization helpers |
|
||||
| `plugin-sdk/speech` | Speech provider types plus provider-facing directive, registry, validation, and provider HTTP error helpers |
|
||||
| `plugin-sdk/speech-core` | Shared speech provider types, registry, directive, normalization, and provider HTTP error helpers |
|
||||
| `plugin-sdk/realtime-transcription` | Realtime transcription provider types, registry helpers, and shared WebSocket session helper |
|
||||
| `plugin-sdk/realtime-voice` | Realtime voice provider types and registry helpers |
|
||||
| `plugin-sdk/image-generation` | Image generation provider types |
|
||||
|
||||
Reference in New Issue
Block a user