#binding #pulse #pulseaudio #audio #pulse-simple


A Rust language binding for the PulseAudio libpulse-simple library

19 stable releases

2.6.1 Apr 11, 2019
2.6.0 Mar 11, 2019
2.5.0 Dec 22, 2018
2.4.0 Nov 28, 2018
1.0.2 Feb 9, 2018

#25 in Audio

Download history 5/week @ 2019-01-29 27/week @ 2019-02-05 2/week @ 2019-02-12 23/week @ 2019-02-19 37/week @ 2019-02-26 13/week @ 2019-03-05 28/week @ 2019-03-12 24/week @ 2019-03-19 83/week @ 2019-03-26 24/week @ 2019-04-02 18/week @ 2019-04-09 7/week @ 2019-04-16 28/week @ 2019-04-23 9/week @ 2019-04-30 28/week @ 2019-05-07

100 downloads per month
Used in 1 crate




A Rust language binding for the PulseAudio libpulse-simple library.


Add this to your Cargo.toml:

libpulse-binding = "2.0"
libpulse-simple-binding = "2.0"

and this to your crate root:

extern crate libpulse_binding as pulse;
extern crate libpulse_simple_binding as psimple;


PulseAudio Rust language binding library for the ‘simple’ component

PulseAudio ‘simple’ provides a simple but limited synchronous playback and recording API. This is a synchronous, simplified wrapper around the standard asynchronous API.


This library is a binding that allows Rust code to connect to the PulseAudio sound server via PulseAudio’s existing C API. This binding provides a safe(r) Rust interface which might be preferred over the raw C API provided by the underlying sys linking crate.

This crate provides an interface to PulseAudio’s ‘simple’ component, and should be used in addition to the general libpulse_binding crate.


The simple API is designed for applications with very basic sound playback or capture needs. It can only support a single stream per connection and has no support for handling of complex features like events, channel mappings and volume control. It is, however, very simple to use and quite sufficient for many programs.


Firstly, add a dependency on the crate in your program’s Cargo.toml file. Secondly, import the crate along with the general libpulse_binding crate to the root of your program:

extern crate libpulse_binding as pulse;
extern crate libpulse_simple_binding as psimple;

Finally, establish a connection, as below.


The first step before using the sound system is to connect to the server. This is normally done this way:

# extern crate libpulse_binding as pulse;
# extern crate libpulse_simple_binding as psimple;
use psimple::Simple;
use pulse::stream::Direction;

# fn main() {
let spec = pulse::sample::Spec {
    format: pulse::sample::SAMPLE_S16NE,
    channels: 2,
    rate: 44100,

let s = Simple::new(
    None,                // Use the default server
    "FooApp",            // Our application’s name
    Direction::Playback, // We want a playback stream
    None,                // Use the default device
    "Music",             // Description of our stream
    &spec,               // Our sample format
    None,                // Use default channel map
    None                 // Use default buffering attributes
# }

Transferring data

Once the connection is established to the server, data can start flowing. Using the connection is very similar to the normal read() and write() system calls using read and write methods of the Simple object. Note that these operations always block.

Buffer control

  • Simple::get_latency: Will return the total latency of the playback or record pipeline, respectively.
  • Simple::flush: Will throw away all data currently in buffers.

If a playback stream is used then the following operation is available:


Once playback or capture is complete, the connection should be closed and resources freed. This is done automatically once the object is dropped.