Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用网络音频api的音高变换器?_Javascript_Node.js_Web Audio Api_Pitch Shifting - Fatal编程技术网

Javascript 使用网络音频api的音高变换器?

Javascript 使用网络音频api的音高变换器?,javascript,node.js,web-audio-api,pitch-shifting,Javascript,Node.js,Web Audio Api,Pitch Shifting,使用节点js的音调移位器 嗨,我是一个网络开发的初学者 所以我正在尝试建立一个在线音频播放器,我需要一个音高变换器 我试图学习网络音频API,这对我来说并不容易理解 任何人都可以帮助建立一个“音高变换器”使用节点js。。。或建议资源学习网络音频API 为什么这段代码在NodeJS中不起作用 var audioCtx=new(window.AudioContext | | window.webkitadiocontext)()很遗憾,Node.js上没有Web音频API。js只是一个JavaScr

使用节点js的音调移位器

嗨,我是一个网络开发的初学者

所以我正在尝试建立一个在线音频播放器,我需要一个音高变换器

我试图学习网络音频API,这对我来说并不容易理解

任何人都可以帮助建立一个“音高变换器”使用节点js。。。或建议资源学习网络音频API

为什么这段代码在NodeJS中不起作用


var audioCtx=new(window.AudioContext | | window.webkitadiocontext)()

很遗憾,Node.js上没有Web音频API。js只是一个JavaScript运行时,Web音频API不是JavaScript本身的一部分。它是由浏览器添加的API。Node.js中甚至没有
窗口

为了让事情变得更加混乱,Node.js中也提供了一些浏览器API。例如,全球可用的
URL
。在这几年里,张若怡(Joyee Cheung)给出了。但是,Web音频API不在列表中

在Node.js中提供Web音频API是否有意义仍有争议,但这肯定是可能的。至少在一定程度上,如和项目所示

如果您想在浏览器中实现PitchShifter,可以使用随附的。下面是一个简单的例子:

<!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>

开始
向上的
向下
const$startStopButton=document.getElementById('start-stop');
const$upButton=document.getElementById('up');
const$downButton=document.getElementById('down');
常量振荡器=新音调振荡器();
const pitchShift=新音调。pitchShift();
振荡器。连接(俯仰位移);
pitchShift.toMaster();
$startStopButton.onclick=()=>{
如果($startStopButton.textContent=='start'){
$startStopButton.textContent='stop';
start();
}否则{
$startStopButton.textContent='start';
振荡器。停止();
}
};
$upButton.onclick=()=>pitchShift.pitch+=1;
$downButton.onclick=()=>pitchShift.pitch-=1;

谢谢您的回复,克里斯!我对你的回答很满意。您知道如何在tone js中创建3d效果吗?官方文档中有一个空间化示例()。您好,我对在web上制作音频应用程序感兴趣,所以我需要将音高变换器连接到web音频API!所以你上面的代码可以工作,但我需要将其连接到web audio API的音频上下文,有什么方法吗?如果还有什么,请帮帮我,伙计!谢谢你把这变成一个单独的问题。我认为这是更好的方法,因为它与原始问题没有太多共同之处。它让其他人更容易找到它。