Nerdy Pun Mavens

    @dr.pogodin/react-native-audio
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.6 • Public • Published

    React Native Audio

    Latest NPM Release NPM Downloads GitHub Repo stars

    React Native audio stream listening / recording

    Installation

    npm install @dr.pogodin/react-native-audio

    Usage

    Detailed documentation to be written, however the overall idea is this:

    import {
      AUDIO_FORMATS,
      AUDIO_SOURCES,
      CHANNEL_CONFIGS,
      InputAudioStream,
    } from "@dr.pogodin/react-native-audio";
    
    function createAndStartAudioStream() {
      const stream = new InputAudioStream(
        AUDIO_SOURCES.RAW,
        44100, // Sample rate in Hz.
        CHANNEL_CONFIGS.MONO,
        AUDIO_FORMATS.PCM_16BIT,
        4096, // Sampling size.
      );
    
      stream.addErrorListener((error) => {
        // Do something with a stream error.
      });
    
      stream.addChunkListener((chunk, chunkId) => {
        // Pause the stream for the chunk processing. The point is: if your chunk
        // processing in this function is too slow, and chunks arrive faster than
        // this callback is able to handle them, it will rapidly crash the app,
        // with out of memory error. Muting the stream ignores any new chunks
        // until stream.unmute() is called, thus protecting from the crash.
        // And if your chunk processing is rapid enough, not chunks won't be
        // skipped. The "chunkId" argument is just sequential chunk numbers,
        // by which you may judge whether any chunks have been skipped between
        // this callback calls or not.
        stream.mute();
    
        // Do something with the chunk.
    
        // Resumes the stream.
        stream.unmute();
      });
    
      stream.start();
    
      // Call stream.destroy() to stop the stream and release any associated
      // resources. If you need to temporarily stop and then resume the stream,
      // use .mute() and .unmute() methods instead.
    }

    Contributing

    See the contributing guide to learn how to contribute to the repository and the development workflow.

    License

    MIT

    Install

    npm i @dr.pogodin/react-native-audio

    DownloadsWeekly Downloads

    11

    Version

    1.2.6

    License

    MIT

    Unpacked Size

    176 kB

    Total Files

    50

    Last publish

    Collaborators

    • dr.pogodin