https://github.com/eddiegulay/rtrimmer
Python package to trim RTTM diarization files and optionally audio files to a user-specified time range.
https://github.com/eddiegulay/rtrimmer
audio diarization pyannote rttm tanzania trimming
Last synced: about 2 months ago
JSON representation
Python package to trim RTTM diarization files and optionally audio files to a user-specified time range.
- Host: GitHub
- URL: https://github.com/eddiegulay/rtrimmer
- Owner: eddiegulay
- License: mit
- Created: 2025-05-27T15:24:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-28T16:58:33.000Z (about 1 year ago)
- Last Synced: 2025-12-16T09:17:01.737Z (6 months ago)
- Topics: audio, diarization, pyannote, rttm, tanzania, trimming
- Language: Python
- Homepage: https://pypi.org/project/rtrimmer/
- Size: 17.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rtrimmer
Lightweight Python package to trim RTTM diarization files and optionally audio files to a user-specified time range.
## Features
- Trim RTTM files to a specified time range
- Adjust segment durations if they overlap the max duration
- Optionally trim audio files using ffmpeg
- Batch support for folders
- CLI and Python API
- Logging and input validation
## Installation
```bash
pip install rtrimmer
```
## Usage
### CLI
Trim an RTTM file to the first 5 minutes (300 seconds):
```bash
rttm-trim --rttm input.rttm --output-rttm trimmed.rttm --duration 300
```
Trim both RTTM and audio file:
```bash
rttm-trim --rttm input.rttm --audio input.wav --output-rttm trimmed.rttm --output-audio trimmed.wav --duration 300
```
Batch trim all RTTM files in a folder:
```bash
rttm-trim --rttm-folder ./rttms --output-folder ./trimmed_rttms --duration 300
```
Trim starting from a specific time point (e.g., 60 seconds in) for 5 minutes:
```bash
rttm-trim --rttm input.rttm --output-rttm trimmed.rttm --start-time 60 --duration 300
```
### Python API
```python
from rtrimmer import trim_rttm, trim_audio, trim_rttm_folder
# Trim a single RTTM file
trim_rttm("session1.rttm", "session1_trimmed.rttm", max_duration=300)
# Trim starting from 60 seconds in
trim_rttm("session1.rttm", "session1_trimmed.rttm", max_duration=300, min_time=60)
# Trim audio file
trim_audio("session1.wav", "session1_trimmed.wav", duration=300, start_time=0)
# Batch process a folder of RTTM files
results = trim_rttm_folder("./rttms", "./trimmed_rttms", max_duration=300)
print(f"Processed {len(results)} files")
```
## How It Works
### RTTM Trimming Logic
The package handles various edge cases when trimming RTTM files:
1. **Segments fully within the target range**: Kept as is
2. **Segments starting before the target range but extending into it**: Start time adjusted to the beginning of the target range, duration shortened accordingly
3. **Segments extending beyond the target range**: Duration shortened to end at the target range boundary
4. **Segments outside the target range**: Excluded from the output
### Audio Trimming
Audio trimming is performed using ffmpeg, which must be installed and available in your PATH. The package attempts to use the copy codec for faster processing, but falls back to re-encoding if needed.
## Requirements
- Python 3.8+
- ffmpeg (for audio trimming, must be installed and in PATH)
## Example
Suppose you have a diarization RTTM file and a corresponding WAV file for a 1-hour meeting, but you only want the first 5 minutes:
```bash
rttm-trim --rttm meeting.rttm --audio meeting.wav --output-rttm meeting_5min.rttm --output-audio meeting_5min.wav --duration 300
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.