Spaces:
Sleeping
Sleeping
audio file tempo path updated
Browse files
app.py
CHANGED
|
@@ -56,14 +56,16 @@ def process_audio():
|
|
| 56 |
audio_file = request.files['audio']
|
| 57 |
print("AUDIO FILE NAME: ", audio_file)
|
| 58 |
|
|
|
|
| 59 |
try:
|
| 60 |
print("STARTING TRANSCRIPTION, ANIKET")
|
| 61 |
|
| 62 |
-
# Step 1: Save the audio file temporarily
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
# Step 2: Transcribe the uploaded audio file synchronously
|
| 69 |
transcription = transcribe_audio(temp_audio_path)
|
|
@@ -86,6 +88,13 @@ def process_audio():
|
|
| 86 |
except Exception as e:
|
| 87 |
return jsonify({"error": str(e)}), 500
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
def transcribe_audio(wav_file_path):
|
| 91 |
"""
|
|
|
|
| 56 |
audio_file = request.files['audio']
|
| 57 |
print("AUDIO FILE NAME: ", audio_file)
|
| 58 |
|
| 59 |
+
temp_audio_path = None
|
| 60 |
try:
|
| 61 |
print("STARTING TRANSCRIPTION, ANIKET")
|
| 62 |
|
| 63 |
+
# Step 1: Save the audio file temporarily to a specific location
|
| 64 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as temp_audio_file:
|
| 65 |
+
temp_audio_path = temp_audio_file.name # Get the file path
|
| 66 |
+
temp_audio_file.write(audio_file.read()) # Write the uploaded audio to the temp file
|
| 67 |
+
|
| 68 |
+
print(f"Temporary audio file saved at: {temp_audio_path}")
|
| 69 |
|
| 70 |
# Step 2: Transcribe the uploaded audio file synchronously
|
| 71 |
transcription = transcribe_audio(temp_audio_path)
|
|
|
|
| 88 |
except Exception as e:
|
| 89 |
return jsonify({"error": str(e)}), 500
|
| 90 |
|
| 91 |
+
finally:
|
| 92 |
+
# Clean up the temporary WAV file
|
| 93 |
+
if temp_audio_path and os.path.exists(temp_audio_path):
|
| 94 |
+
os.remove(temp_audio_path)
|
| 95 |
+
print(f"Temporary WAV file deleted: {temp_audio_path}")
|
| 96 |
+
|
| 97 |
+
|
| 98 |
|
| 99 |
def transcribe_audio(wav_file_path):
|
| 100 |
"""
|