-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho.py
More file actions
40 lines (29 loc) · 859 Bytes
/
echo.py
File metadata and controls
40 lines (29 loc) · 859 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
40
from __future__ import annotations
import logging
import os
from logging import getLogger
from dotenv import load_dotenv
from stackchan_server.app import StackChanApp
from stackchan_server.ws_proxy import EmptyTranscriptError, WsProxy
logger = getLogger(__name__)
logging.basicConfig(
level=os.getenv("STACKCHAN_LOG_LEVEL", "INFO"),
format="%(asctime)s.%(msecs)03d %(levelname)s:%(name)s:%(message)s",
datefmt="%H:%M:%S",
)
load_dotenv()
app = StackChanApp()
@app.setup
async def setup(proxy: WsProxy):
logger.info("WebSocket connected")
@app.talk_session
async def talk_session(proxy: WsProxy):
while True:
try:
text = await proxy.listen()
except EmptyTranscriptError:
return
if not text:
return
logger.info("Heard: %s", text)
await proxy.speak(text)