Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
72 |
recording = False
|
73 |
last_partial_time = time.time()
|
74 |
current_model = transcriber_tiny # Default to tiny model
|
|
|
75 |
|
76 |
try:
|
77 |
while True:
|
@@ -88,6 +89,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
88 |
# Convert the 16-bit PCM data to float32.
|
89 |
chunk = pcm16_to_float32(data["bytes"])
|
90 |
speech = np.concatenate((speech, chunk))
|
|
|
91 |
if not recording:
|
92 |
# Retain only the last few chunks when not recording.
|
93 |
speech = speech[-lookback_size:]
|
@@ -95,6 +97,7 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
95 |
# Process VAD on the current chunk.
|
96 |
vad_result = vad_iterator(chunk)
|
97 |
current_time = time.time()
|
|
|
98 |
if vad_result:
|
99 |
# If VAD signals the start of speech and we're not already recording.
|
100 |
if "start" in vad_result and not recording:
|
@@ -125,7 +128,9 @@ async def websocket_endpoint(websocket: WebSocket):
|
|
125 |
# Send partial transcription updates periodically.
|
126 |
if (current_time - last_partial_time) > MIN_REFRESH_SECS:
|
127 |
text = current_model(speech)
|
128 |
-
|
|
|
|
|
129 |
last_partial_time = current_time
|
130 |
except WebSocketDisconnect:
|
131 |
# If the client disconnects, send any final transcript if available.
|
|
|
72 |
recording = False
|
73 |
last_partial_time = time.time()
|
74 |
current_model = transcriber_tiny # Default to tiny model
|
75 |
+
last_output = ""
|
76 |
|
77 |
try:
|
78 |
while True:
|
|
|
89 |
# Convert the 16-bit PCM data to float32.
|
90 |
chunk = pcm16_to_float32(data["bytes"])
|
91 |
speech = np.concatenate((speech, chunk))
|
92 |
+
|
93 |
if not recording:
|
94 |
# Retain only the last few chunks when not recording.
|
95 |
speech = speech[-lookback_size:]
|
|
|
97 |
# Process VAD on the current chunk.
|
98 |
vad_result = vad_iterator(chunk)
|
99 |
current_time = time.time()
|
100 |
+
|
101 |
if vad_result:
|
102 |
# If VAD signals the start of speech and we're not already recording.
|
103 |
if "start" in vad_result and not recording:
|
|
|
128 |
# Send partial transcription updates periodically.
|
129 |
if (current_time - last_partial_time) > MIN_REFRESH_SECS:
|
130 |
text = current_model(speech)
|
131 |
+
if last_output != text:
|
132 |
+
last_output = text
|
133 |
+
await websocket.send_json({"type": "partial", "transcript": text})
|
134 |
last_partial_time = current_time
|
135 |
except WebSocketDisconnect:
|
136 |
# If the client disconnects, send any final transcript if available.
|