Spaces:
Sleeping
Sleeping
AshDavid12
commited on
Commit
·
fe056ae
1
Parent(s):
bee3bf4
fixing timing and changing new segs[]
Browse files
infer.py
CHANGED
@@ -184,7 +184,7 @@ def transcribe_core_ws(audio_file, last_transcribed_time):
|
|
184 |
|
185 |
|
186 |
import tempfile
|
187 |
-
|
188 |
|
189 |
@app.websocket("/wtranscribe")
|
190 |
async def websocket_transcribe(websocket: WebSocket):
|
@@ -194,8 +194,6 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
194 |
|
195 |
try:
|
196 |
processed_segments = [] # Keeps track of the segments already transcribed
|
197 |
-
last_transcribed_time = 0.0
|
198 |
-
#min_transcription_time = 5.0 # Minimum duration of audio in seconds before transcription starts
|
199 |
|
200 |
# A temporary file to store the growing audio data
|
201 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
|
@@ -213,25 +211,21 @@ async def websocket_transcribe(websocket: WebSocket):
|
|
213 |
temp_audio_file.write(audio_chunk)
|
214 |
temp_audio_file.flush()
|
215 |
|
216 |
-
|
217 |
-
# Transcribe when enough time (audio) is accumulated (e.g., at least 5 seconds of audio)
|
218 |
-
#if accumulated_audio_time >= min_transcription_time:
|
219 |
-
#logging.info("Buffered enough audio time, starting transcription.")
|
220 |
-
|
221 |
-
|
222 |
# Call the transcription function with the last processed time
|
223 |
partial_result, last_transcribed_time = transcribe_core_ws(temp_audio_file.name, last_transcribed_time)
|
224 |
accumulated_audio_time = 0 # Reset the accumulated audio time
|
225 |
-
processed_segments.extend(partial_result['new_segments'])
|
226 |
-
|
227 |
-
# Reset the accumulated audio size after transcription
|
228 |
|
229 |
-
# Send the transcription result back to the client with both new and all processed segments
|
230 |
response = {
|
231 |
"new_segments": partial_result['new_segments'],
|
232 |
"processed_segments": processed_segments
|
233 |
}
|
234 |
logging.info(f"Sending {len(partial_result['new_segments'])} new segments to the client.")
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
await websocket.send_json(response)
|
236 |
|
237 |
except WebSocketDisconnect:
|
|
|
184 |
|
185 |
|
186 |
import tempfile
|
187 |
+
last_transcribed_time = 0.0
|
188 |
|
189 |
@app.websocket("/wtranscribe")
|
190 |
async def websocket_transcribe(websocket: WebSocket):
|
|
|
194 |
|
195 |
try:
|
196 |
processed_segments = [] # Keeps track of the segments already transcribed
|
|
|
|
|
197 |
|
198 |
# A temporary file to store the growing audio data
|
199 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio_file:
|
|
|
211 |
temp_audio_file.write(audio_chunk)
|
212 |
temp_audio_file.flush()
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
# Call the transcription function with the last processed time
|
215 |
partial_result, last_transcribed_time = transcribe_core_ws(temp_audio_file.name, last_transcribed_time)
|
216 |
accumulated_audio_time = 0 # Reset the accumulated audio time
|
|
|
|
|
|
|
217 |
|
|
|
218 |
response = {
|
219 |
"new_segments": partial_result['new_segments'],
|
220 |
"processed_segments": processed_segments
|
221 |
}
|
222 |
logging.info(f"Sending {len(partial_result['new_segments'])} new segments to the client.")
|
223 |
+
processed_segments.extend(partial_result['new_segments'])
|
224 |
+
|
225 |
+
# Reset the accumulated audio size after transcription
|
226 |
+
|
227 |
+
# Send the transcription result back to the client with both new and all processed segments
|
228 |
+
|
229 |
await websocket.send_json(response)
|
230 |
|
231 |
except WebSocketDisconnect:
|