-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (29 loc) · 1012 Bytes
/
utils.py
File metadata and controls
39 lines (29 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
def coerce_partial_utterances(value: object, default: bool = False) -> bool:
if isinstance(value, bool):
return value
if isinstance(value, (int, float)):
return value != 0
if isinstance(value, str):
normalized = value.strip().lower()
if normalized in {"true", "1", "t", "yes", "y"}:
return True
if normalized in {"false", "0", "f", "no", "n"}:
return False
return default
def coerce_min_utterance_length_seconds(value: object, default: float = 0.0) -> float:
if value in (None, ""):
return default
try:
parsed = float(value)
except (TypeError, ValueError):
logging.warning(
f"Invalid minUtteranceLength value '{value}', falling back to {default}."
)
return default
if parsed < 0:
logging.warning(
f"Negative minUtteranceLength value '{value}', clamping to {default}."
)
return default
return parsed