Unrecognized file format error whisper BytesIO, can't write to disk

I used pydub for my solution on the Samsung files, but I am still saving a tempfile. Not sure of any other way.

@app.route('/transcribe', methods=['POST'])
def transcribe_audio():
    print("request received")
    if 'audio' not in request.files:
        return jsonify({"error": "No audio file"}), 400

    audio_file = request.files['audio']

    try:
        # Save the uploaded .3gp file to a temporary file
        with tempfile.NamedTemporaryFile(suffix='.3gp', delete=False) as tmp_3gp:
            audio_file.save(tmp_3gp.name)
            tmp_3gp_path = tmp_3gp.name

        # Convert the .3gp file to .mp3 and save to another temporary file
        with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as tmp_mp3:
            sound = AudioSegment.from_file(tmp_3gp_path, format="3gp")
            sound.export(tmp_mp3.name, format="mp3")
            tmp_mp3_path = tmp_mp3.name

        # Remove the original .3gp temporary file
        os.remove(tmp_3gp_path)

        # OpenAI API call with the converted .mp3 file
        with open(tmp_mp3_path, 'rb') as mp3_file:
            transcript = client.audio.transcriptions.create(
                model="whisper-1",
                file=mp3_file,
                language="en"
            )

        print("transcribed")
        print(transcript)
        return jsonify({"transcription": transcript.text})
    
    except Exception as e:
        traceback.print_exc()
        # Remove temporary files in case of an exception
        os.remove(tmp_3gp_path)
        os.remove(tmp_mp3_path)
        return jsonify({"error": str(e)}), 500
    finally:
        # Cleanup: Ensure temporary files are deleted
        if os.path.exists(tmp_3gp_path):
            os.remove(tmp_3gp_path)
        if os.path.exists(tmp_mp3_path):
            os.remove(tmp_mp3_path)