想要把 https://github.com/surikov/webaudiofont 这个库移植 微信小程序
微信程序 npm 包的限制
https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
如果是已经发布过的一些 npm 包,因为一些原因无法改造成小程序 npm 包的结构的话,也可以通过微调后被使用,但是请确保遵循以下几点:
-
不支持依赖于 Node.js 内置库的包
-
不支持依赖于浏览器内置对象的包
-
不支持依赖于 C++ 插件的包
https://www.w3schools.com/nodejs/ref_modules.asp
小程序环境比较特殊,一些全局变量(如 window 对象)和构造器(如 Function 构造器)是无法使用的。
搞定了
webaudiofont 在小程序中可以使用了
https://github.com/pencilCool/mp/blob/master/OrignalMP/pages/index/webaudiofont.js
记录改造 webaudiofont 遇到的问题
不传 errfunc ,decodeAudioData 在iOS 真机上不起作用
const errfunc = function(err) {
console.log("err(decodeAudioData): "+err);
}
audioContext.decodeAudioData(arraybuffer, function (audioBuffer) {
zone.buffer = audioBuffer;
},errfunc);
atob 在IOS 上不起作用,自己实现一遍
参考: https://github.com/equicy/weapp-jwt-decode/blob/master/weapp-jwt.js
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
const atob = function (string) {
string = String(string).replace(/[\t\n\f\r ]+/g, "");
if (!b64re.test(string))
throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
string += "==".slice(2 - (string.length & 3));
var bitmap, result = "", r1, r2, i = 0;
for (; i < string.length;) {
bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12 |
(r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) :
r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) :
String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
}
return result;
};
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix