1
This commit is contained in:
@@ -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