49
49
50
50
load_dotenv (override = True )
51
51
52
+
52
53
@asynccontextmanager
53
54
async def lifespan (app : FastAPI ):
54
55
"""Handles FastAPI startup and shutdown."""
@@ -70,8 +71,8 @@ async def lifespan(app: FastAPI):
70
71
# Mount the frontend at /
71
72
app .mount ("/client" , SmallWebRTCPrebuiltUI )
72
73
73
- class SimulateFreezeInput (FrameProcessor ):
74
74
75
+ class SimulateFreezeInput (FrameProcessor ):
75
76
def __init__ (
76
77
self ,
77
78
** kwargs ,
@@ -123,11 +124,13 @@ async def _send_frames(self):
123
124
# Emulation as if the user has spoken and the stt transcribed
124
125
await self .push_frame (UserStartedSpeakingFrame ())
125
126
await self .push_frame (StartInterruptionFrame ())
126
- await self .push_frame (TranscriptionFrame (
127
- "Count from 01 to 20!" ,
128
- "" ,
129
- time_now_iso8601 (),
130
- ))
127
+ await self .push_frame (
128
+ TranscriptionFrame (
129
+ "Count from 01 to 20!" ,
130
+ "" ,
131
+ time_now_iso8601 (),
132
+ )
133
+ )
131
134
await self .push_frame (UserStoppedSpeakingFrame ())
132
135
# sleeping 1s before interrupting
133
136
wait_time = random .uniform (1 , 10 )
@@ -136,7 +139,6 @@ async def _send_frames(self):
136
139
logger .error (f"{ self } exception receiving data: { e .__class__ .__name__ } ({ e } )" )
137
140
138
141
139
-
140
142
async def run_example (websocket_client ):
141
143
logger .info (f"Starting bot" )
142
144
@@ -177,7 +179,7 @@ async def run_example(websocket_client):
177
179
178
180
pipeline = Pipeline (
179
181
[
180
- #freeze,
182
+ # freeze,
181
183
transport .input (),
182
184
rtvi ,
183
185
stt ,
@@ -197,7 +199,7 @@ async def run_example(websocket_client):
197
199
enable_usage_metrics = True ,
198
200
report_only_initial_ttfb = True ,
199
201
),
200
- idle_timeout_secs = 120
202
+ idle_timeout_secs = 120 ,
201
203
)
202
204
203
205
@transport .event_handler ("on_client_connected" )
@@ -236,6 +238,7 @@ async def websocket_endpoint(websocket: WebSocket):
236
238
except Exception as e :
237
239
print (f"Exception in run_bot: { e } " )
238
240
241
+
239
242
@app .post ("/connect" )
240
243
async def bot_connect (request : Request ) -> Dict [Any , Any ]:
241
244
server_mode = os .getenv ("WEBSOCKET_SERVER" , "fast_api" )
0 commit comments