AshDavid12 commited on
Commit
bee3bf4
·
1 Parent(s): a3f668c

prev works, adujsting time

Browse files
Files changed (1) hide show
  1. infer.py +2 -10
infer.py CHANGED
@@ -176,7 +176,7 @@ def transcribe_core_ws(audio_file, last_transcribed_time):
176
  ret['new_segments'].append(seg)
177
 
178
  # Update the last transcribed time to the end of the current segment
179
- new_last_transcribed_time = max(new_last_transcribed_time, s.end)
180
  logging.debug(f"Updated last transcribed time to: {new_last_transcribed_time} seconds")
181
 
182
  #logging.info(f"Returning {len(ret['new_segments'])} new segments and updated last transcribed time.")
@@ -194,8 +194,6 @@ async def websocket_transcribe(websocket: WebSocket):
194
 
195
  try:
196
  processed_segments = [] # Keeps track of the segments already transcribed
197
- accumulated_audio_size = 0 # Track how much audio data has been buffered
198
- accumulated_audio_time = 0 # Track the total audio duration accumulated
199
  last_transcribed_time = 0.0
200
  #min_transcription_time = 5.0 # Minimum duration of audio in seconds before transcription starts
201
 
@@ -214,16 +212,11 @@ async def websocket_transcribe(websocket: WebSocket):
214
  # Write audio chunk to file and accumulate size and time
215
  temp_audio_file.write(audio_chunk)
216
  temp_audio_file.flush()
217
- accumulated_audio_size += len(audio_chunk)
218
 
219
- # Estimate the duration of the chunk based on its size (e.g., 16kHz audio)
220
- chunk_duration = len(audio_chunk) / (16000 * 2) # Assuming 16kHz mono WAV (2 bytes per sample)
221
- accumulated_audio_time += chunk_duration
222
- logging.info(f"Received and buffered {len(audio_chunk)} bytes, total buffered: {accumulated_audio_size} bytes, total time: {accumulated_audio_time:.2f} seconds")
223
 
224
  # Transcribe when enough time (audio) is accumulated (e.g., at least 5 seconds of audio)
225
  #if accumulated_audio_time >= min_transcription_time:
226
- logging.info("Buffered enough audio time, starting transcription.")
227
 
228
 
229
  # Call the transcription function with the last processed time
@@ -232,7 +225,6 @@ async def websocket_transcribe(websocket: WebSocket):
232
  processed_segments.extend(partial_result['new_segments'])
233
 
234
  # Reset the accumulated audio size after transcription
235
- accumulated_audio_size = 0
236
 
237
  # Send the transcription result back to the client with both new and all processed segments
238
  response = {
 
176
  ret['new_segments'].append(seg)
177
 
178
  # Update the last transcribed time to the end of the current segment
179
+ new_last_transcribed_time = s.end
180
  logging.debug(f"Updated last transcribed time to: {new_last_transcribed_time} seconds")
181
 
182
  #logging.info(f"Returning {len(ret['new_segments'])} new segments and updated last transcribed time.")
 
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
 
 
212
  # Write audio chunk to file and accumulate size and time
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
 
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 = {