Asynchronous cross-platform real-time audio recording & playback.
Getting Started
Add the following to your Cargo.toml:
[dependencies]
pasts = "0.7"
wavy = "0.8"
fon = "0.4"
This example records audio and plays it back in real time as it's being
recorded. (Make sure to wear headphones to avoid feedback):
use fon::{stereo::Stereo32, Sink, Audio};
use pasts::{exec, wait};
use wavy::{Speakers, Microphone, SpeakersSink, MicrophoneStream};
enum Event<'a> {
Play(SpeakersSink<'a, Stereo32>),
Record(MicrophoneStream<'a, Stereo32>),
}
struct State {
buffer: Audio<Stereo32>,
}
impl State {
fn event(&mut self, event: Event<'_>) {
match event {
Event::Play(mut speakers) => speakers.stream(self.buffer.drain()),
Event::Record(microphone) => self.buffer.extend(microphone),
}
}
}
fn main() {
let mut state = State { buffer: Audio::with_silence(48_000, 0) };
let mut speakers = Speakers::default();
let mut microphone = Microphone::default();
exec!(state.event(wait! {
Event::Record(microphone.record().await),
Event::Play(speakers.play().await),
}));
}