Giter VIP home page Giter VIP logo

react-audio-analyser's Introduction

English | 简体中文

react-audio-analyser

GitHub

recording audio and drawing the curve. support for converting the audio to wav.

Demo

Check out the demo.

Installation

npm install react-audio-analyser --save

Features

  • Record audio and show the curve
  • Support output audio/wav,audio/mp3,audio/webm
  • Various state callbacks
  • Support the introduction of multiple components(reference)

Example

import React, {Component} from "react";
import "./index.css";
import AudioAnalyser from "react-audio-analyser"


export default class demo extends Component {
    constructor(props) {
        super(props)
        this.state = {
            status: ""
        }
    }

    componentDidMount() {
    }

    controlAudio(status) {
        this.setState({
            status
        })
    }

    changeScheme(e) {
        this.setState({
            audioType: e.target.value
        })
    }

    render() {
        const {status, audioSrc, audioType} = this.state;
        const audioProps = {
            audioType,
            // audioOptions: {sampleRate: 30000}, // 设置输出音频采样率
            status,
            audioSrc,
            timeslice: 1000, // timeslice(https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/start#Parameters)
            startCallback: (e) => {
                console.log("succ start", e)
            },
            pauseCallback: (e) => {
                console.log("succ pause", e)
            },
            stopCallback: (e) => {
                this.setState({
                    audioSrc: window.URL.createObjectURL(e)
                })
                console.log("succ stop", e)
            },
            onRecordCallback: (e) => {
                console.log("recording", e)
            },
            errorCallback: (err) => {
                console.log("error", err)
            }
        }
        return (
            <div>
                <AudioAnalyser {...audioProps}>
                    <div className="btn-box">
                        {status !== "recording" &&
                        <i className="iconfont icon-start" title="开始"
                           onClick={() => this.controlAudio("recording")}></i>}
                        {status === "recording" &&
                        <i className="iconfont icon-pause" title="暂停"
                           onClick={() => this.controlAudio("paused")}></i>}
                        <i className="iconfont icon-stop" title="停止"
                           onClick={() => this.controlAudio("inactive")}></i>
                    </div>
                </AudioAnalyser>
                <p>choose output type</p>
                <select name="" id="" onChange={(e) => this.changeScheme(e)} value={audioType}>
                    <option value="audio/webm">audio/webm(default, safari does not support )</option>
                    <option value="audio/wav">audio/wav</option>
                    <option value="audio/mp3">audio/mp3</option>
                    <option value="audio/mp4">audio/mp4</option>
                </select>
            </div>
        );
    }
}

Properties(audioProps)

Properties Description Default IsRequired
status recording start , paused pause , inactive stop undefined yes
audioType audio output type audio/webm(audio/mp4 in safari) no
timeslice The number of milliseconds to record into each Blob undefined no
audioSrc window.URL.createObjectURL of output audio blob ,when the prop set, showing the audio control list null no
startCallback Function triggered after starting(resuming) recording undefined no
pauseCallback Function triggered after pausing recording undefined no
stopCallback Function triggered after stoping recording undefined no
onRecordCallback Function triggered after setting timeslice or stoping recording undefined no
errorCallback Function triggered after error undefined no
backgroundColor audio canvas backgroundColor rgba(0, 0, 0, 1) no
strokeColor audio canvas strokeColor #ffffff no
className audio canvas css classname audioContainer no
audioBitsPerSecond audioBitsPerSecond 128000 no
width audio canvas width 500px no
height audio canvas height 100px no
audioOptions output audio/wav options {} no
audioOptions.sampleRate output audio/wav sampleRate no

License

MIT

TODO

  • output audio/mp3 (completed)
  • support safari (completed)
  • Diverse audio curve display

react-audio-analyser's People

Contributors

dependabot[bot] avatar forgere avatar jiwenjiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-audio-analyser's Issues

Cannot record on IOS

Hi, due to IOS updates the package is not working now.
On android everything is fine, but on IOS the recorder is not working (including the package demo)

录制时长问题

大神你好,想问下,如何在录制的过程中同时获取已经录制的时长秒数呢?

react antd 下运行报错

image

按照readME 里面的做法
npm install react-audio-analyser --save
拷贝demo
运行npm run start 出现上图的错误。 这是怎么回事?

完整的demo代码:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { DatePicker } from 'antd';

import AudioAnalyser from "react-audio-analyser";

export default class Demo extends Component {
constructor(props) {
super(props)
this.state = {
status: null
}
}

controlAudio(status) {
    this.setState({
        status
    })
}

render() {
    const {status, audioSrc} = this.state;
    const audioProps = {
        audioType: "audio/wav", // supported audio/wav,audio/mp3, default audio/webm
        status, // Triggering component updates by changing status
        audioSrc,
        startCallback: (e) => {
            console.log("succ start", e)
        },
        pauseCallback: (e) => {
            console.log("succ pause", e)
        },
        stopCallback: (e) => {
            this.setState({
                audioSrc: window.URL.createObjectURL(e)
            })
            console.log("succ stop", e)
        }
    }
    return (
        <AudioAnalyser {...audioProps}>
            <div className="btn-box">
                {status !== "recording" &&
                <i className="iconfont icon-start" title="开始"
                   onClick={() => this.controlAudio("recording")}></i>}
                {status === "recording" &&
                <i className="iconfont icon-pause" title="暂停"
                   onClick={() => this.controlAudio("paused")}></i>}
                <i className="iconfont icon-stop" title="停止"
                   onClick={() => this.controlAudio("inactive")}></i>
            </div>
        </AudioAnalyser>
    );
}

}

function App() {
return (
<div style={{ margin: 100 }}>

AntDesign Demo







);
}

ReactDOM.render(, document.getElementById('root'));

获取的音频分段问题

你好,现在的录音是基于两个按钮,《开始》《停止》来结束一段录音的,我们现在想实现一种类似长连接的方式的录音,即点击开始录音(有点像打开录音模式),保持录音状态,说一句,过了一会,又说一句,过了一会又说一句,能不能分别获取第一句,第二句,第三句的内容,即监测某句话是否说完了然后分别只发送这一句话的流内容呢?

safari支持

大神打算什么时候支持一下safari吗

Error when install on a next project

Any ideas why i get this error ?

thanks

Client pings, but there's no entry for page: /_error
/App_Next_reactStrapV2/node_modules/react-audio-analyser/lib/index.js:4
import AudioAnalyser from './AudioAnalyser';
^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)

Issue with import ./AudioAnalyser

I face this issue when testing. A similar Issue was mentioned in closed issues, but there was no answer. Apparently, the issue is from importing the AudioAnalyser component outside any module at https://github.com/jiwenjiang/react-audio-analyser/blob/master/lib/index.js line 4.

`C:\Users...\node_modules\react-audio-analyser\lib\index.js:4
import AudioAnalyser from './AudioAnalyser';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at compileFunction ()
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Module._compile (C:\Users...\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Object.newLoader [as .js] (C:...\node_modules\pirates\lib\index.js:104:7)`

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.