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 ¶
- type Card
- type Client
- func (c *Client) ActiveOutput() (Output, error)
- func (c *Client) Cards() ([]Card, error)
- func (c *Client) Close()
- func (c *Client) GetOutputByCardIDAndPortID(cardID, portID string) (Output, error)
- func (c *Client) GetOutputByID(id string) (Output, error)
- func (c *Client) Mute() (bool, error)
- func (c *Client) Outputs() (outputs []Output, activeIndex int, err error)
- func (c *Client) ServerInfo() (*Server, error)
- func (c *Client) SetCardProfile(cardIndex uint32, profileName string) error
- func (c *Client) SetMute(b bool) error
- func (c *Client) SetSinkVolume(sinkName string, volume float32) error
- func (c *Client) SetVolume(volume float32) error
- func (c *Client) ToggleMute() (bool, error)
- func (c *Client) Updates() (updates <-chan struct{}, err error)
- func (c *Client) Volume() (float32, error)
- type Error
- type Output
- type Server
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 (*Client) ActiveOutput ¶
ActiveOutput returns the currently active output.
func (*Client) Close ¶
func (c *Client) Close()
Close closes the connection to PulseAudio server and makes the Client unusable.
func (*Client) GetOutputByCardIDAndPortID ¶
GetOutputByID returns the output with the given card and port id
func (*Client) GetOutputByID ¶
GetOutputByID returns the output with the given ID
func (*Client) Outputs ¶
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 (*Client) SetCardProfile ¶
func (*Client) SetSinkVolume ¶
func (*Client) SetVolume ¶
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 ¶
ToggleMute reverse mute status
func (*Client) Updates ¶
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
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.
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"`
}