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

@josephuspaye/win-audio-outputs

v0.1.0

Published

List and control system audio outputs from Node.js on Windows

Downloads

1

Readme

win-audio-outputs

List and system control audio outputs from Node.js on Windows

Wraps the excellent SoundVolumeView for use in Node.js.

This project is part of #CreateWeekly, my attempt to create something new publicly every week in 2020.

Installation

npm install -g @josephuspaye/win-audio-outputs

Examples

List audio outputs

The following program prints a list of currently active audio outputs in JSON format:

import { listOutputs } from '@josephuspaye/win-audio-outputs';

async function main() {
  const outputs = await listOutputs();
  console.log(JSON.stringify(outputs, null, '  '));
}

main();
[
  {
    "id": "{0.0.0.00000000}.{456f665c-5c37-4a04-b894-9ea4a1717f76}",
    "name": "LG Ultra HD",
    "deviceName": "NVIDIA High Definition Audio",
    "isDefaultForMultimedia": false,
    "isDefaultForCommunications": false,
    "isMuted": false,
    "volume": 60
  },
  {
    "id": "{0.0.0.00000000}.{938a0889-557f-4ba3-ae3e-2d6837decbe4}",
    "name": "Realtek HD Audio 2nd output",
    "deviceName": "Realtek(R) Audio",
    "isDefaultForMultimedia": true,
    "isDefaultForCommunications": true,
    "isMuted": false,
    "volume": 20.5
  }
]

Set the volume of an output

The following program sets the volume of the default multimedia output to 50%:

import { listOutputs, setVolume } from '@josephuspaye/win-audio-outputs';

async function main() {
  const outputs = await listOutputs();
  const multimediaDefault = outputs.find(
    (output) => output.isDefaultForMultimedia
  );

  if (multimediaDefault) {
    await setVolume(multimediaDefault, 50);
  } else {
    console.log('No default multimedia output found');
  }
}

main();

Mute or unmute an output

The following program mutes or unmutes the default communications output:

import { listOutputs, mute, unmute } from '@josephuspaye/win-audio-outputs';

async function main() {
  const outputs = await listOutputs();
  const multimediaDefault = outputs.find(
    (output) => output.isDefaultForCommunications
  );

  if (multimediaDefault) {
    if (multimediaDefault.isMuted) {
      await unmute(multimediaDefault);
    } else {
      await mute(multimediaDefault);
    }
  } else {
    console.log('No default communications output found');
  }
}

main();

Change default output

The following program changes the default multimedia output to the first non-default one:

import { listOutputs, setAsDefault } from '@josephuspaye/win-audio-outputs';

async function main() {
  const outputs = await listOutputs();
  const firstNonDefault = outputs.find(
    (output) => output.isDefaultForMultimedia === false
  );

  if (firstNonDefault) {
    await setAsDefault(firstNonDefault);
  } else {
    console.log('No non-default multimedia output found');
  }
}

main();

API

interface AudioOutput {
  /**
   * The ID of the output, used for subsequent calls that control the output
   */
  id: string;

  /**
   * The name of the output
   */
  name: string;

  /**
   * The name of the output device
   */
  deviceName: string;

  /**
   * Whether this output is the default for multimedia
   */
  isDefaultForMultimedia: boolean;

  /**
   * Whether this output is the default for communications
   */
  isDefaultForCommunications: boolean;

  /**
   * Whether this output is muted
   */
  isMuted: boolean;

  /**
   * The current volume of the output, in the range [0, 100]
   */
  volume: number;
}

/**
 * Get a list of currently active (connected and non-disabled) audio outputs on the system.
 */
function getOutputs(): Promise<AudioOutput[]>;

/**
 * Set the volume of the given output.
 *
 * @param output The output or id of the output
 * @param volume The volume to set, in the range [0, 100]
 * @throws       Throws when output id or volume is invalid
 */
function setVolume(output: AudioOutput | string, volume: number): Promise<void>;

/**
 * Mute the given output.
 *
 * @param output The output or id of the output
 * @throws       Throws when output id is invalid
 */
function mute(output: AudioOutput | string): Promise<void>;

/**
 * Unmute the given output.
 *
 * @param output The output or id of the output
 * @throws       Throws when output id is invalid
 */
function unmute(output: AudioOutput | string): Promise<void>;

/**
 * Set the give output as the default output of the given type.
 *
 * @param output The output or id of the output
 * @param type   The type of default to set: 'multimedia', 'commcommunications', or 'all'
 * @throws       Throws when output id or default type is invalid
 */
function setAsDefault(
  output: AudioOutput | string,
  type?: 'all' | 'multimedia' | 'communications'
): Promise<void>;

Licence

MIT