47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
import { ensureAppConfigReady } from "../config/videoPipeline.js";
|
|
import { formatVoiceIdWithPrefix } from "../utils/voiceIdPrefix.js";
|
|
|
|
const VOICE_CLONE_ENROLL_SCRIPT = "voice_clone_enroll.js";
|
|
|
|
/**
|
|
* @param {{ name: string, audioPath: string, existingVoiceId?: string }} opts
|
|
*/
|
|
export async function enrollCloneVoice(opts) {
|
|
const name = String(opts.name || "").trim();
|
|
const audioPath = String(opts.audioPath || "").trim();
|
|
if (!name) return { ok: false, message: "请先输入音色名称" };
|
|
if (!audioPath) return { ok: false, message: "请先录制或上传参考声音" };
|
|
|
|
const cfg = await ensureAppConfigReady();
|
|
if (!cfg.ok) return { ok: false, message: cfg.message };
|
|
|
|
try {
|
|
const result = await invoke("run_nodejs_script", {
|
|
scriptName: VOICE_CLONE_ENROLL_SCRIPT,
|
|
params: { audioPath, name },
|
|
});
|
|
|
|
if (!result?.success || !result?.voiceId) {
|
|
return {
|
|
ok: false,
|
|
message: String(result?.error || "复刻失败,请重试"),
|
|
};
|
|
}
|
|
|
|
const voiceId = formatVoiceIdWithPrefix(
|
|
result.voiceId,
|
|
opts.existingVoiceId || result.voiceId,
|
|
);
|
|
return {
|
|
ok: true,
|
|
voiceId,
|
|
message: "复刻成功!音色 ID 已自动填入",
|
|
};
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err || "未知错误");
|
|
return { ok: false, message: `调用复刻服务异常:${msg}` };
|
|
}
|
|
}
|