GoodML commited on
Commit
4bfe417
·
verified ·
1 Parent(s): 65501bb

audio file tempo path updated

Browse files
Files changed (1) hide show
  1. app.py +14 -5
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
- # Save the audio file to a temporary location for processing
64
- temp_audio_path = "/path/to/save/audio.wav" # Adjust this as needed
65
- with open(temp_audio_path, 'wb') as f:
66
- f.write(audio_file.read())
 
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
  """