Giter Club home page Giter Club logo

recorder's Introduction

recorder

js audio recorder plugin

使用

demo使用

npm ci 或 npm i
npm run dev

编译

npm run build

使用方法

引入方式

  • script标签方式
<script type="text/javascript" src="./dist/recorder.js"></script>

let recorder = new Recorder();
  • npm方式:

安装:

npm i js-audio-recorder

调用:

import Recorder from 'js-audio-recorder';

let recorder = new Recorder();

基本用法

// 开始录音
recorder.start();
// 暂停录音
recorder.pause();
// 继续录音
recorder.resume()
// 结束录音
recorder.stop();
// 录音播放
recorder.play();
// 销毁录音实例,释放资源,fn为回调函数,
recorder.destroy(fn);
recorder = null;

下载功能

// 下载pcm文件
recorder.downloadPCM();
// 下载wav文件
recorder.downloadWAV();
// 重命名pcm文件,wav也支持
recorder.downloadPCM('重命名');

获取录音时长

// 回调持续输出时长
recorder.onprocess = function(duration) {
    console.log(duration);
}
// 手动获取录音时长
console.log(recorder.duration);

默认配置

sampleBits,采样位数,默认是16
sampleRate,采样频率,浏览器默认的,我的chrome是48000
numChannels,声道数,默认是1

传入参数

new Recorder时支持传入参数,

{
    sampleBits: 16,         // 采样位数,范围8或16
    sampleRate: 16000,      // 采样率,范围11025、16000、22050、24000、44100、48000
    numChannels: 1,         // 声道,范围1或2
}

注意

  1. 使用127.0.0.1或localhost尝试,因为getUserMedia在高版本的chrome下需要使用https。

浏览器兼容性

主要是以下几个方面:

  • Web Audio Api

https://caniuse.com/#search=webaudio

  • getUserMedia

https://caniuse.com/#search=getusermedia

  • Typed Arrays

https://caniuse.com/#search=typedarrays

其他资源

recorder's People

Contributors

2fps avatar

Watchers

李航 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.