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
Output:
Index ¶
- type Card
- type Client
- func (c *Client) Cards() ([]Card, error)
- func (c *Client) Close()
- 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) SetSinkVolume(sinkName string, volume float32) error
- func (c *Client) SetVolume(volume float32) 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 Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains a connection to the PulseAudio server.
func (*Client) Close ¶
func (c *Client) Close()
Close closes the connection to PulseAudio server and makes the Client unusable.
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) 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