wren applies all/every commands itself, answers temperatures, reads aliases and number words; tts says units and clock times
wren's model answers "turn off all lights" with one call, and at 0.98 a
living room light switched on. The node now applies such a command to every
wired target of the kind. Number words become digits ("in five minutes"
lost its delay), aliases put the house's words and known mishearings in the
model's, and sensors.temperature is answered from <area>_temperature or
outdoor. tts writes out units and clock times before speaking.
This commit is contained in:
@@ -44,6 +44,15 @@ PLAYING_SLACK_S = 1.0
|
||||
#: The partial for an utterance that came back empty, often a wake word that
|
||||
#: was not one, or was lost: shown on the caption, never spoken.
|
||||
NOTHING_HEARD = "Didn't catch that."
|
||||
#: Units read out after a number, the longer first. Kokoro says "22 °C" as
|
||||
#: "22 degrees C" and "3.4 kWh" letter by letter.
|
||||
UNITS = {
|
||||
"°C": "degrees",
|
||||
"°": "degrees",
|
||||
"kWh": "kilowatt hours",
|
||||
"kW": "kilowatts",
|
||||
"W": "watts",
|
||||
}
|
||||
|
||||
|
||||
def _check(specs: list[MessageSpec], ports: dict[str, DType], node: str) -> None:
|
||||
@@ -70,6 +79,23 @@ def sentences(text: str) -> list[str]:
|
||||
return [s for s in (p.strip() for p in re.split(r"(?<=[.!?])\s+", text)) if s]
|
||||
|
||||
|
||||
def speakable(text: str) -> str:
|
||||
"""``text`` as it is said: a unit after a number in words, and a clock
|
||||
time as its hour and minutes, since "07:30" is read "zero seven thirty"."""
|
||||
units = "|".join(map(re.escape, UNITS))
|
||||
text = re.sub(
|
||||
rf"(\d)\s*({units})(?![A-Za-z])", lambda m: f"{m[1]} {UNITS[m[2]]}", text
|
||||
)
|
||||
return re.sub(r"\b([01]?\d|2[0-3]):([0-5]\d)\b", _clock, text)
|
||||
|
||||
|
||||
def _clock(time: re.Match[str]) -> str:
|
||||
hour, minute = int(time[1]), int(time[2])
|
||||
if minute == 0:
|
||||
return f"{hour} o'clock"
|
||||
return f"{hour} oh {minute}" if minute < 10 else f"{hour} {minute}"
|
||||
|
||||
|
||||
def mp3_seconds(data: bytes) -> float:
|
||||
"""An MP3's length, from the frame count LAME writes into its first frame."""
|
||||
header = int.from_bytes(data[:4], "big")
|
||||
@@ -358,7 +384,7 @@ class TtsNode(_Speech):
|
||||
if not text.strip() or not self._reachable(url):
|
||||
return None
|
||||
with self._lock:
|
||||
for sentence in sentences(text):
|
||||
for sentence in sentences(speakable(text)):
|
||||
reference = self._spoken(url, sentence)
|
||||
now = time.monotonic()
|
||||
if now < self._until + PLAYING_SLACK_S:
|
||||
|
||||
Reference in New Issue
Block a user