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

websocket-audio-api

v0.1.6

Published

WebSocket Audio API: library to broadcast the sound from the microphone through a WebSocket

Downloads

57

Readme

WebSocket Audio API

Thanks

The project is forked from (ws-audio-api)[https://github.com/Ivan-Feofanov/ws-audio-api]

I just fixed little problem.

####Library to broadcast the sound from the microphone through a WebSocket

This library can work in two ways:

Streamer mode:

  1. Get user audio from microphone (getUserMedia support require)
  2. Encode it with Opus codec
  3. Send it to websocket server

Works fine in Chrome, Firefox, Edge. Doesn't work in Safari.

Player mode:

  1. Get packet from broadcasting server
  2. Decode it with Opus codec
  3. Write it to audio queue
  4. Play audio queue (Web Audio Api support require)

Works fine in all browsers

For Speaker only: In Chrome browser you should use secure connection cause Chrome does not support getUserMedia in unsecure HTTP connection
How to setup secure HTTP server

Bower

$ bower install ws-audio-api

NPM

$ npm install ws-audio-api
$ import 'ws-audio-api'

Quick start

  1. Clone this repository

    $ git clone https://github.com/Ivan-Feofanov/ws-audio-api.git
    $ cd ws-audio-api/example
  2. Start secure websockets server from server folder

    $ cd server && npm i
    $ npm start

    This command will start broadcasting server on port 5000

  3. Include scripts in both, speaker and listener page

    <script src="scripts/ws-audio-api.min.js"></script>
  4. On Streamer side create new speaker and make start/stop stream buttons

    <script>
        var streamer = new WSAudioAPI.Streamer({
            server: {
                host: window.location.hostname, //websockets server addres. In this example - localhost
                port: 5000 //websockets server port
        });
    </script>
       
    <button onclick="streamer.start()">Start stream</button>
    <button onclick="streamer.stop()">Stop stream</button>

    Detailed config description placed below

  5. On listener side create new listener and make play/stop buttons

    <script>
        var player = new WSAudioAPI.Player({
            server: {
                host: window.location.hostname, //websockets server addres. In this example - localhost
                port: 5000 //websockets server port
        });
    </script>
    <button onclick="player.start()">Play stream</button>
    <button onclick="player.stop()">Stop playing</button>
  6. Enjoy!

Config

Default config

var defaultConfig = { 
    codec: {
        sampleRate: 24000,
        channels: 1,
        app: 2048,
        frameDuration: 20,
        bufferSize: 4096
    },
    server: {
        host: window.location.hostname,
        port: 5000
    }
}

You can change any parameter to fine tune your broadcast.
!! Codec settings on both streamer and listener side should be the same !!
I recommend use sample rate 24000 and below to avoid gaps in stream

Opus Quality Settings

App: 2048=voip, 2049=audio, 2051=low-delay
Sample Rate: 8000, 12000, 16000, 24000, or 48000
Frame Duration: 2.5, 5, 10, 20, 40, 60
Buffer Size = sample rate/6000 * 1024

Server-side

Server side script is very simple:
You can use this script for setup standalone broadcasting server or add ws-audio broadcast functionality to your own server.

API

Streamer

Create new streamer:

var streamer = new WSAudioAPI.Streamer(config);

Start stream

streamer.start();

Mute microphone

streamer.mute();

Unmute microphone

streamer.unMute();

Stop stream

streamer.stop();

Player

Create new player

var player = new WSAudioAPI.Player(config);

Play stream

player.start();

Get stream volume

player.getVolume();

Change stream volume

player.setVolume(level); //Float 0.00 - 1.00

Volume control example

<input id="volume" type="range" min ="0.0" max="1.0" step ="0.01" oninput="setVol(this.value)" oninput="setVol(this.value)" style="-webkit-appearance: slider-vertical">
<input type="text" id="volumeIndicator">
var volume = document.querySelector('#volume');
var volumeIndicator = document.querySelector('#volumeIndicator');
volumeIndicator.value = player.getVolume();

function setVol(val){
    player.setVolume(val);
    volumeIndicator.value = player.getVolume();
}

Stop playing

player.stop();

People

USM LLC.
With regards to

License

MIT