使用网络音频API的音调变送器?
- 作者: 麦克斯甜点屋
- 来源: 51数据库
- 2022-10-19
问题描述
使用Node js的音调转换器
您好,我是Web开发的初学者!
我正在尝试建立一个在线音频播放器,为此我需要一个音调变送器。我试着学习Web音频API,这对我来说不是很容易理解...
有没有人能用节点js帮助建立一个"音调移位器"……或建议学习Web音频API的资源...
为什么此代码在节点js中不起作用?
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
推荐答案
遗憾的是,网络音频API在Node.js上不可用。Js只是一个JavaScript运行时,Web Audio API不是JavaScript本身的一部分。它是由浏览器添加的API。Node.js中甚至没有window。
更令人困惑的是,Node.js中还提供了一些浏览器API。全球可用的URL就是一个例子。在这一年,JSConf.eu张祖儿给了a talk explaining the strategy behind bringing more browser APIs to Node.js。但是,Web Audio API不在列表中。在Node.js中提供Web Audio API是否有意义还有待商榷,但这当然是可能的。至少在一定程度上,如web-audio-api和web-audio-engine项目所示。
如果要在浏览器中实现PitchShifter,可以使用Tone.js附带的PitchShift Effect。下面是一个最小的例子:<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<button id="start-stop">start</button>
<button id="up">up</button>
<button id="down">down</button>
<script src="http://www.51sjk.com/Upload/Articles/1/0/331/331395_20221019170320492.js"></script>
<script>
const $startStopButton = document.getElementById('start-stop');
const $upButton = document.getElementById('up');
const $downButton = document.getElementById('down');
const oscillator = new Tone.Oscillator();
const pitchShift = new Tone.PitchShift();
oscillator.connect(pitchShift);
pitchShift.toMaster();
$startStopButton.onclick = () => {
if ($startStopButton.textContent === 'start') {
$startStopButton.textContent = 'stop';
oscillator.start();
} else {
$startStopButton.textContent = 'start';
oscillator.stop();
}
};
$upButton.onclick = () => pitchShift.pitch += 1;
$downButton.onclick = () => pitchShift.pitch -= 1;
</script>
</body>
</html>
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
