Expand description
A Rust crate for working with Praat .TextGrid
files.
Provides parsing, writing, manipulation, and history tracking for TextGrid data. This crate supports both text and binary formats of Praat TextGrid files, offering a robust set of tools for phonetic annotation, linguistic research, and audio analysis.
§Features
- Parsing: Read TextGrid files in long/short text formats and Praat’s binary format.
- Writing: Write TextGrid files in long/short text formats and binary format.
- Manipulation: Add, remove, split, merge, and query tiers, intervals, and points with undo/redo support.
- Validation: Ensure data integrity with bounds and overlap checks.
§Usage
use textgrid::{TextGrid, Tier, TierType, Interval};
fn main() -> Result<(), textgrid::TextGridError> {
// Create a TextGrid
let mut tg = TextGrid::new(0.0, 10.0)?;
let tier = Tier {
name: "words".to_string(),
tier_type: TierType::IntervalTier,
xmin: 0.0,
xmax: 10.0,
intervals: vec![Interval {
xmin: 1.0,
xmax: 2.0,
text: "hello".to_string(),
}],
points: vec![],
};
tg.add_tier(tier)?;
// Save to file
tg.to_file("example.TextGrid", false)?;
// Load from file
let loaded = TextGrid::from_file("example.TextGrid")?;
assert_eq!(loaded.tiers[0].intervals[0].text, "hello");
Ok(())
}
Structs§
- Interval
- Represents a time interval with associated text.
- Point
- Represents a single time point with a mark.
- Text
Grid - Main structure representing a Praat TextGrid with tiers and history.
- Tier
- Represents a tier in a TextGrid, containing intervals or points.
Enums§
- Text
Grid Error - Errors that can occur during TextGrid operations.
- Tier
Type - Type of a tier, either interval-based or point-based.