Code Monkey home page Code Monkey logo

pulseaudio's Introduction

๐ŸŽถ @tmigone/pulseaudio ๐ŸŽถ

NPM CI Coverage Status

@tmigone/pulseaudio is a TypeScript based client library for PulseAudio, the most popular sound server for Linux. This library allows you to easily build clients or applications that interact with a PulseAudio server over it's native protocol, for example media players/recorders, volume control applications, etc.

Features

  • Zero dependency fully typed TypeScript implementation of the PulseAudio client protocol
  • Extensive testing suite
  • Protocol features:
    • authentication - provide authentication data for the server
    • transport - connect over UNIX domain sockets or TCP sockets
    • introspection - query, modify and operate on PulseAudio objects like modules, sinks, sources, etc.
    • events - subscribe to server-side object events like a sink starting playback, etc.
    • (To be implemented) streams - manage audio playback and recording using Node.js streams

Installation

Install the library using npm:

npm install @tmigone/pulseaudio

Usage

import PulseAudio, { Sink } from '@tmigone/pulseaudio'

(async () => {
  // Connect using tcp or unix socket
  // const client: PulseAudio = new PulseAudio('unix:/run/pulse/pulseaudio.socket')
  const client: PulseAudio = new PulseAudio('tcp:192.168.1.10:4317')
  await client.connect()

  // Set volume of all sinks to 50%
  const sinks: Sink[] = await client.getSinkList()
  for (const sink of sinks) {
    await client.setSinkVolume(sink.index, 50)
  }

  // Close connection
  client.disconnect()
})()

Documentation

Visit the docs site for in depth documentation on the library API's.

pulseaudio's People

Contributors

spacingbat3 avatar tmigone avatar versionist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pulseaudio's Issues

Refactor command/response

Currently it's a bit confusing with so many entities. Refactor as follows to simplify:

  • Remove top level command.ts and response.ts. PARequest is the generic protocol level entity to represent a request being made to a PulseAudio server. PACommand to be redefined as an abstraction that implements different types of requests made to the server, including query and reply.
  • /commands contain subfolders by command type (sink, source, sinkInput, authenticate, etc). Each command should expose interfaces to generate a PARequest.query and PARequest.reply: PACommand.<command_type>.<command>.query = (requestId: number, ...args): PAPacket => {} and PACommand.<command_type>.<command>.reply = (packet: PAPacket, protocol: number): T => {}

For example for sink commands:

/commands/sink/
- get.ts --> PulseAudio.getSink()
- getAll.ts --> PulseAudio.getSinks()
- setVolume.ts --> PulseAudio.setSinkVolume()

Each file exports a PACommand, for example:

PACommand.sink.getAll.query()
PACommand.sink.getAll.reply()

Record a Stream?

I would like to record sound or would like to pass the sound on to a Discord client bot later. What does the code for this look like? I couldn't find an example and unfortunately the documentation doesn't give me much feedback.

Support sources too

It doesn't look like configuring and reading from sources is implemented yet.

(Honestly I'm still impressed that you managed to reimplement most of the pulse audio protocol from scratch. This is what I was looking for and didn't expect to find anywhere.)

unix socket connection

const client: PulseAudio = new PulseAudio('unix:/run/pulse/pulseaudio.socket');

await client.connect();

I didn't see that unix:/ is taken into account when parsing the address. How is this supposed to work?

Console result:
Uncaught RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received NaN.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.