Spaces:
Running
Running
more powerful model
Browse files- index.html +51 -44
index.html
CHANGED
|
@@ -63,60 +63,67 @@
|
|
| 63 |
|
| 64 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
const msg = e.data;
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
}
|
| 90 |
}
|
| 91 |
-
}
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
}
|
| 97 |
}
|
|
|
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
//
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
self.postMessage({ type: 'result', text: output.text });
|
| 115 |
-
} catch (err) {
|
| 116 |
-
self.postMessage({ type: 'error', error: err.message });
|
| 117 |
-
}
|
| 118 |
}
|
| 119 |
-
}
|
|
|
|
| 120 |
</script>
|
| 121 |
|
| 122 |
<script type="module">
|
|
|
|
| 63 |
|
| 64 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
|
| 65 |
|
| 66 |
+
// 允许缓存
|
| 67 |
+
env.allowLocalModels = false;
|
| 68 |
+
env.useBrowserCache = true;
|
| 69 |
|
| 70 |
+
let transcriber = null;
|
| 71 |
|
| 72 |
+
self.onmessage = async (e) => {
|
| 73 |
+
const msg = e.data;
|
|
|
|
| 74 |
|
| 75 |
+
if (msg.type === 'load') {
|
| 76 |
+
try {
|
| 77 |
+
self.postMessage({ type: 'status', text: '⏳ 正在加载 Whisper-Base (更聪明版)...' });
|
| 78 |
+
|
| 79 |
+
// 🔴 改动 1: 从 tiny 换成 base,更不容易发疯
|
| 80 |
+
transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-base', {
|
| 81 |
+
progress_callback: (data) => {
|
| 82 |
+
if (data.status === 'progress') {
|
| 83 |
+
self.postMessage({
|
| 84 |
+
type: 'download_progress',
|
| 85 |
+
percent: Math.round((data.loaded / data.total) * 100),
|
| 86 |
+
file: data.file
|
| 87 |
+
});
|
|
|
|
| 88 |
}
|
| 89 |
+
}
|
| 90 |
+
});
|
| 91 |
|
| 92 |
+
self.postMessage({ type: 'ready' });
|
| 93 |
+
} catch (err) {
|
| 94 |
+
self.postMessage({ type: 'error', error: err.message });
|
|
|
|
| 95 |
}
|
| 96 |
+
}
|
| 97 |
|
| 98 |
+
if (msg.type === 'run') {
|
| 99 |
+
if (!transcriber) return;
|
| 100 |
+
|
| 101 |
+
try {
|
| 102 |
+
self.postMessage({ type: 'status', text: '🚀 正在分析长音频 (已开启防幻觉)...' });
|
| 103 |
|
| 104 |
+
// 开始推理
|
| 105 |
+
const output = await transcriber(msg.audio, {
|
| 106 |
+
// 基础设置
|
| 107 |
+
chunk_length_s: 30,
|
| 108 |
+
stride_length_s: 5,
|
| 109 |
+
task: 'transcribe',
|
| 110 |
+
language: msg.language !== 'auto' ? msg.language : undefined,
|
| 111 |
+
|
| 112 |
+
// 🔴 改动 2: 关键参数优化
|
| 113 |
+
return_timestamps: true, // 强制让模型对齐时间轴,能极大减少乱说
|
| 114 |
+
no_repeat_ngram_size: 2, // 强行禁止连续重复 2 个词以上的短语
|
| 115 |
|
| 116 |
+
// 🔴 改动 3: 温度设置 (Temperature)
|
| 117 |
+
// 0 代表最冷静、最严谨。默认可能是随机的,导致它乱猜。
|
| 118 |
+
temperature: 0,
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
self.postMessage({ type: 'result', text: output.text });
|
| 122 |
+
} catch (err) {
|
| 123 |
+
self.postMessage({ type: 'error', error: err.message });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
}
|
| 125 |
+
}
|
| 126 |
+
};
|
| 127 |
</script>
|
| 128 |
|
| 129 |
<script type="module">
|