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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wav-file-processor

v1.0.4

Published

Intercepts wav file tail audio

Downloads

11

Readme

WAV File Processor

该模块提供了处理 WAV 音频文件的实用工具。通过这个模块,你可以对 WAV 文件进行裁剪,以及读取和写入文件的操作。

Features

  • 通过设定的时长来裁剪音频文件的末尾部分
  • 固定末尾保留的静默时间做裁剪
  • 通过文件名称获取 WAV 文件信息
  • 以 Buffer 的形式读取文件内容
  • 将数据以 Buffer 的形式写入到文件中

How to Use

首先,你需要将该模块安装到你的项目中:

npm install wav-file-processor

然后,在你的代码文件中 import 后就可以使用:

import * as wavProcessor from "wav-file-processor";

// 裁剪文件的末尾
wavProcessor.trimWavByTime(source, size, target);
// 获取文件信息
const info = await wavProcessor.getInfoByFilename(filename);
// 读取文件内容
const data = await wavProcessor.readFile(filename);
// 将数据写入到文件中
await wavProcessor.writeFile(filename, data);

API

getInfoByFilename

获取指定 WAV 文件的信息。

Syntax:

getInfoByFilename(filename: string): Promise<any>

Parameters:

  • filename (string): 要获取信息的 WAV 文件的名称。

Return value:

返回一个 Promise 对象,该对象将解析为包含指定 WAV 文件信息的对象。

trimWavByTime

通过设定的时长来裁剪音频文件的末尾部分。

Syntax:

trimWavByTime(source: string, size?: number, target?: string): Promise<void>

Parameters:

  • source (string): 作为输入的音频文件路径。
  • size (number): 要裁剪的时长,以秒为单位。
  • target (string): 裁剪后音频的保存路径,如未指定则覆盖源文件。

Return value:

返回一个 Promise 对象,当音频文件被成功裁剪后,该 Promise 对象将会被解析。

// 导入该模块
import * as wavProcessor from "wav-file-processor";

// 使用 trimWavByTime 方法来裁剪音频文件的末尾部分
wavProcessor
  .trimWavByTime("source.wav", 10, "target.wav")
  .then(() => {
    console.log("音频文件裁剪完成");
  })
  .catch((error) => {
    console.error("音频文件裁剪时发生错误: ", error);
  });

trimTailSilence

固定末尾保留的静默时长做裁剪。

Syntax:

trimTailSilence(source: string, silenceTime?: number, target?: string): Promise<void>

Parameters:

  • source (string): 作为输入的音频文件路径。
  • silenceTime (number): 保留的静默时长,以秒为单位。其余部分将被裁剪掉。
  • target (string): 裁剪后的音频的保存路径,如未指定则覆盖源文件。

Return value:

返回一个 Promise 对象,当音频文件被成功裁剪后,该 Promise 对象将会被解析。

// 使用 trimTailSilence 方法来固定末尾保留的静默时长做裁剪
wavProcessor
  .trimTailSilence("source.wav", 5, "target.wav")
  .then(() => {
    console.log("音频文件裁剪完成");
  })
  .catch((error) => {
    console.error("音频文件裁剪时发生错误: ", error);
  });

readFile

读取指定文件的内容。

Syntax:

readFile(filename: string): Promise<Buffer>

Parameters:

  • filename (string): 要读取的文件的名称。

Return value:

返回一个 Promise 对象,该对象将解析为一个 Buffer,该 Buffer 包含指定文件的内容。

writeFile

将 Buffer 数据写入到指定的文件中。

Syntax:

writeFile(filename: string, data: Buffer): Promise<void>

Parameters:

  • filename (string): 需要接收数据的文件的名称。
  • data (Buffer): 需要写入的数据。

Return value:

返回一个 Promise 对象,当数据被成功写入文件后,该 Promise 对象将会被解析。

Contribute

我们欢迎任何形式的贡献,包括但不限于提交 bug 报告、改进代码、提供新的功能思路。

License

此模块遵循 MIT 协议