xujinheng666 commited on
Commit
80fad5a
·
verified ·
1 Parent(s): 26db416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -29,17 +29,26 @@ def transcribe_audio(audio_path):
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"]
 
29
  continue
30
 
31
  temp_filename = f"temp_chunk_{start}.wav"
32
+
33
+ # Save the chunk only if it contains valid data
34
+ try:
35
+ torchaudio.save(temp_filename, chunk, sample_rate)
36
+ if not os.path.exists(temp_filename):
37
+ print(f"Error: {temp_filename} was not created!")
38
+ continue
39
+
40
+ result = pipe(temp_filename)["text"]
41
+ results.append(result)
42
 
43
+ except Exception as e:
44
+ print(f"Error processing {temp_filename}: {e}")
45
+
46
+ finally:
47
+ if os.path.exists(temp_filename):
48
+ os.remove(temp_filename) # Ensure file is deleted safely
49
+ else:
50
+ print(f"Warning: File {temp_filename} was not found for deletion.")
51
+
52
  return " ".join(results)
53
 
54
  return pipe(audio_path)["text"]