Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

capdilla/audiotee_rust

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

audiotee

Crates.io Documentation License: MIT

A Rust library for capturing system audio output on macOS using the audiotee binary. This library provides a convenient wrapper around the command-line tool, making it easy to capture, process, and save system audio in your Rust applications.

Features

  • Real-time audio capture: Capture system audio output as PCM data streams
  • Event-driven API: React to audio data, start/stop events, and errors through callbacks
  • Configurable parameters: Control sample rate, chunk duration, and process filtering
  • WAV file export: Built-in support for saving captured audio as WAV files
  • Thread-safe: Safe to use in multi-threaded applications
  • macOS only: Specifically designed for macOS system audio capture

Installation

Add this to your Cargo.toml:

[dependencies]
audiotee = "0.1.0"

Prerequisites

  • macOS: This library only works on macOS
  • audiotee binary: The audiotee command-line tool must be installed and accessible in your PATH
  • Rust: 1.70 or later

Usage

use audiotee::{AudioTee, AudioTeeOptions};
use std::sync::{Arc, Mutex};

fn main() {
    // Configure options
    let options = AudioTeeOptions {
        sample_rate: Some(16_000),
        chunk_duration_ms: Some(1000),
        mute: Some(false),
        include_processes: None,
        exclude_processes: None,
    };

    // Buffer to accumulate audio data
    let audio_buffer: Arc<Mutex<Vec<u8>>> = Arc::new(Mutex::new(Vec::new()));
    let audio_buffer_clone = Arc::clone(&audio_buffer);

    // Create AudioTee instance with event handlers
    let mut tee = AudioTee::new(options)
        .on_start(|| println!("Started capturing audio"))
        .on_stop(|| println!("Stopped capturing audio"))
        .on_error(|e| eprintln!("Error: {e}"))
        .on_data(move |chunk| {
            let mut buffer = audio_buffer_clone.lock().unwrap();
            buffer.extend_from_slice(&chunk.data);
        });

    // Start capturing
    tee.start().expect("Failed to start AudioTee");

    // Capture for some time...
    std::thread::sleep(std::time::Duration::from_secs(10));

    // Stop capturing
    tee.stop().expect("Failed to stop AudioTee");
}

Configuration Options

The AudioTeeOptions struct allows you to customize the audio capture behavior:

  • sample_rate: Sample rate in Hz (e.g., 16000, 44100, 48000)
  • chunk_duration_ms: Duration of each audio chunk in milliseconds
  • mute: Whether to mute system audio output during capture
  • include_processes: List of process IDs to include in capture (whitelist)
  • exclude_processes: List of process IDs to exclude from capture (blacklist)

Examples

Check out the examples directory for more comprehensive usage examples:

cargo run --example main

This will demonstrate:

  • Starting and stopping audio capture
  • Saving audio chunks periodically
  • Exporting captured audio as WAV files

Platform Support

Platform Supported
macOS ✅ Yes
Linux ❌ No
Windows ❌ No

Credits

This library is built on top of the audiotee command-line tool. Special thanks to Nick Payne and his excellent article: AudioTee: Capture System Audio Output on macOS.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Rust library for capturing system audio output on macOS using the audiotee binary. This library provides a convenient wrapper around the command-line tool, making it easy to capture, process, and save system audio in your Rust applications.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.