Update app.py
Browse files
app.py
CHANGED
@@ -29,17 +29,26 @@ def transcribe_audio(audio_path):
|
|
29 |
continue
|
30 |
|
31 |
temp_filename = f"temp_chunk_{start}.wav"
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
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"]
|