Node.js - 让 Node.js/Express 与网络音频一起工作 API

Node.js - Having Node.js/Express work with Web Audio API

我正在编写需要使用网络音频 API 的节点。js/Express。由于 . However, I've found two projects online that seem to me to use Node.js/Express as well as the Web Audio API. They can be found here and here 中解释的原因,我注意到这实际上是 'not possible'。当我尝试在我的应用程序中做类似的事情时(运行 使用 npm start 我收到以下错误:

/Users/user/Documents/STAGE4/PRCO304/RTMC/controllers/workstation/workstation.js:1
(function (exports, require, module, __filename, __dirname) { var context = new AudioContext();
                                                                                  ^

ReferenceError: AudioContext is not defined

当我将 var context = new AudioContext(); 行更改为 window.AudioContext = window.AudioContext 之类的内容时,我收到 window 未定义的错误,我将其理解为 Node.js 的工作方式.

有人可以向我解释一下这两个项目是如何设法将 Web Audio API 与 Node.js/Express 一起使用的吗?当我尝试在我的项目中实现类似的东西时却失败了?

提前致谢。

Web Audio API 在浏览器端,融入现代浏览器中,没有明确引入任何库。当然,nodejs 是服务器端,因此您需要自己编写或发现某人所在的节点包已使用其 published specs , for use directly on the nodejs platform, that is if you want a stand alone nodejs server based audio rendering project, independent of any browser. The mentions a npm module using this approach

移植网络音频 API

您当然可以将您的系统设计为仅互连服务器和浏览器,这在今天非常可行,也是大多数人在将节点与音频结合时采用的路线。

你还没说清楚你喜欢哪种架构???

nodejs 当然可以在任何一种体系结构中与 Web Audio API 一起使用,我已经使用每种方法编写了项目

我猜你上面的错误是试图执行不与浏览器对话的服务器端代码?在这种情况下,请确保您正在使用 nodejs 移植的 Web Audio API library