GithubHelp home page GithubHelp logo

qkdxorjs1002 / recorderservice.js Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 423 KB

WebAudioAPI Audio Recorder Service

License: GNU General Public License v3.0

JavaScript 100.00%
encoding javascript recording webaudioapi audioworklet audioworkletprocessor

recorderservice.js's Introduction

RecorderService.js

WebAudioAPI Audio Recorder Service

RecorderService AudioWorkletProcessor
RecorderService AudioWorketProcessor

Tutorial

let recorderService = RecorderService.createPreConfigured({
    debug: true,
    micGain: 1.0,
});

// buffer event
recorderService.addBufferEventListener(async (event) => {
    let audioBuffer = event.detail.audioBuffer;

    wavesurfer.loadDecodedBuffer(audioBuffer);
});

// got stream event
recorderService.addGotStreamEventListener(async () => {
    console.log("'gotstream' Event is triggered...");
});

// recorded event
recorderService.addRecordedEventListener(async (event) => {
    console.log("'dataavailable' Event is triggered...");

    document.querySelector('#blobUrl').innerHTML = event.detail.recorded.blobUrl;

    wavesurfer.on('ready', function () {
        wavesurfer.play();
    });
    wavesurfer.load(event.detail.recorded.blobUrl);
});

// init 
recorderService.init().then(() => {
    console.log("RecorderService is inited...");

    micBtn.style.visibility = "visible";
    micPauseBtn.style.visibility = "visible";
});

micBtn.onclick = function() {
    if (!recording) {
        wavesurfer.un('ready');
        // record
        recorderService.record().then(() => {
            console.log("Start Recording...");
        });
        recording = true;
    } else {
        // stop
        recorderService.stop().then(() => {
            console.log("Stop Recording...");
        });
        recording = false;
    }
};

micPauseBtn.onclick = function() {
    if (recorderService.state === "recording") {
        // pause
        recorderService.pause().then(() => {
            console.log("Pause Recording...");
        });
    } else if (recorderService.state === "paused") {
        //resume
        recorderService.resume().then(() => {
            console.log("Resume Recording...");
        });
    }
};    

Demo

# install node.js serve
yarn global add serve
# or
npm install -g serve
# run serve
serve --ssl-cert <SSL_CERT_PATH> --ssl-key <SSL_KEY_PATH> ./
# https://localhost:3000/demo

Documentation

Docs.md

recorderservice.js's People

Stargazers

 avatar  avatar

Watchers

 avatar  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.