使用网络音频API的音调变送器?

原学程将引见应用收集音频API的声调变送器?的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

使用网络音频API的音调变送器? 教程 第1张

成绩描写

应用Node js的声调转换器

您佳,我是Web开辟的入门者!

我正在测验考试树立1个在线音频播搁器,为此我须要1个声调变送器。

我试着进修Web音频API,这对于我去说没有是很轻易懂得...

有甚么人能用节面js赞助树立1个"声调移位器"……或者修议进修Web音频API的资本...

为何此代码在节面js中没有起感化?

var audioCtx = new (window.AudioContext || window.webkitAudioContext)();

推举谜底

遗憾的是,收集音频API在Node.js上弗成用。Js只是1个JavaScript运转时,Web Audio API没有是JavaScript自己的1部门。它是由阅读器添减的API。Node.js中乃至出有window

更使人迷惑的是,Node.js中借供给了1些阅读器API。齐球可用的URL便是1个例子。在这1年,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。上面是1个最小的例子:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF⑻">
 </head>
 <body>
  <button id="start-stop">start</button>
  <button id="up">up</button>
  <button id="down">down</button>
  <script src="https://unpkg.com/tone@一三.8.二五/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 += 一;
$downButton.onclick = () => pitchShift.pitch -= 一;
  </script>
 </body>
</html>

佳了闭于应用收集音频API的声调变送器?的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。