Estimate the spoken duration of Hindi, English, and Hinglish (code-mixed) text from syllable counts alone — no audio, no TTS call required. Useful as a fast, offline proxy for how long a sentence will take to speak, e.g. for pacing voice-bot scripts or sanity-checking TTS output length.
- Language detection per word — each whitespace-separated token is classified as Hindi or English by checking for Devanagari Unicode characters (
ऀ–ॿ). - Syllable counting
n_syllable_hindi: counts Devanagari grapheme clusters (treating a consonant + halant/virama + following consonant as one cluster, per this approach).n_syllable_english: a regex-based heuristic syllable counter (vowel runs, with exception/correction rules for silente,-ely,-es/-ed, etc.), adapted from this approach.
- Duration mapping — each syllable count is scaled by an empirically fit per-language seconds-per-syllable constant (Hindi:
0.18034... * 1.05, English:0.2807928174616981) to produce an estimated duration in seconds. - Sentence aggregation — punctuation is stripped, the sentence is split into words, and each word's estimated duration is summed to give a total sentence duration.
alignment_v0.ipynb— the current (v0) implementation and worked examples, including a mixed Hindi/English sentence.
Open the notebook and run all cells (only standard library modules — unicodedata, re, time — are used, no extra dependencies needed beyond Jupyter itself):
pip install jupyter
jupyter notebook alignment_v0.ipynbExample:
text = "अगर आप आज payment नहीं करते तो हम legal action initiate करने के लिए बाध्य होंगे।"
# -> per-word syllable/duration breakdown + total estimated duration in secondsThe per-syllable duration constants were fit against reference audio timings for representative Hindi, English, and Hinglish sentences (see the commented example durations in the notebook). Accuracy will vary with speaking rate, so treat outputs as an approximation rather than an exact duration.
Early-stage / experimental (v0). Known limitations:
- English syllable counting is a heuristic and will mis-count some words.
- Hindi/English detection is per-word and purely script-based, so transliterated Hindi written in Latin script is treated as English.
- Calibration constants are based on a small sample of sentences.