Skip to main content

Crate phonetik

Crate phonetik 

Source
Expand description

§Phonetik

Phonetic analysis engine for English. Sub-millisecond rhyme detection, stress scanning, meter analysis, and syllable counting backed by a 126K-word CMU Pronouncing Dictionary embedded directly in the binary.

§Quick start

use phonetik::Phonetik;

let ph = Phonetik::new();

// Look up a word
let info = ph.lookup("extraordinary").unwrap();
println!("{}: {} syllables, {}", info.word, info.syllable_count, info.stress_display);

// Find rhymes (all types, best first)
for r in ph.rhymes("love", 10) {
    println!("  {} ({:?}, {:.0}%)", r.word, r.rhyme_type, r.confidence * 100.0);
}

// Scan a line of verse
let scan = ph.scan("uneasy lies the head that wears the crown");
println!("{} — {} ({})", scan.stressed_display, scan.meter.name, scan.meter.regularity);

// Compare two words
let cmp = ph.compare("cat", "bat").unwrap();
println!("similarity: {:.0}%, rhyme: {:?}", cmp.similarity * 100.0, cmp.rhyme_type);

§Architecture

All dictionary data is compiled into the binary at build time:

BlobSizeContents
cmudict.bin2.3 MB126K words, u8-encoded phonemes
rhyme_groups.bin993 KB14K perfect rhyme tail groups
near_neighbors.bin350 KB3.2K coda edit-distance graph

No filesystem access required. The binary is fully self-contained.

§Feature flags

  • server (default): Includes the HTTP server binary (phonetik-server) and dependencies (axum, tokio, reqwest). Disable with default-features = false for library-only use.

Modules§

mcp
MCP (Model Context Protocol) stdio transport.
phoneme
Low-level phoneme encoding/decoding.
server
HTTP API built with Axum. Used by the phonetik-server binary and unit-tested in-process.

Structs§

Comparison
Result of comparing two words phonetically.
DocumentAnalyzeOptions
Options for Phonetik::analyze_document. Suitable for JSON request bodies (camelCase).
DocumentDominantMeter
DocumentLineMetadata
DocumentMetadata
Full-document prosody and coverage metadata.
DocumentSummary
LineScan
Result of scansion — stress and meter analysis of a line of text.
LineSyllableCount
Syllable counts for a line of text.
MeterInfo
Detected metrical pattern.
Phonetik
The phonetic analysis engine. Create one with Phonetik::new() and call methods on it. Thread-safe and cheaply cloneable — all internal data is reference-counted, so clone() is just a handful of pointer bumps with zero allocation. Share freely across threads.
RhymeMatch
A word that rhymes with the query.
WordInfo
Information about a single word’s phonetic properties.
WordSyllableCount
Syllable count for a single word.

Enums§

RhymeType
Classification of a rhyme relationship.
StressMode
Controls whether monosyllabic function words are demoted to unstressed.

Constants§

DOCUMENT_METADATA_VERSION
Schema version for DocumentMetadata. Increment when the JSON shape changes incompatibly.