Crate wavy[][src]

Asynchronous cross-platform real-time audio recording & playback.

Getting Started

Add the following to your Cargo.toml:

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};

/// An event handled by the event loop.
enum Event<'a> {
    /// Speaker is ready to play more audio.
    Play(SpeakersSink<'a, Stereo32>),
    /// Microphone has recorded some audio.
    Record(MicrophoneStream<'a, Stereo32>),

/// Shared state between tasks on the thread.
struct State {
    /// Temporary buffer for holding real-time audio samples.
    buffer: Audio<Stereo32>,

impl State {
    /// Event loop.  Return false to stop program.
    fn event(&mut self, event: Event<'_>) {
        match event {
            Event::Play(mut speakers) =>,
            Event::Record(microphone) => self.buffer.extend(microphone),

/// Program start.
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! {



Record audio samples from a microphone.


A stream of recorded audio samples from a microphone.


Play audio samples through a speaker.


A sink that consumes audio samples and plays them through the speakers.