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

monitor-sound-level

v1.1.2

Published

A package to dynamically measure microphone input level

Downloads

10

Readme

react-native-sound-level-monitor

A package to dynamically measure sound input level in React Native applications. Can be used to help user to adjust microphone sensitivity.

Installation

Choose between yarn add react-native-sound-level-monitor or npm install --save react-native-sound-level-monitor and then run pod install

iOS

You need to add a usage description to Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>TEXT HERE</string>

Android

You need to add a permission to AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Installation on Ubuntu

  1. Add to package.json: "desktopExternalModules": [ "node_modules/react-native-sound-level-monitor/desktop" ]
  2. You may need to make QT's multimedia library accessible for linker sudo ln -s $YOUR_QT_DIR/5.9.1/gcc_64/lib/libQt5Multimedia.so /usr/local/lib/libQt5Multimedia.so

Usage

import rnSoundLevelMonitor, {
  SoundLevelResultType
} from 'react-native-sound-level-monitor';

// OPTIONAL (default 250): the rate, in milliseconds, which to check for microphone sound
const monitorInterval = 50;

export const soundLevelMonitor =
  rnSoundLevelMonitor(monitorInterval);

// you can start monitoring anywhere in your code
soundLevelMonitor.start(); // optional argument

// you can stop monitoring anywhere in your code
soundLevelMonitor.stop();

// you can add listeners which will be called on every frame
const removeThisListener = soundLevelMonitor.addListener(
  (data: SoundLevelResultType) => {
    console.log('new frame', data);
  }
);

// you can then remove added listener by calling the returned callback of `addListener`
removeThisListener();

Full example

import React, { useCallback, useEffect, useState } from 'react';
import { Platform, Text } from 'react-native';
import {
  PERMISSIONS,
  requestMultiple
} from 'react-native-permissions';
import rnSoundLevelMonitor from 'react-native-sound-level-monitor';

const soundLevelMonitor = rnSoundLevelMonitor(50);

const App: React.FunctionComponent = () => {
  const [canProceed, setCanProceed] = useState(false);
  const [hasChecked, setHasChecked] = useState(false);

  const requestPermissions = useCallback(async () => {
    const permissions = await requestMultiple(
      Platform.select({
        ios: [PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.MICROPHONE],
        default: [
          PERMISSIONS.ANDROID.CAMERA,
          PERMISSIONS.ANDROID.RECORD_AUDIO
        ]
      })
    );

    setHasChecked(true);

    if (
      (permissions['android.permission.CAMERA'] === 'granted' &&
        permissions['android.permission.RECORD_AUDIO'] ===
          'granted') ||
      (permissions['ios.permission.CAMERA'] === 'granted' &&
        permissions['ios.permission.MICROPHONE'] === 'granted')
    )
      setCanProceed(true);
  }, []);

  useEffect(() => {
    if (!hasChecked) requestPermissions();
  }, [hasChecked, requestPermissions]);

  useEffect(() => {
    const removeListener = soundLevelMonitor.addListener(data => {
      console.log(data);
    });

    return removeListener;
  }, []);

  useEffect(() => {
    if (!canProceed) return;
    soundLevelMonitor.start();
    return soundLevelMonitor.stop;
  }, [canProceed]);

  if (!canProceed) return null;

  return <Text>Monitoring sound</Text>;
};

export default App;

Credits

Originally forked from https://github.com/punarinta/react-native-sound-level. It seems like the original package is no longer being maintained so I forked it and made tons of improvements. Improvements made were also based on the PRs at the time.

  • https://github.com/punarinta/react-native-sound-level/pull/24
  • https://github.com/punarinta/react-native-sound-level/pull/21
  • https://github.com/punarinta/react-native-sound-level/pull/13