feat: the brain can change the box's speaker volume
"Speak up" and "too loud" now work: the reply tool takes louder, in percentage points, and the button service nudges the speaker's softvol before it speaks that reply, so the person hears the change at once. The box keeps the level between 10% and 80% (body/mixer.py). No new port or key: the volume changes only with a reply, in a conversation someone is listening to. Generated-by: Claude Opus 5.5
This commit is contained in:
1 parent
cf503ac247
commit
5191ee9931
11 files changed
+146
-21
No files matched your search
+35
-4
@@ -1,17 +1,18 @@
|
||||
"""One conversation with the box, from the press that opened it to goodbye.
|
||||
|
||||
Everything it touches comes in as a function: listen, transcribe, ask, speak, play, the LED.
|
||||
Everything it touches comes in as a function: listen, transcribe, ask, speak, play, the volume, the LED.
|
||||
"""
|
||||
from contextlib import aclosing
|
||||
|
||||
|
||||
async def converse(convo, listen, transcribe, ask, speak, play, led, thinking, end, log,
|
||||
async def converse(convo, listen, transcribe, ask, speak, play, louder, led, thinking, end, log,
|
||||
note=lambda kind, **data: None):
|
||||
"""One conversation, from the press that opened it to goodbye.
|
||||
|
||||
Async: listen(skip_s) returns ("speech", clip), ("quiet", None), or ("press", None).
|
||||
play(name) starts an earcon and returns its length, which listen skips.
|
||||
ask(text, convo) yields ("say", text), then ("reply", text, end); or ("press",).
|
||||
ask(text, convo) yields ("say", text), perhaps ("louder", points), then ("reply", text, end); or ("press",).
|
||||
louder(points) changes the speaker volume, before the reply is spoken, and returns the new level.
|
||||
speak(text) returns False if a press interrupted it. end(convo) tells the brain.
|
||||
Not async: led(on), thinking(on), log(msg), and
|
||||
note(kind, ...) counts it for a status page: turn, huh, interrupt, end.
|
||||
@@ -25,6 +26,9 @@ async def converse(convo, listen, transcribe, ask, speak, play, led, thinking, e
|
||||
... if text == "Switch to the PC.":
|
||||
... yield ("say", "Let me try.")
|
||||
... yield ("reply", "Done.", False)
|
||||
... elif text == "Speak up!":
|
||||
... yield ("louder", 10)
|
||||
... yield ("reply", "Is this better?", False)
|
||||
... elif text == "Thanks!":
|
||||
... yield ("reply", "You're welcome. Bye!", True)
|
||||
... else:
|
||||
@@ -33,7 +37,8 @@ async def converse(convo, listen, transcribe, ask, speak, play, led, thinking, e
|
||||
>>> async def speak(text): return print("speak", text) or True
|
||||
>>> async def play(name): return print("play", name) or 0.4
|
||||
>>> async def end(convo): print("end", convo)
|
||||
>>> ops = dict(transcribe=transcribe, ask=ask, speak=speak, play=play, end=end, log=print,
|
||||
>>> async def louder(points): return 45 + points
|
||||
>>> ops = dict(transcribe=transcribe, ask=ask, speak=speak, play=play, louder=louder, end=end, log=print,
|
||||
... led=lambda on: print("led", on), thinking=lambda on: print("thinking", on))
|
||||
>>> run = lambda convo, listen, **kw: asyncio.run(converse(convo, listen, **kw))
|
||||
>>> run("k1", script(("speech", "Switch to the PC."), ("speech", "Thanks!")), **ops)
|
||||
@@ -62,6 +67,26 @@ async def converse(convo, listen, transcribe, ask, speak, play, led, thinking, e
|
||||
play bye
|
||||
end k1
|
||||
|
||||
The brain can turn the volume up or down; the box does so before it speaks the reply:
|
||||
|
||||
>>> run("k4", script(("speech", "Speak up!"), ("press", None)), **ops)
|
||||
play open
|
||||
led True
|
||||
led False
|
||||
play gotit
|
||||
thinking True
|
||||
k4 heard: Speak up!
|
||||
k4: volume 55%
|
||||
thinking False
|
||||
speak Is this better?
|
||||
thinking False
|
||||
play turn
|
||||
led True
|
||||
led False
|
||||
k4: press; goodbye
|
||||
play bye
|
||||
end k4
|
||||
|
||||
A press while the agent thinks interrupts it; silence ends the conversation:
|
||||
|
||||
>>> run("k2", script(("speech", "Tell me a long story."), ("quiet", None)), **ops)
|
||||
@@ -143,6 +168,12 @@ async def converse(convo, listen, transcribe, ask, speak, play, led, thinking, e
|
||||
try:
|
||||
async with aclosing(ask(text, convo)) as events: # a break closes it now, not someday
|
||||
async for event in events:
|
||||
if event[0] == "louder":
|
||||
try:
|
||||
log(f"{convo}: volume {await louder(event[1])}%")
|
||||
except Exception as err:
|
||||
log(f"{convo}: volume change failed: {err}")
|
||||
continue
|
||||
thinking(False)
|
||||
if event[0] == "press" or not await speak(event[1]):
|
||||
interrupted = True
|
||||
|
||||
Reference in new issue
Block a user