https://github.com/capdilla/audiotee_rust
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.
https://github.com/capdilla/audiotee_rust
macos rust-lang system-audio-capture
Last synced: 7 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/capdilla/audiotee_rust
- Owner: capdilla
- Created: 2025-11-05T01:15:33.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-05T01:23:28.000Z (8 months ago)
- Last Synced: 2025-12-11T08:10:21.085Z (7 months ago)
- Topics: macos, rust-lang, system-audio-capture
- Language: Rust
- Homepage:
- Size: 188 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# audiotee
[](https://crates.io/crates/audiotee)
[](https://docs.rs/audiotee)
[](https://opensource.org/licenses/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`:
```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
```rust
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>> = 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](examples/) directory for more comprehensive usage examples:
```bash
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`](https://github.com/makeusabrew/audiotee) command-line tool. Special thanks to [Nick Payne](https://github.com/makeusabrew) and his excellent article: [AudioTee: Capture System Audio Output on macOS](https://stronglytyped.uk/articles/audiotee-capture-system-audio-output-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](LICENSE) file for details.