#audio #playback #synthesizer

sys soloud-sys

Rust bindings for the soloud audio engine

16 unstable releases (3 breaking)

0.4.0 May 4, 2021
0.3.4 Jan 21, 2021
0.2.4 Dec 27, 2020
0.2.2 Nov 22, 2020
0.1.6 Aug 31, 2020

#112 in Audio

Download history 15/week @ 2021-02-23 11/week @ 2021-03-02 12/week @ 2021-03-09 12/week @ 2021-03-16 44/week @ 2021-03-23 71/week @ 2021-03-30 40/week @ 2021-04-06 83/week @ 2021-04-13 50/week @ 2021-04-20 15/week @ 2021-04-27 48/week @ 2021-05-04 47/week @ 2021-05-11 55/week @ 2021-05-18 15/week @ 2021-05-25 22/week @ 2021-06-01 35/week @ 2021-06-08

188 downloads per month
Used in 2 crates (via soloud)

MIT license

7MB
72K SLoC

C++ 45K SLoC // 0.1% comments C 22K SLoC // 0.0% comments Rust 2.5K SLoC Python 1.5K SLoC // 0.5% comments Lua 871 SLoC // 0.0% comments Ruby 102 SLoC // 0.1% comments C# 20 SLoC // 0.2% comments Batch 12 SLoC Shell 1 SLoC JavaScript 1 SLoC

soloud-rs

Documentation Crates.io License Build

A crossplatform Rust bindings for the soloud audio engine library.

Supported formats: wav, mp3, ogg, flac. The library also comes with a speech synthesizer.

Usage

[dependencies]
soloud = "0.3"

Or to use the git repo:

[dependencies]
soloud = { git = "https://github.com/moalyousef/soloud-rs" }

To play audio:

use soloud::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sl = Soloud::default()?;

    let mut wav = audio::Wav::default();

    wav.load(&std::path::Path::new("sample.wav"))?;

    sl.play(&wav); // calls to play are non-blocking, so we put the thread to sleep
    while sl.voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    wav.load(&std::path::Path::new("Recording.mp3"))?;
    
    sl.play(&wav);
    while sl.voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    Ok(())
}

To play speech:

use soloud::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sl = Soloud::default()?;

    let mut speech = audio::Speech::default();

    speech.set_text("Hello World")?;

    sl.play(&speech);
    while sl.active_voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    speech.set_text("1 2 3")?;

    sl.play(&speech);
    while sl.active_voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    speech.set_text("Can you hear me?")?;

    sl.play(&speech);
    while sl.active_voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }
    
    Ok(())
}

To add a filter:

use soloud::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sl = Soloud::default()?;

    let mut wav = audio::Wav::default();
    let mut filt = filter::EchoFilter::default();
    filt.set_params(0.2)?; // sets the delay

    wav.load(&std::path::Path::new("sample.wav"))?;
    wav.set_filter(0, Some(&filt));

    sl.play(&wav);
    while sl.voice_count() > 0 {
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    Ok(())
}

The examples can be found in the soloud/examples directory. They can be run using:

$ cargo run --example simple
$ cargo run --example speech
$ cargo run --example filter
$ cargo run --example load_mem

You will need to have valid "sample.wav" and "Recording.mp3" audio files in the project root. Or you can change the paths to point to any supported audio file.

There is also a demo gui application (using fltk) here.

Dependencies

A Rust compiler, C++ compiler, Cargo, CMake and git (all these need to be in your PATH). This crate uses the miniaudio backend by default which assumes default sound drivers are functional.

Backends

The default backend is miniaudio, however Soloud supports several backends to varying degrees. To enable support of a certain backend, alsa for example:

[dependencies]
soloud = { version = "0.3", default-features = false, features = ["alsa"] }

This also assumes that those libraries headers are in your include path where CMake can find them, otherwise you can set it via the command line (posix):

$ export CXXFLAGS="-I /path/to/include"

or for Windows:

$ set CXXFLAGS="-I C:\\path\\to\\include"

The same can be done for CFLAGS if needed.

Supported backends:

  • miniaudio
  • oss
  • alsa
  • sdl2
  • sdl2-static
  • portaudio
  • openal
  • xaudio2
  • winmm
  • wasapi
  • opensles
  • coreaudio
  • jack

Dependencies