简体   繁体   English

如何捕获在我的应用程序中播放的音频流,然后将其用作 Web Audio API 的有效输入以进行可视化?

[英]How can I capture an audio stream playing in my application, and then it use it as a valid input for Web Audio API for visualization?

I am building an app that I want to be able to capture browser audio from say Spotify or YT.我正在构建一个应用程序,我希望能够从 Spotify 或 YT 中捕获浏览器音频。 And then make it so that I can turn it into a live stream to input into Web Audio API to create visuals while the audio plays.然后制作它,以便我可以将其转换为实时流以输入到 Web Audio API 以在音频播放时创建视觉效果。 I've came across technologies like Jack and MediaCapture API but wanted to know if anyone has an efficient approach.我遇到过 Jack 和 MediaCapture API 等技术,但想知道是否有人有有效的方法。 Any ideas and suggestions are appreciated greatly.非常感谢任何想法和建议。

UPDATE:更新:

Was able to get my audio to stream in my application's tab.能够让我的音频在我的应用程序选项卡中流式传输。 I am looking for an approach on how to capture the audio to analyze it.我正在寻找一种关于如何捕获音频来分析它的方法。 I've seen a method where it can be captured through microphone hardware, but I wanted to capture just the audio without any interfering noises.我见过一种可以通过麦克风硬件捕获它的方法,但我想只捕获音频而没有任何干扰噪音。

You can use getDisplayMedia() to get a MediaStream from other tabs, but this is subject to browser support.您可以使用getDisplayMedia()从其他选项卡获取 MediaStream,但这取决于浏览器的支持。 Chromium-based browsers support this, but others are less compatible at the moment.基于 Chromium 的浏览器支持这一点,但目前其他浏览器的兼容性较差。

Additionally, the UX isn't very good.此外,用户体验不是很好。 It depends on the user first choosing that they want to capture another tab, checking a box to share that tab's audio, and then continuing.这取决于用户首先选择他们想要捕获另一个选项卡,选中一个框以共享该选项卡的音频,然后继续。 Also, you need to then stop the video track you get back.此外,您还需要停止返回的视频轨道。

You might consider participating in these discussions to push for better browser support:您可以考虑参与这些讨论以推动更好的浏览器支持:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM