a basic duplex agent is built
This commit is contained in:
@@ -269,6 +269,15 @@ class MicrophoneClient:
|
||||
print("← User speech detected")
|
||||
elif event_type == "silence":
|
||||
print("← User silence detected")
|
||||
elif event_type == "transcript":
|
||||
# Display user speech transcription
|
||||
text = event.get("text", "")
|
||||
is_final = event.get("isFinal", False)
|
||||
if is_final:
|
||||
print(f"← You said: {text}")
|
||||
else:
|
||||
# Interim result - show with indicator
|
||||
print(f"← [listening] {text}", end="\r")
|
||||
elif event_type == "trackStart":
|
||||
print("← Bot started speaking")
|
||||
# Clear any old audio in buffer
|
||||
|
||||
@@ -129,11 +129,21 @@ class SimpleVoiceClient:
|
||||
# JSON event
|
||||
event = json.loads(msg)
|
||||
etype = event.get("event", "?")
|
||||
print(f"<- {etype}")
|
||||
|
||||
if etype == "hangup":
|
||||
if etype == "transcript":
|
||||
# User speech transcription
|
||||
text = event.get("text", "")
|
||||
is_final = event.get("isFinal", False)
|
||||
if is_final:
|
||||
print(f"<- You said: {text}")
|
||||
else:
|
||||
print(f"<- [listening] {text}", end="\r")
|
||||
elif etype == "hangup":
|
||||
print(f"<- {etype}")
|
||||
self.running = False
|
||||
break
|
||||
else:
|
||||
print(f"<- {etype}")
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user