xujinheng666 commited on
Commit
26db416
·
verified ·
1 Parent(s): 0c70e4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -24,11 +24,22 @@ def transcribe_audio(audio_path):
24
  for start in range(0, int(duration), 50):
25
  end = min(start + 60, int(duration))
26
  chunk = waveform[:, start * sample_rate:end * sample_rate]
 
 
 
 
27
  temp_filename = f"temp_chunk_{start}.wav"
28
  torchaudio.save(temp_filename, chunk, sample_rate)
29
- result = pipe(temp_filename)["text"]
30
- results.append(result)
31
- os.remove(temp_filename)
 
 
 
 
 
 
 
32
  return " ".join(results)
33
 
34
  return pipe(audio_path)["text"]
 
24
  for start in range(0, int(duration), 50):
25
  end = min(start + 60, int(duration))
26
  chunk = waveform[:, start * sample_rate:end * sample_rate]
27
+
28
+ if chunk.shape[1] == 0: # Skip empty chunks
29
+ continue
30
+
31
  temp_filename = f"temp_chunk_{start}.wav"
32
  torchaudio.save(temp_filename, chunk, sample_rate)
33
+
34
+ if os.path.exists(temp_filename):
35
+ try:
36
+ result = pipe(temp_filename)["text"]
37
+ results.append(result)
38
+ finally:
39
+ os.remove(temp_filename) # Delete only if file exists
40
+ else:
41
+ print(f"Warning: File {temp_filename} was not created.")
42
+
43
  return " ".join(results)
44
 
45
  return pipe(audio_path)["text"]