MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS-Nano / WeTextProcessingManager

Class WeTextProcessingManager

text_normalization_pipeline.py:29–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29class WeTextProcessingManager:
30 def __init__(self) -> None:
31 self._lock = threading.Lock()
32 self._normalize_lock = threading.Lock()
33 self._thread: threading.Thread | None = None
34 self._started = False
35 self._state = "pending"
36 self._message = "Waiting for WeTextProcessing preload."
37 self._error: str | None = None
38 self._available = True
39 self._normalizers: dict[str, object] | None = None
40
41 def snapshot(self) -> TextNormalizationSnapshot:
42 with self._lock:
43 return TextNormalizationSnapshot(
44 state=self._state,
45 message=self._message,
46 error=self._error,
47 ready=self._state == "ready",
48 available=self._available,
49 )
50
51 def _set_state(self, *, state: str, message: str, error: str | None = None) -> None:
52 with self._lock:
53 self._state = state
54 self._message = message
55 self._error = error
56
57 def start(self) -> None:
58 with self._lock:
59 if self._started:
60 return
61 self._started = True
62 self._thread = threading.Thread(target=self._run, name="wetext-preload", daemon=True)
63 self._thread.start()
64
65 def ensure_ready(self) -> TextNormalizationSnapshot:
66 with self._lock:
67 if not self._started:
68 self._started = True
69 self._thread = threading.Thread(target=self._run, name="wetext-preload", daemon=True)
70 self._thread.start()
71 thread = self._thread
72 if thread is not None and thread.is_alive():
73 thread.join()
74 return self.snapshot()
75
76 def close(self) -> None:
77 return
78
79 def _run(self) -> None:
80 if not self._available:
81 self._set_state(
82 state="failed",
83 message="WeTextProcessing unavailable.",
84 error="installed WeTextProcessing modules are unavailable",
85 )
86 return

Callers 3

mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected