Syllable Counter
计算单词和文本中的音节,分析可读性指标,检查应力模式。
关于此工具
音节计数器是一款轻量级工具,通过计算单词中的音节数量和通过可读性指标衡量文本复杂度来分析文本的节奏结构。理解音节分布可以帮助作家、诗人和语言学习者认识文本的流畅性,以及内容是否适合目标受众。与需要服务器查询的基于词典的系统不同,本工具使用元音组启发式方法在浏览器中即时运行,处理常见的英文模式。
要使用该工具,只需将文本粘贴或输入到输入框中,然后点击分析。工具显示总音节数、单词数、每词平均音节数,以及从简单(每词少于1.5个音节)到复杂(超过2.5个)的可读性分类。逐词分析显示各个单词的音节数,帮助你识别哪些单词对文本密度影响最大。这对于诗人调整韵脚、作家调整内容以符合年级水平、或作词人将歌词配合旋律节拍时特别有用。
计数器对无音字母(如"cake"末尾的'e')进行补正,并处理常见的英文模式,如-le结尾。对于不寻常的专有名词或专业术语的最高精度,请参考发音指南交叉验证结果。本工具针对英语进行了优化;其他语言有不同的音节划分规则,可能只能提供近似结果。
常见问题
代码实现
import re
def count_syllables(word: str) -> int:
word = word.lower().strip(".,!?;:'"")
if not word:
return 0
# Special case: silent 'e' at end
if word.endswith('e') and len(word) > 2:
word = word[:-1]
# Count vowel groups
vowels = "aeiouy"
count = 0
prev_was_vowel = False
for char in word:
is_vowel = char in vowels
if is_vowel and not prev_was_vowel:
count += 1
prev_was_vowel = is_vowel
return max(1, count)
def count_syllables_in_text(text: str) -> dict:
words = re.findall(r"[a-zA-Z']+", text)
total = sum(count_syllables(w) for w in words)
return {
"words": len(words),
"syllables": total,
"avg_per_word": round(total / len(words), 2) if words else 0
}
text = "The quick brown fox jumps over the lazy dog"
result = count_syllables_in_text(text)
print(f"Words: {result['words']}")
print(f"Syllables: {result['syllables']}")
print(f"Avg per word: {result['avg_per_word']}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.