1
This commit is contained in:
@@ -13,8 +13,24 @@ const { VideoRewriteOptimizer } = require("./video_rewrite_optimizer.js");
|
||||
const pipelineNative = require("./pipeline_native.js");
|
||||
const desktopConfig = require("./desktop_config.js");
|
||||
|
||||
const log = (level, msg, fields) =>
|
||||
globalThis.__native.log(level, msg, fields == null ? null : fields);
|
||||
/**
|
||||
* Tauri 子进程内请用 __native.log(stderr __EVT__ → Rust → nodejs:event)。
|
||||
* console.* 被管道接管,不会出现在 tauri dev 终端;仅在没有 __native 时回退到控制台。
|
||||
*/
|
||||
const log = (level, msg, fields) => {
|
||||
if (globalThis.__native?.log) {
|
||||
globalThis.__native.log(level, msg, fields == null ? null : fields);
|
||||
return;
|
||||
}
|
||||
const tag = `[pipeline.${level}] ${msg}`;
|
||||
if (fields != null) {
|
||||
if (level === "error") console.error(tag, fields);
|
||||
else if (level === "warn") console.warn(tag, fields);
|
||||
else console.log(tag, fields);
|
||||
} else if (level === "error") console.error(tag);
|
||||
else if (level === "warn") console.warn(tag);
|
||||
else console.log(tag);
|
||||
};
|
||||
const progress = (s) => {
|
||||
try {
|
||||
globalThis.__native.emitProgress(s);
|
||||
@@ -120,7 +136,7 @@ async function processDouyinShareComplete(
|
||||
error: `音频上传失败: ${upload?.error || "unknown"}`,
|
||||
};
|
||||
}
|
||||
log("info", "pipeline.ossOk", { audioUrl: upload.url.slice(0, 80) });
|
||||
log("info", "pipeline.ossOk", { audioUrl: upload.url });
|
||||
|
||||
progress("音频上传完成,正在识别文案(在线模式)...");
|
||||
const asr = await pipelineNative.aliyunAsrFiletrans(upload.url, {
|
||||
|
||||
@@ -15,6 +15,28 @@ const http = require("http");
|
||||
const TEMP_DIR = path.join(os.tmpdir(), "aiclient-node-pipeline");
|
||||
fs.mkdirSync(TEMP_DIR, { recursive: true });
|
||||
|
||||
/** Tauri 子进程优先 __native.log;独立 node 调试时回退 console */
|
||||
function log(level, msg, fields) {
|
||||
const payload =
|
||||
fields == null
|
||||
? null
|
||||
: typeof fields === "object" && !Array.isArray(fields)
|
||||
? fields
|
||||
: { value: fields };
|
||||
if (globalThis.__native?.log) {
|
||||
globalThis.__native.log(level, msg, payload);
|
||||
return;
|
||||
}
|
||||
const tag = `[pipeline_native.${level}] ${msg}`;
|
||||
if (payload != null) {
|
||||
if (level === "error") console.error(tag, payload);
|
||||
else if (level === "warn") console.warn(tag, payload);
|
||||
else console.log(tag, payload);
|
||||
} else if (level === "error") console.error(tag);
|
||||
else if (level === "warn") console.warn(tag);
|
||||
else console.log(tag);
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((r) => setTimeout(r, ms));
|
||||
}
|
||||
@@ -207,6 +229,9 @@ async function fetchJson(url, options = {}) {
|
||||
async function aliyunAsrFiletrans(audioUrl, opts) {
|
||||
const apiKey = opts.apiKey || opts.api_key;
|
||||
const model = opts.model || "qwen3-asr-flash-filetrans";
|
||||
log("info", "apiKey",apiKey);
|
||||
log("info", "model",model);
|
||||
log("info", "audioUrl",audioUrl);
|
||||
if (!apiKey) {
|
||||
return { success: false, error: "缺少 DashScope apiKey" };
|
||||
}
|
||||
@@ -222,7 +247,12 @@ async function aliyunAsrFiletrans(audioUrl, opts) {
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
input: { file_urls: [audioUrl] },
|
||||
parameters: {},
|
||||
parameters: {
|
||||
channel_id: [0],
|
||||
// 音频通道ID
|
||||
enable_itn: false
|
||||
// 是否启用逆文本归一化
|
||||
}
|
||||
}),
|
||||
}
|
||||
);
|
||||
@@ -230,7 +260,7 @@ async function aliyunAsrFiletrans(audioUrl, opts) {
|
||||
if (!taskId) {
|
||||
return { success: false, error: `ASR 提交失败: ${JSON.stringify(submit).slice(0, 200)}` };
|
||||
}
|
||||
|
||||
log("info", "voice recognition taskId",taskId);
|
||||
for (let i = 0; i < 60; i++) {
|
||||
await sleep(5000);
|
||||
const poll = await fetchJson(
|
||||
@@ -238,9 +268,11 @@ async function aliyunAsrFiletrans(audioUrl, opts) {
|
||||
{ headers: { Authorization: `Bearer ${apiKey}` } }
|
||||
);
|
||||
const status = poll?.output?.task_status;
|
||||
log("info", "voice recognition status",status);
|
||||
if (status === "SUCCEEDED") {
|
||||
const transUrl = poll?.output?.results?.[0]?.transcription_url;
|
||||
if (!transUrl) {
|
||||
log("error", "voice recognition transUrl",transUrl);
|
||||
return { success: false, error: "ASR 成功但无 transcription_url" };
|
||||
}
|
||||
const trans = await fetchJson(transUrl);
|
||||
|
||||
Reference in New Issue
Block a user