mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-22 03:31:46 +00:00
refactor(microsoft): use node-edge-tts declarations
This commit is contained in:
@@ -5,29 +5,12 @@ import path from "node:path";
|
||||
import { writeExternalFileWithinRoot } from "openclaw/plugin-sdk/security-runtime";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
|
||||
type EdgeTTSRuntimeConfig = {
|
||||
voice?: string;
|
||||
lang?: string;
|
||||
outputFormat?: string;
|
||||
saveSubtitles?: boolean;
|
||||
proxy?: string;
|
||||
rate?: string;
|
||||
pitch?: string;
|
||||
volume?: string;
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
type EdgeTTSDeps = {
|
||||
EdgeTTS: new (config: EdgeTTSRuntimeConfig) => {
|
||||
ttsPromise: (text: string, outputPath: string) => Promise<unknown>;
|
||||
};
|
||||
EdgeTTS: new (
|
||||
...args: ConstructorParameters<typeof import("node-edge-tts").EdgeTTS>
|
||||
) => Pick<import("node-edge-tts").EdgeTTS, "ttsPromise">;
|
||||
};
|
||||
|
||||
async function loadDefaultEdgeTTSDeps(): Promise<EdgeTTSDeps> {
|
||||
const { EdgeTTS } = await import("node-edge-tts");
|
||||
return { EdgeTTS };
|
||||
}
|
||||
|
||||
function isMissingOutputFileError(error: unknown): boolean {
|
||||
return (
|
||||
typeof error === "object" &&
|
||||
@@ -89,8 +72,8 @@ export async function edgeTTS(
|
||||
throw new Error("Microsoft TTS text cannot be empty");
|
||||
}
|
||||
|
||||
const resolvedDeps = deps ?? (await loadDefaultEdgeTTSDeps());
|
||||
const tts = new resolvedDeps.EdgeTTS({
|
||||
const EdgeTTSClass = deps?.EdgeTTS ?? (await import("node-edge-tts")).EdgeTTS;
|
||||
const tts = new EdgeTTSClass({
|
||||
voice: config.voice,
|
||||
lang: config.lang,
|
||||
outputFormat: config.outputFormat,
|
||||
|
||||
30
src/types/node-edge-tts.d.ts
vendored
30
src/types/node-edge-tts.d.ts
vendored
@@ -1,30 +0,0 @@
|
||||
/** Minimal ambient types for node-edge-tts voice synthesis. */
|
||||
declare module "node-edge-tts" {
|
||||
/** Options passed to the Edge TTS wrapper. */
|
||||
export type EdgeTTSOptions = {
|
||||
voice?: string;
|
||||
lang?: string;
|
||||
outputFormat?: string;
|
||||
saveSubtitles?: boolean;
|
||||
proxy?: string;
|
||||
rate?: string;
|
||||
pitch?: string;
|
||||
volume?: string;
|
||||
timeout?: number;
|
||||
};
|
||||
|
||||
/** Edge TTS class subset used by OpenClaw audio generation. */
|
||||
export class EdgeTTS {
|
||||
constructor(options?: EdgeTTSOptions);
|
||||
ttsPromise(text: string, outputPath: string): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "node-edge-tts/dist/drm.js" {
|
||||
/** Chromium version constant required by the upstream token generator. */
|
||||
export const CHROMIUM_FULL_VERSION: string;
|
||||
/** Trusted client token required by the upstream token generator. */
|
||||
export const TRUSTED_CLIENT_TOKEN: string;
|
||||
/** Generate the DRM token needed by Edge TTS requests. */
|
||||
export function generateSecMsGecToken(): string;
|
||||
}
|
||||
Reference in New Issue
Block a user