refactor(microsoft): use node-edge-tts declarations

This commit is contained in:
Peter Steinberger
2026-07-13 21:04:52 +01:00
parent 56c7414924
commit 3d64e6fd7c
2 changed files with 5 additions and 52 deletions

View File

@@ -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,

View File

@@ -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;
}