npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dao3fun/volume-processor

v1.0.0

Published

用于实时和静态分析WAV音频文件的音量。它提供了从WAV文件中提取元数据和计算详细音量指标(包括平均音量、峰值音量和RMS音量)的功能。

Downloads

4

Readme

神岛客户端音量分析器

一个轻量级的TypeScript库,用于实时和静态分析WAV音频文件的音量。它提供了从WAV文件中提取元数据和计算详细音量指标(包括平均音量、峰值音量和RMS音量)的功能。

典型应用场景:

  • 音量监控:音量越大,玩家跑得越快。
  • 音量分析:分析音频文件的音量特征,用于音频处理和分析。

核心功能

  • 元数据提取:从WAV文件中解析采样率、通道数、位深度和持续时间。
  • 高级音量分析:计算平均音量、峰值音量和均方根(RMS)音量。
  • 实时处理:提供 VolumeProcessor 类,用于从媒体流中进行连续的实时音量监控。
  • 纯TypeScript:使用TypeScript编写,提供完整的类型定义,易于在现代项目中使用。
  • 零依赖:不依赖任何第三方库。

安装

npm install @dao3fun/volume-processor

使用方法

1. 静态分析:分析单个WAV文件

如果你有一个WAV文件的 Blob 对象,你可以使用 WavParser 来获取完整的音频分析。

import { WavParser, type AudioAnalysis } from '@dao3fun/volume-processor';

async function analyzeWavFile(wavBlob: Blob) {
  try {
    const analysis: AudioAnalysis = await WavParser.analyze(wavBlob);

    // 打印元数据
    console.log('元数据:', analysis.metadata);
    // 打印音量指标
    console.log('音量指标:', analysis.volume);
  } catch (error) {
    console.error('分析失败:', error);
  }
}

2. 实时音量监控

VolumeProcessor 类可以持续从一个全局可用的 media 对象中捕捉音频,并按设定的时间间隔提供音量反馈。

import { VolumeProcessor, type VolumeMetrics } from '@dao3fun/volume-processor';

// 1. 定义一个回调函数来处理音量数据
const handleVolumeMetrics = (metrics: VolumeMetrics) => {
  console.log(
    `实时音量 - 平均: ${metrics.average.toFixed(4)}, 峰值: ${metrics.peak.toFixed(4)}, RMS: ${metrics.rms.toFixed(4)}`
  );
};

// 2. 创建VolumeProcessor实例
// 每500毫秒处理一次音频
const volumeProcessor = new VolumeProcessor(handleVolumeMetrics, 500);

// 3. 启动监控
volumeProcessor.start();

// 4. 在适当的时候停止监控
setTimeout(() => {
  volumeProcessor.stop();
  console.log('音量监控已停止。');
}, 10000); // 10秒后停止

API 参考

WavParser

一个静态类,用于解析WAV文件。

  • WavParser.analyze(blob: Blob): Promise<AudioAnalysis> 返回一个包含元数据和音量指标的完整分析对象。

  • WavParser.parseMetadata(blob: Blob): Promise<WavMetadata> 只从WAV文件中提取元数据。

  • WavParser.parseVolumeMetrics(blob: Blob): Promise<VolumeMetrics> 只从WAV文件中计算音量指标。

VolumeProcessor

一个用于实时音量监控的类。

  • constructor(onVolumeMetrics: (metrics: VolumeMetrics) => void, interval?: number) 创建一个新的 VolumeProcessor 实例。

    • onVolumeMetrics: 每次计算出新的音量指标时调用的回调函数。
    • interval: 处理音频的时间间隔(毫秒,默认为500)。
  • start(): void 启动连续的音量监控。

  • stop(): void 停止音量监控。