To add the pvrecorder library into your app, add pv_recorder
to your app's Cargo.toml
manifest:
toml
[dependencies]
pv_recorder = "*"
Getting the list of input devices does not require an instance:
```rust use pv_recorder::PvRecorderBuilder
let audiodevices = PvRecorderBuilder::default().getaudio_devices()?; ```
To start recording initialize an instance using the builder and run start
:
```rust use pv_recorder::PvRecorderBuilder;
let framelength = 512; let recorder = PvRecorderBuilder::new(framelength).init()?; recorder.start()? ```
Get frame of audio by calling the read()
function:
rust
while recorder.is_recording() {
let frame = recorder.read()?;
// process audio frame
}
To stop recording just run stop on the instance:
rust
recorder.stop()?;
The PvRecorder Rust demo is a Rust command-line application that demonstrates how to use PvRecorder to record audio to a file.