4 stable releases

new 1.1.0 May 12, 2022
1.0.2 Jan 31, 2022
1.0.1 Oct 8, 2021
1.0.0 Sep 7, 2021

#38 in Audio

Download history 19/week @ 2022-01-24 50/week @ 2022-01-31 3/week @ 2022-02-07 5/week @ 2022-02-14 5/week @ 2022-02-21 12/week @ 2022-02-28 20/week @ 2022-03-07 33/week @ 2022-03-14 42/week @ 2022-03-21 6/week @ 2022-03-28 32/week @ 2022-04-04 42/week @ 2022-04-11 31/week @ 2022-04-18 68/week @ 2022-04-25 76/week @ 2022-05-02 84/week @ 2022-05-09

261 downloads per month
Used in rustpotter-cli

Apache-2.0

4MB
474 lines

PvRecorder Rust Binding

A cross platform audio recorder that captures single-channel audio at a sample rate of 16kHz.

Requirements

  • Rust 1.54+

Compatibility

  • Windows (x86_64)
  • macOS (x86_64)
  • Linux (x86_64)
  • Raspberry Pi:
    • Zero
    • 2
    • 3 (32 and 64 bit)
    • 4 (32 and 64 bit)
  • NVIDIA Jetson Nano
  • BeagleBone

Installation

To add the pvrecorder library into your app, add pv_recorder to your app's Cargo.toml manifest:

[dependencies]
pv_recorder = "*"

Usage

Getting the list of input devices does not require an instance:

use pv_recorder::Recorder

let audio_devices = Recorder::get_audio_devices();

To start recording initialize an instance using the builder and run start:

use pv_recorder::RecorderBuilder;

let recorder = RecorderBuilder::new().init()?;
recorder.start()?

Get the pcm frames by calling the read function:

loop {
    let mut pcm_frame_buffer: [i16; FRAME_LENGTH] = [0; FRAME_LENGTH];
    recorder.read(&mut pcm_frame_buffer)?;
    // do something with pcm
}

To stop recording just run stop on the instance:

recorder.stop()?;

Demo

For more detailed information on how to use the pv_recorder Rust sdk, see examples/demo.rs.

In the following instructions, we will refer to {AUDIO_DEVICE_INDEX} as the index of the audio device to use, and {OUTPUT_PATH} as the path to save the raw audio data

{AUDIO_DEVICE_INDEX} defaults to -1 and {OUTPUT_PATH} can be empty if you wish to not save any data.

To show the available audio devices run:

cargo run --release --example demo -- --show_audio_devices

To run the audio recorder:

cargo run --release --example demo -- --audio_device_index {AUDIO_DEVICE_INDEX} --output_path {OUTPUT_PATH}

See additional options by calling -h/--help:

cargo run --release --example demo -- -h

Dependencies