使用網絡音頻API的音調變送器? [英] pitch shifter using web-audio-api?
本文介紹了使用網絡音頻API的音調變送器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
使用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
。
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="https://unpkg.com/tone@13.8.25/build/Tone.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>
這篇關于使用網絡音頻API的音調變送器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持IT屋!
查看全文