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

@micahfang/recorder

v1.4.9

Published

录制音频,可转成 PCM 或者 WAV 格式

Downloads

5

Readme

@micahfang/recorder

录制音频文件

安装

npm install -S @micahfang/recorder

使用

import Recorder from "@micahfang/recorder";
// 或 import {Recorder} from '@micahfang/recorder'

const options = {
  sampleBits: 16, // 采样位数 8, 16
  sampleRate: 16000, // 采样率16khz 16000
  bufferSize: 2048, // 录音缓存大小 1024/2048/4096
  inputChannels: 1, // 输入声道数
  outputChannels: 1, // 输出声道数
  inputSampleRate: 48000, // 音频输入的采样率
};

const recorder = new Recorder(options);

recorder.check(); // 检查浏览器是否能够录音

const startRecord = async () => {
  await recorder.initAudio(); // 初始化录音 track
  recorder.start(); // 开始录音
};

const stopRecord = async () => {
  recorder.stop(); // 结束录音

  const bytes = recorder.getAllBytes();
  const base64 = await recorder.toPCMBase64(bytes);
  // base64

  recorder.destroy(); // 销毁 track
};

API

const recorder = new Recorder(config:)

  • ** config:RecorderOptions **

    • sampleBits: number 采样位数 8, 16 默认: 16
    • sampleRate: number 采样率 16khz 16000 8khz 8000, 默认 16000
    • bufferSize: number 录音缓存大小 1024/2048/4096 默认 2048
    • inputChannels: number 输入声道数 默认 1
    • outputChannels: number 输出声道数 默认 1
    • inputSampleRate: number 音频输入的采样率 默认 48000
  • Recorder.check() 检查浏览器是否支持录音,返回 boolean

  • recorder.initAudio(): Promise<undefined> 初始化录音

  • recorder.start(): void 开始录音

  • recorder.stop(): void 结束录音

  • recorder.destroy(): void 销毁 tracks,用于关闭浏览器录音

  • recorder.getConfig(): RecorderOptions 获取 recorder 的配置

  • recorder.clearBuffer(): void 清空缓存

  • recorder.getAllBytes(): Blob 返回缓存中的所有数据

  • recorder.getBufferBytes(index: number): Blob 获取单个分片的数据

  • recorder.encodeWavBlob(bytes: Blob): Blob 将音频流转化成 wav 文件

  • recorder.toPCMDataView(bytes: Blob): DataView 将 Blob 数据 转化成 pcm DataView

  • recorder.toPCMBase64(bytes: Blob): string 将 Blob 数据转化成 Base64 字符串