Cgo bindings to PulseAudio's Simple API, for easily playing or capturing raw audio.

pulse-simple

Cgo bindings to PulseAudio's Simple API, for easily playing or capturing raw audio.

The full Simple API is supported, including channel mapping and setting buffer attributes.

prerequisites

These bindings require the pulseaudio C headers to be available. On Ubuntu they can be installed by sudo apt install libpulse-dev, and on other distros there should be a similar package available.

quick test

If everything is configured correctly, go run examples/sinewave.go should output some simple tones via pulseaudio.

usage

Basic usage is to request a playback or capture stream, then write bytes to or read bytes from it.

Reading and writing will block until the given byte slice is completely consumed or filled, or an error occurs.

The format of the data will be as requested on stream creation.

For example, assuming "data" contains raw bytes representing stereophonic audio in little-endian 16-bit integer PCM format, the following will obtain a playback stream and play the given data as audio on the default sound device.

ss := pulse.SampleSpec{pulse.SAMPLE_S16LE, 44100, 2}
stream, _ := pulse.Playback("my app", "my stream", &ss)
defer stream.Free()
defer stream.Drain()
stream.Write(data)

More example usage can be found in the examples folder.

For more information, see the PulseAudio Simple API documentation at http://www.freedesktop.org/software/pulseaudio/doxygen/simple.html

license

MIT (see the included LICENSE file for full license text)

Similar Resources

Go bindings to OpenGL Utility Library

GLU This package offers minimal bindings for GLU functions. Usage go get github.com/go-gl-legacy/glu License Copyright 2012 The go-gl Authors. All ri

Aug 18, 2018

naive go bindings to GnuPlot

naive go bindings to GnuPlot

go-gnuplot Simple-minded functions to work with gnuplot. go-gnuplot runs gnuplot as a subprocess and pushes commands via the STDIN of that subprocess.

Nov 8, 2021

go-gtk3 - GTK3 BINDINGS FOR GO

go-gtk3 - GTK3 BINDINGS FOR GO THIS IS: Hopefully GTK3 Bindings using gobject binding for Go. Goal is to have fairly complete gtk3 widgets with pango

May 25, 2021

Experimental OpenAL bindings for Go.

Experimental OpenAL bindings for Go. ==================================== Everything is evolving quickly and nothing is totally done. If you want to

Jul 24, 2022

