moalyousef/soloud-rs

A crossplatform Rust bindings for the soloud audio engine library

Supported formats: wav, mp3, ogg, flac

soloud-rs

.

. The library also comes with a speech synthesizer.

  • The official soloud website
  • The official soloud repo

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

Information - Updated Jan 04, 2022

Stars: 28
Forks: 5
Issues: 0

Rust bindings for libinjection

Add libinjection to dependencies of Cargo

Rust bindings for libinjection

Rust bindings for the shaderc library

Rust bindings for the Compiler interface to compile GLSL/HLSL

Rust bindings for the shaderc library

Rust bindings for the C++ api of PyTorch

LIghtweight wrapper for pytorch eg libtorch in rust

Rust bindings for the C++ api of PyTorch

Rust bindings for Sciter

this page for other language bindings (Delphi / D / Go /

Rust bindings for Sciter

Rust bindings to *nix APIs

wrapping the libc functionality with types/abstractions that enforce legal/safe

Rust bindings to *nix APIs

Rust bindings for the FLTK Graphical User Interface library

The fltk crate is a crossplatform lightweight gui library which can be statically linked to produce small, self-contained and fast gui applications

Rust bindings for the FLTK Graphical User Interface library

Rust bindings to bgfx, a cross-platform, graphics API agnostic, &quot;Bring Your Own Engine/Framework&quot; style rendering...

Rust bindings to wrapper for Rust exists, the code here takes a different approach and generate high-level bindings from the BGFX API examples an how...

Rust bindings to bgfx, a cross-platform, graphics API agnostic, &quot;Bring Your Own Engine/Framework&quot; style rendering...
Cargo

1.5K

Rust bindings for the python interpreter

Copyright (c) 2015-2021 Daniel Grunwald

Rust bindings for the python interpreter

Rust bindings for the NumPy C-API

Basically, our MSRV follows the one of ndarray for rust-side matrix library

Rust bindings for the NumPy C-API

Rust Bindings to AVX2-optimized SIP-like hash functions

bindings to three hash functions implemented in C++

Rust Bindings to AVX2-optimized SIP-like hash functions

Rust bindings for Torch

rs (torturous) is a set of Rust bindings for torch intended

Rust bindings for Torch

Rust bindings to libdeflate, a high-performance

Rust bindings to libdeflate

Rust bindings to libdeflate, a high-performance
Facebook Instagram Twitter GitHub Dribbble
Privacy