-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add MiniMax regional text to speech provider #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
octo-patch
wants to merge
1
commit into
linuxhsj:main
Choose a base branch
from
octo-patch:octo/20260822-tts-tool-recvsf4Uc2iI0L
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import type { | ||
| SpeechProviderConfig, | ||
| SpeechProviderPlugin, | ||
| } from "openclaw/plugin-sdk/speech-core"; | ||
|
|
||
| const GLOBAL_TTS_URL = "https://api.minimax.io/v1/t2a_v2"; | ||
| const DEFAULT_MODEL = "speech-2.8-hd"; | ||
|
|
||
| function text(value: unknown): string | undefined { | ||
| return typeof value === "string" && value.trim() ? value.trim() : undefined; | ||
| } | ||
|
|
||
| function configValue( | ||
| config: SpeechProviderConfig, | ||
| key: string, | ||
| ): string | undefined { | ||
| return text(config[key]); | ||
| } | ||
|
|
||
| export function buildMinimaxSpeechProvider(): SpeechProviderPlugin { | ||
| return { | ||
| id: "minimax", | ||
| label: "MiniMax", | ||
| autoSelectOrder: 25, | ||
| models: [ | ||
| "speech-2.8-hd", | ||
| "speech-2.8-turbo", | ||
| "speech-2.6-hd", | ||
| "speech-2.6-turbo", | ||
| ], | ||
| resolveConfig: ({ rawConfig }) => { | ||
| const providers = rawConfig.providers; | ||
| const providerConfig = | ||
| typeof providers === "object" && providers !== null | ||
| ? (providers as Record<string, unknown>).minimax | ||
| : undefined; | ||
| return ( | ||
| typeof providerConfig === "object" && providerConfig !== null | ||
| ? providerConfig | ||
| : {} | ||
| ) as SpeechProviderConfig; | ||
| }, | ||
| isConfigured: ({ providerConfig }) => | ||
| Boolean( | ||
| configValue(providerConfig, "apiKey") || process.env.MINIMAX_API_KEY, | ||
| ), | ||
| synthesize: async (req) => { | ||
| const apiKey = | ||
| configValue(req.providerConfig, "apiKey") || | ||
| process.env.MINIMAX_API_KEY; | ||
| if (!apiKey) throw new Error("MiniMax API key missing"); | ||
| const endpoint = | ||
| configValue(req.providerConfig, "baseUrl") || GLOBAL_TTS_URL; | ||
| const model = | ||
| configValue(req.providerOverrides ?? {}, "model") || | ||
| configValue(req.providerConfig, "model") || | ||
| DEFAULT_MODEL; | ||
| const voice = | ||
| configValue(req.providerOverrides ?? {}, "voice") || | ||
| configValue(req.providerConfig, "voice") || | ||
| "female-shaonv"; | ||
| const response = await fetch(endpoint, { | ||
| method: "POST", | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body: JSON.stringify({ | ||
| model, | ||
| text: req.text, | ||
| stream: false, | ||
| output_format: "hex", | ||
| voice_setting: { voice_id: voice }, | ||
| }), | ||
| signal: AbortSignal.timeout(req.timeoutMs), | ||
| }); | ||
| if (!response.ok) | ||
| throw new Error(`MiniMax TTS request failed (${response.status})`); | ||
| const payload = (await response.json()) as { | ||
| data?: { audio?: string }; | ||
| base_resp?: { status_code?: number }; | ||
| }; | ||
| if ( | ||
| payload.base_resp?.status_code && | ||
| payload.base_resp.status_code !== 0 | ||
| ) { | ||
| throw new Error( | ||
| `MiniMax TTS request failed (${payload.base_resp.status_code})`, | ||
| ); | ||
| } | ||
| if (!payload.data?.audio) | ||
| throw new Error("MiniMax TTS response did not include audio"); | ||
| return { | ||
| audioBuffer: Buffer.from(payload.data.audio, "hex"), | ||
| outputFormat: "mp3", | ||
| fileExtension: ".mp3", | ||
| voiceCompatible: false, | ||
| }; | ||
| }, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: linuxhsj/openclaw-zero-token
Length of output: 50384
🏁 Script executed:
Repository: linuxhsj/openclaw-zero-token
Length of output: 5391
在解码前验证十六进制音频。
如果
data.audio不是字符串、包含非十六进制字符,或长度为奇数,请在调用Buffer.from(audio, "hex")前抛出错误。Node.js 会静默截断这些输入,导致调用方收到损坏的 MP3 音频。🤖 Prompt for AI Agents