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

@siteed/expo-audio-stream

v0.7.5

Published

stream audio crossplatform

Downloads

1,363

Readme

@siteed/expo-audio-stream

@siteed/expo-audio-stream is a comprehensive library designed to facilitate real-time audio processing and streaming across iOS, Android, and web platforms. This library leverages Expo's robust ecosystem to simplify the implementation of audio recording and streaming functionalities within React Native applications. Key features include audio streaming with configurable buffer intervals and automatic handling of microphone permissions in managed Expo projects.

Features

  • Real-time audio streaming across iOS, Android, and web.
  • Configurable intervals for audio buffer receipt.
  • Automated microphone permissions setup in managed Expo projects.
  • IOS is automatically setup to handle background audio recording.
  • Listeners for audio data events with detailed event payloads.
  • Utility functions for recording control and file management.

Installation

To install @siteed/expo-audio-stream, add it to your project using npm or Yarn:

npm install @siteed/expo-audio-stream
# or
yarn add @siteed/expo-audio-stream

Make sure that you have Expo set up in your project. For details on setting up Expo, refer to the Expo documentation.

Configuring with app.json

To ensure expo-audio-stream works correctly with Expo, you must add it as a plugin in your app.json configuration file. This step is crucial as it allows Expo to load any necessary configurations or permissions required by the library.

Add the plugin to your app.json like so:

{
  "expo": {
    "plugins": ["@siteed/expo-audio-stream"]
  }
}

Make sure to run npx expo prebuild after adding the plugin to your app.json file.

Usage

The example/ folder contains a fully functional React Native application that demonstrates how to integrate and use the @siteed/expo-audio-stream library in a real-world scenario. This sample application includes features such as starting and stopping audio recordings, handling permissions, and processing live audio data.

Importing the module

import {
  useAudioRecorder,
  AudioStreamResult,
} from '@siteed/expo-audio-stream';

export default function App() {
  const { startRecording, stopRecording, duration, size, isRecording } = useAudioRecorder({
    debug: true,
    onAudioStream: (audioData: Blob) => {
      console.log(`audio event`,audioData);
    }
  });

  const handleStart = async () => {
    const { granted } = await Audio.requestPermissionsAsync();
    if (granted) {
      const fileUri = await startRecording({interval: 500});
    }
  };

  const handleStop = async () => {
    const result: AudioStreamResult = await stopRecording();
  };

  const renderRecording = () => (
    <View>
      <Text>Duration: {duration} ms</Text>
      <Text>Size: {size} bytes</Text>
      <Button title="Stop Recording" onPress={handleStop} />
    </View>
  );

  const renderStopped = () => (
    <View>
      <Button title="Start Recording" onPress={handleStart} />
    </View>
  );

  return (
    <View>
      <Button title="Request Permission" onPress={() => Audio.requestPermissionsAsync()} />
      {isRecording ? renderRecording() : renderStopped()}
    </View>
  );
}

The library also exposes an addAudioEventListener function that provides an AudioEventPayload object that you can subscribe to:

import { addAudioEventListener } from '@siteed/expo-audio-stream';

  useEffect(() => {
    const subscribe = addAudioEventListener(async ({fileUri, deltaSize, totalSize, from, streamUuid, encoded, mimeType, buffer}) => {
        log(`Received audio event:`, {fileUri, deltaSize, totalSize, mimeType, from, streamUuid, encodedLength: encoded?.length, bufferLength: buffer?.length})
    });
    return () => subscribe.remove();
  }, []);

Recording configuration

  • on Android and IOS, audio is recorded in wav format, 16khz sample rate, 16 bit depth, 1 channel.
  • on web, it usually records in opus but it depends on the browser configuration.

If you want to process the audio livestream directly, I recommend having another encoding step to align the audio format across platforms.

TODO

this package is still in development, and there are a few things that need to be done:

  • Add resume (vs currently use start) support and implement pause on iOS.
  • Multi format support: Extend support to other audio formats beyond WAV, such as MP3 or AAC
  • Integrate an audio processing library for optional audio analysis, such as equalization, noise reduction, or volume normalization.
  • Implement a more robust error handling system to provide detailed error messages and recovery options.