微信小程序本地如何加载rnnoise.wasm? 文件为https://github.com/jitsi/rnnoise-wasm/tree/master/dist下载所得
// rnnoise.js(最终版)
export function load() {
return new Promise((resolve, reject) => {
const path = `${wx.env.USER_DATA_PATH}/../rnnoise.wasm`; // 无论文件目录怎么改都不行。
wx.getFileSystemManager().readFile({
filePath: path,
success(res) {
const bytes = new Uint8Array(res.data);
WXWebAssembly.instantiate(bytes, {})
.then(({ instance }) => resolve(instance.exports))
.catch(reject);
},
fail: reject
});
});
}
-------------------------------------
const fs = wx.getFileSystemManager();
const wasmFilePath = `${wx.env.USER_DATA_PATH}/rnnoise.wasm`; // 确保路径正确
// 检查文件是否存在
fs.access({
path: wasmFilePath,
success: () => {
// 文件存在,读取文件
fs.readFile({
filePath: wasmFilePath,
encoding: 'binary',
success: (res) => {
const wasmBuffer = res.data;
this.initializeWasm(wasmBuffer);
},
fail: (err) => {
wx.showToast({
title: '读取文件失败',
icon: 'none',
});
console.error('读取文件失败', err);
},
});
},
fail: () => {
wx.showToast({
title: '文件不存在,请检查路径',
icon: 'none',
});
console.error('文件不存在,请检查路径');
},
});
提示:'文件不存在,请检查路径'

死气沉沉的,一般发了都石沉大海。