Hammad712 commited on
Commit
a41862f
·
verified ·
1 Parent(s): ef3c29a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -0
main.py CHANGED
@@ -304,6 +304,36 @@ async def root():
304
  "/sessions/{session_id}": "Get session information",
305
  }
306
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
  if __name__ == "__main__":
309
  import uvicorn
 
304
  "/sessions/{session_id}": "Get session information",
305
  }
306
  }
307
+ @app.route('/transcribe-audio', methods=['POST'])
308
+ def transcribe_audio():
309
+ if 'audio' not in request.files:
310
+ return jsonify({"error": "No audio file provided"}), 400
311
+
312
+ audio_file = request.files['audio']
313
+
314
+ # Save the uploaded file temporarily
315
+ temp_path = os.path.join(os.path.dirname(__file__), "temp_audio.m4a")
316
+ audio_file.save(temp_path)
317
+
318
+ try:
319
+ # Use Groq client to transcribe the audio
320
+ with open(temp_path, "rb") as file:
321
+ transcription = client.audio.transcriptions.create(
322
+ file=(temp_path, file.read()),
323
+ model="whisper-large-v3",
324
+ response_format="verbose_json",
325
+ )
326
+
327
+ # Return the transcription result
328
+ return jsonify({"transcription": transcription.text})
329
+
330
+ except Exception as e:
331
+ return jsonify({"error": str(e)}), 500
332
+
333
+ finally:
334
+ # Clean up the temporary file
335
+ if os.path.exists(temp_path):
336
+ os.remove(temp_path)
337
 
338
  if __name__ == "__main__":
339
  import uvicorn