pulseaudio

package module
v0.0.0-...-289c011 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 10 Imported by: 0

README

pulseaudio GoDoc

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Download:

go get mrogalski.eu/go/pulseaudio

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Rather than exposing the PulseAudio protocol directly this library attempts to hide the PulseAudio complexity behind a Go interface. Some of the things which are deliberately not exposed in the API are:

→ backwards compatibility for old PulseAudio servers

→ transport mechanism used for the connection (Unix sockets / memfd / shm)

→ encoding used in the pulseaudio-native protocol

Working features

Querying and setting the volume.

Listing audio outputs.

Changing the default audio output.

Notifications on config updates.


Automatically generated by autoreadme on 2018.06.22

Documentation

Overview

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Rather than exposing the PulseAudio protocol directly this library attempts to hide the PulseAudio complexity behind a Go interface. Some of the things which are deliberately not exposed in the API are:

→ backwards compatibility for old PulseAudio servers

→ transport mechanism used for the connection (Unix sockets / memfd / shm)

→ encoding used in the pulseaudio-native protocol

Working features

Querying and setting the volume.

Listing audio outputs.

Changing the default audio output.

Notifications on config updates.

Example
client, err := NewClient()
if err != nil {
	panic(err)
}
defer client.Close()
// Use `client` to interact with PulseAudio

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Index         uint32              `json:"index"`
	Name          string              `json:"name"`
	Module        uint32              `json:"module"`
	Driver        string              `json:"driver"`
	Profiles      map[string]*profile `json:"profiles"`
	ActiveProfile *profile            `json:"active_profile"`
	PropList      map[string]string   `json:"prop_list"`
	Ports         []port              `json:"ports"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client maintains a connection to the PulseAudio server.

func NewClient

func NewClient(addressArr ...string) (*Client, error)

NewClient establishes a connection to the PulseAudio server.

func (*Client) ActiveOutput

func (c *Client) ActiveOutput() (Output, error)

ActiveOutput returns the currently active output.

func (*Client) Cards

func (c *Client) Cards() ([]Card, error)

func (*Client) Close

func (c *Client) Close()

Close closes the connection to PulseAudio server and makes the Client unusable.

func (*Client) GetOutputByCardIDAndPortID

func (c *Client) GetOutputByCardIDAndPortID(cardID, portID string) (Output, error)

GetOutputByID returns the output with the given card and port id

func (*Client) GetOutputByID

func (c *Client) GetOutputByID(id string) (Output, error)

GetOutputByID returns the output with the given ID

func (*Client) Mute

func (c *Client) Mute() (bool, error)

func (*Client) Outputs

func (c *Client) Outputs() (outputs []Output, activeIndex int, err error)

Outputs returns a list of all audio outputs and an index of the active audio output.

The last audio output is always called "None" and indicates that audio is disabled.

func (*Client) ServerInfo

func (c *Client) ServerInfo() (*Server, error)

func (*Client) SetCardProfile

func (c *Client) SetCardProfile(cardIndex uint32, profileName string) error

func (*Client) SetMute

func (c *Client) SetMute(b bool) error

ToggleMute reverse mute status

func (*Client) SetSinkVolume

func (c *Client) SetSinkVolume(sinkName string, volume float32) error

func (*Client) SetVolume

func (c *Client) SetVolume(volume float32) error

SetVolume changes the current volume to a specified value from 0 to 1 (or more than 1 - if volume should be boosted).

Example
c := clientForTest()
defer c.Close()

err := c.SetVolume(1.5)
if err != nil {
	panic(err)
}

vol, err := c.Volume()
if err != nil {
	panic(err)
}

fmt.Printf("Current volume is: %.2f", vol)
Output:

Current volume is: 1.50

func (*Client) ToggleMute

func (c *Client) ToggleMute() (bool, error)

ToggleMute reverse mute status

func (*Client) Updates

func (c *Client) Updates() (updates <-chan struct{}, err error)

Updates returns a channel with PulseAudio updates.

Example
c := clientForTest()
defer c.Close()

updates, err := c.Updates()
if err != nil {
	panic(err)
}

select {
case _ = <-updates:
	fmt.Println("Got update from PulseAudio")
case _ = <-time.After(time.Millisecond * 10):
	fmt.Println("No update in 10 ms")
}

err = c.SetVolume(0.1)
if err != nil {
	panic(err)
}
fmt.Println("Volume set to 0.1")

select {
case _ = <-updates:
	fmt.Println("Got update from PulseAudio")
case _ = <-time.After(time.Millisecond * 10):
	fmt.Println("No update in 10 ms")
}
Output:

No update in 10 ms
Volume set to 0.1
Got update from PulseAudio

func (*Client) Volume

func (c *Client) Volume() (float32, error)

Volume returns current audio volume as a number from 0 to 1 (or more than 1 - if volume is boosted).

type Error

type Error struct {
	Cmd  string
	Code uint32
}

func (*Error) Error

func (err *Error) Error() string

type Output

type Output struct {
	ID        string `json:"id"`
	CardID    string `json:"card_id"`
	PortID    string `json:"port_id"`
	CardName  string `json:"card_name"`
	PortName  string `json:"port_name"`
	Available bool   `json:"available"`
	Active    bool   `json:"active"`
	// contains filtered or unexported fields
}

Output represents PulseAudio output.

func (Output) Activate

func (o Output) Activate() error

Activate sets this output as the main one.

type Server

type Server struct {
	PackageName    string     `json:"package_name"`
	PackageVersion string     `json:"package_version"`
	User           string     `json:"user"`
	Hostname       string     `json:"hostname"`
	SampleSpec     sampleSpec `json:"sample_spec"`
	DefaultSink    string     `json:"default_sink"`
	DefaultSource  string     `json:"default_source"`
	Cookie         uint32     `json:"cookie"`
	ChannelMap     channelMap `json:"channel_map"`
}

func (*Server) ReadFrom

func (s *Server) ReadFrom(r io.Reader) (int64, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL