| Crates.io | audio-processor |
| lib.rs | audio-processor |
| version | 0.0.1 |
| created_at | 2025-03-10 16:50:17.074231+00 |
| updated_at | 2025-03-10 16:50:17.074231+00 |
| description | A modular audio processing crate that integrates with FFmpeg for various audio operations. |
| homepage | |
| repository | https://github.com/rishabh-chaturvedi/audio-processor |
| max_upload_size | |
| id | 1586932 |
| size | 37,482 |
A modular audio processing crate for Rust that leverages FFmpeg to perform a wide range of audio operations. The crate is designed for ease of integration and reuse in various projects. It provides a set of functions for audio editing—such as trimming, seeking, transcoding, applying effects, merging, reversing, normalizing, and overlaying audio.
File I/O & Metadata
Basic Editing Operations
Transcoding
Audio Effects & Processing
Integration Tests
Add the following dependency in your Cargo.toml file:
[dependencies]
audio_processor = "0.0.1"
If you are developing or testing locally, clone the repository and build using:
cargo build
Here’s an example demonstrating how to use the crate:
use std::time::Duration;
use audio_processor::{
AudioProcessor,
transcoding::AudioFormat,
processing::{AudioEffect},
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the processor with an audio file.
let audio = AudioProcessor::new("path/to/audio.wav")?;
// Seek to 30 seconds into the audio.
let seeked_audio = audio.seek(Duration::from_secs(30))?;
// Trim the audio from 10 to 20 seconds.
let trimmed_audio = seeked_audio.trim(Duration::from_secs(10), Duration::from_secs(20))?;
// Transcode the trimmed audio to MP3.
trimmed_audio.transcode(AudioFormat::Mp3, "output.mp3")?;
// Adjust the volume by 1.5 times.
let louder_audio = trimmed_audio.adjust_volume(1.5)?;
// Change the playback speed by a factor of 1.25.
let speed_changed_audio = louder_audio.change_speed(1.25)?;
// Apply a fade-in effect of 2 seconds.
let effected_audio = speed_changed_audio.apply_effect(AudioEffect::FadeIn(Duration::from_secs(2)))?;
// Save the final output.
effected_audio.save("final_output.wav")?;
// Merge two audio files.
let merged_audio = AudioProcessor::merge_audios(&[audio.clone(), seeked_audio.clone()], "merged_output.wav")?;
// Reverse the audio.
let reversed_audio = audio.reverse()?;
// Normalize the audio volume.
let normalized_audio = audio.normalize()?;
// Overlay one audio onto another starting at 5 seconds.
let overlayed_audio = audio.overlay(&seeked_audio, Duration::from_secs(5))?;
Ok(())
}
The repository includes integration tests to validate each feature. The tests automatically generate a 5‑second silent audio file (using FFmpeg) if one is not present. To run the tests, execute:
cargo test -- --nocapture
Make sure that FFmpeg is installed and accessible in your PATH.
audio_processor/
├── Cargo.toml # Package metadata and dependencies.
├── src
│ ├── lib.rs # Core library exposing the public API.
│ ├── io.rs # Audio file input/output functions.
│ ├── processing.rs # Audio processing functions and effects.
│ ├── transcoding.rs # Audio format definitions and transcoding functions.
│ └── errors.rs # Custom error definitions.
└── tests
└── integration_tests.rs # Integration tests covering all features.
Contributions are welcome! If you have ideas for new features, bug fixes, or improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.