Go bindings for GStreamer (retired: currently I don't use/develop this package)

Retired. I don't use/develop this package anymore. Go bindings for GStreamer at a very early stage of maturity. This package is based on GLib bindings

Nov 10, 2022

Go bindings for libVLC and high-level media player interface

Go bindings for libVLC and high-level media player interface

Go bindings for libVLC 2.X/3.X/4.X and high-level media player interface. The package can be useful for adding multimedia capabilities to applications

Dec 31, 2022

Go bindings for OpenCV1.1 (Dev/Zero Dependencies).

Go bindings for OpenCV1.1 (Dev/Zero Dependencies).

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa Go bindings for OpenCV1.1 PkgDoc: http://godoc

Dec 6, 2022

Go cross-platform OpenGL bindings.

gl Package gl is a Go cross-platform binding for OpenGL, with an OpenGL ES 2-like API. It supports: macOS, Linux and Windows via OpenGL 2.1 backend, i

Nov 21, 2022

Go Graphics - 2D rendering in Go with a simple API.

Go Graphics - 2D rendering in Go with a simple API.

Go Graphics gg is a library for rendering 2D graphics in pure Go. Installation go get -u github.com/fogleman/gg Alternatively, you may use gopkg.in t

Dec 29, 2022
Comments
  • Not found

    Not found

    When running go build from the main directory i get this error message:

    Package libpulse-simple was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libpulse-simple.pc'
    to the PKG_CONFIG_PATH environment variable
    

    Any suggestion?

  • Capture returns error when used as systemd service.

    Capture returns error when used as systemd service.

    I created a small program which uses this to capture voice commands from microphone and acts accordingly to the commands like poweroff, lock, wake up. Used pocketsphinx for recognizing commands. All went well until I made it into a systemd unit to run it automatically on startup.

    The funny thing is I can run the shell script(scripted the go binary) that I made successfully both as normal user and root user but for some reason when I try to run it as a systemd unit with systemctl start service it fails with the Capture returning an error saying connection refused. Maybe its an issue with systemd that I've missed.

  • How do I stop playback after Stream.Write(data)

    How do I stop playback after Stream.Write(data)

    Here's my code

    package main
    
    import (
    	"context"
    	"io"
    	"log"
    
    	"github.com/korandiz/mpa"
    
    	pulse "github.com/mesilliac/pulse-simple"
    )
    
    func play() {
    	ctx, cancel := context.WithCancel(context.Background())
    
    	ss := pulse.SampleSpec{pulse.SAMPLE_S16LE, 44100, 2}
    	stream, _ := pulse.Playback("jam", "jam", &ss)
    	defer stream.Free()
    	defer stream.Drain()
    
    	data := make([]byte, 1024*1024*10)
    	for {
    		switch <-state {
    		case 1:
    			_, err := stream.Flush()
    			checkErr(err)
    			song, err := gm.GetStream(queue[numAlbum[true]][numTrack])
    			checkErr(err)
    			go func(ctx context.Context) {
    				for {
    					select {
    					case <-ctx.Done():
    						log.Println("go2: cancelled, i:")
    						return
    					default:
    						//for {
    
    						i, err := (&mpa.Reader{Decoder: &mpa.Decoder{Input: song.Body}}).Read(data)
    						if err != nil && err != io.EOF {
    							log.Fatal(err)
    						}
    						if i == 0 {
    							return
    						}
    
    						_, err = stream.Write(data[:i])
    						checkErr(err)
    
    						//}
    					}
    				}
    			}(ctx)
    		case 2:
    			cancel()
    			log.Println("from case 2")
    			stream.Flush()
    		}
    	}
    }
    
    

    when I send 2 to state, nothing happens except logging. stream.Flush() seems to do nothing. Also it would be nice if you helped me to stop playback if the commented out loop wasn't commented out

  • Needs more examples.

    Needs more examples.

    It would be good to have a couple more complicated examples.

    An "echo" example would be a good start, to demonstrate Capture() usage.

    An example of advanced stream usage, such as setting channel mapping or buffer attributes manually, might be useful.

A library for playing with colors in go (golang).
A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Dec 30, 2022
A Go skia binding based on skia C library through cgo

go-skia is a Go skia binding based on skia C library through cgo. Note: the project is still in early stage, and it only supports Linux-amd64 now. The

Nov 7, 2022
Process audio files with pipelined DSP framework
Process audio files with pipelined DSP framework

phono is a command for audio processing. It's build on top of pipelined DSP framework. Installation Prerequisites: lame to enable mp3 encoding To link

Oct 4, 2022
Go package captcha implements generation and verification of image and audio CAPTCHAs.
Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dec 30, 2022
Go bindings for OpenCV / 2.x API in gocv / 1.x API in opencv

Go OpenCV binding A Golang binding for OpenCV. OpenCV 1.x C API bindings through CGO, and OpenCV 2+ C++ API (GoCV) through SWIG. Disclaimer This is a

Dec 21, 2022
Vulkan API bindings for Go programming language
Vulkan API bindings for Go programming language

Golang Bindings for Vulkan API Package vulkan provides Go bindings for Vulkan — a low-overhead, cross-platform 3D graphics and compute API. Updated Oc

Jan 3, 2023
Easily customizable Social image (or Open graph image) generator

fancycard Easily customizable Social image (or Open graph image) generator Built with Go, Gin, GoQuery and Chromedp Build & Run Simply, Clone this rep

Jan 14, 2022
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Jan 8, 2023
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

Dec 25, 2022
Go bindings for OpenGL (generated via glow)

gl This repository holds Go bindings to various OpenGL versions. They are auto-generated using Glow. Features: Go functions that mirror the C specific

Dec 12, 2022