TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Decode audio files in the browser without insane memory usage

1 点作者 aeroheim超过 4 年前

1 comment

aeroheim超过 4 年前
hi HN!<p>I&#x27;ve been working in the browser audio domain recently and noticed to my surprise that WebAudio has no way to decode audio files efficiently. WebAudio has no support for partial decoding and can only decode entire audio files upfront which results in huge CPU and memory usage.<p>For example, decoding a typical stereo 44.1 KHz 1-hour long audio file (e.g a podcast) into uncompressed floating point samples would consume (3600s * 44100Hz * 4 bytes * 2 channels) = ~1.27 GB of memory. <i>Nice</i><p>Obviously this isn&#x27;t acceptable so I ended up creating this library to work around this issue. I ported FFmpeg over to WASM using Emscripten (a painful process) and then implemented an audio decoder with support for partial decoding. I hope this library can help anyone else with the same issue or at least serve as an additional reference for those looking to roll their own WASM-based workarounds.<p>Thanks for taking a look!<p>P.S: extra info&#x2F;ranting about WebAudio below for those interested<p>Others have already pointed out this glaring issue in the WebAudio API: <a href="https:&#x2F;&#x2F;github.com&#x2F;WebAudio&#x2F;web-audio-api&#x2F;issues&#x2F;1305" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WebAudio&#x2F;web-audio-api&#x2F;issues&#x2F;1305</a><p>But it&#x27;s sad to see that so many libraries&#x2F;applications out there still rely on it such as: <a href="https:&#x2F;&#x2F;github.com&#x2F;bbc&#x2F;waveform-data.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bbc&#x2F;waveform-data.js</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;katspaugh&#x2F;wavesurfer.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;katspaugh&#x2F;wavesurfer.js</a><p>Thankfully this issue should hopefully be addressed whenever WebCodecs is standardized and implemented: <a href="https:&#x2F;&#x2F;github.com&#x2F;WICG&#x2F;web-codecs&#x2F;issues&#x2F;28" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WICG&#x2F;web-codecs&#x2F;issues&#x2F;28</a><p>But until then it&#x27;s quite disappointing that developers have to go as far as rolling their own WASM-based solution just to work around the WebAudio API. I&#x27;ve heard unpleasant things about WebAudio and came in with zero expectations and yet was still disappointed. ¯\_(ツ)_&#x2F;¯