Skip to content

Commit b23a963

Browse files
committed
Automatically sending the recording once the recording is ready.
1 parent 3475c3e commit b23a963

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

examples/freeze_test/client/src/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class RecordingSerializer extends ProtobufFrameSerializer {
6060
}
6161

6262
class WebsocketClientApp {
63+
private RECORDING_TIME_MS = 5000
64+
6365
private rtviClient: RTVIClient | null = null;
6466
private connectBtn: HTMLButtonElement | null = null;
6567
private disconnectBtn: HTMLButtonElement | null = null;
@@ -240,10 +242,11 @@ class WebsocketClientApp {
240242

241243
this.log("Starting to recording the next 05s of audio");
242244
this.recordingSerializer.startRecording()
243-
await this.sleep(5000)
245+
await this.sleep(this.RECORDING_TIME_MS)
244246
this.recordingSerializer.stopRecording()
245247
this.log("Recording stopped");
246248
this.rtviClient.enableMic(false)
249+
this.startSendingRecordedAudio()
247250
} catch (error) {
248251
this.log(`Error connecting: ${(error as Error).message}`);
249252
this.updateStatus('Error');

examples/freeze_test/freeze_test_bot.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
load_dotenv(override=True)
5151

52+
5253
@asynccontextmanager
5354
async def lifespan(app: FastAPI):
5455
"""Handles FastAPI startup and shutdown."""
@@ -70,8 +71,8 @@ async def lifespan(app: FastAPI):
7071
# Mount the frontend at /
7172
app.mount("/client", SmallWebRTCPrebuiltUI)
7273

73-
class SimulateFreezeInput(FrameProcessor):
7474

75+
class SimulateFreezeInput(FrameProcessor):
7576
def __init__(
7677
self,
7778
**kwargs,
@@ -123,11 +124,13 @@ async def _send_frames(self):
123124
# Emulation as if the user has spoken and the stt transcribed
124125
await self.push_frame(UserStartedSpeakingFrame())
125126
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+
)
131134
await self.push_frame(UserStoppedSpeakingFrame())
132135
# sleeping 1s before interrupting
133136
wait_time = random.uniform(1, 10)
@@ -136,7 +139,6 @@ async def _send_frames(self):
136139
logger.error(f"{self} exception receiving data: {e.__class__.__name__} ({e})")
137140

138141

139-
140142
async def run_example(websocket_client):
141143
logger.info(f"Starting bot")
142144

@@ -177,7 +179,7 @@ async def run_example(websocket_client):
177179

178180
pipeline = Pipeline(
179181
[
180-
#freeze,
182+
# freeze,
181183
transport.input(),
182184
rtvi,
183185
stt,
@@ -197,7 +199,7 @@ async def run_example(websocket_client):
197199
enable_usage_metrics=True,
198200
report_only_initial_ttfb=True,
199201
),
200-
idle_timeout_secs=120
202+
idle_timeout_secs=120,
201203
)
202204

203205
@transport.event_handler("on_client_connected")
@@ -236,6 +238,7 @@ async def websocket_endpoint(websocket: WebSocket):
236238
except Exception as e:
237239
print(f"Exception in run_bot: {e}")
238240

241+
239242
@app.post("/connect")
240243
async def bot_connect(request: Request) -> Dict[Any, Any]:
241244
server_mode = os.getenv("WEBSOCKET_SERVER", "fast_api")

0 commit comments

Comments
 (0)