Spaces:
Sleeping
Sleeping
Download modules/utils/detect_lang.py from ProbablyBlue/ChatTTS-Forge: direct link, hf CLI and curl.
- Browser
- Download file 527 Bytes
-
https://huggingface.co/spaces/ProbablyBlue/ChatTTS-Forge/resolve/main/modules/utils/detect_lang.py
- Command line
-
hf download hf://spaces/ProbablyBlue/ChatTTS-Forge/modules/utils/detect_lang.py
-
curl -L -o detect_lang.py https://huggingface.co/spaces/ProbablyBlue/ChatTTS-Forge/resolve/main/modules/utils/detect_lang.py
527 Bytes
| from functools import lru_cache | |
| from typing import Literal | |
| def is_chinese(text): | |
| for char in text: | |
| if "\u4e00" <= char <= "\u9fff": | |
| return True | |
| return False | |
| def is_eng(text): | |
| for char in text: | |
| if "a" <= char.lower() <= "z": | |
| return True | |
| return False | |
| def guess_lang(text) -> Literal["zh", "en"]: | |
| if is_chinese(text): | |
| return "zh" | |
| if is_eng(text): | |
| return "en" | |
| return "zh" | |