HChandeepa/PulmoSense_AI
0
1from pydub import AudioSegment2import tempfile3 4def convert(input_stream, output_file_path):5 try:6 # Save uploaded file temporarily7 with tempfile.NamedTemporaryFile(delete=False) as tmp:8 tmp.write(input_stream.read())9 tmp_path = tmp.name10 11 # Read and convert audio using pydub12 audio = AudioSegment.from_file(tmp_path)13 audio = audio.set_frame_rate(22500).set_channels(1)14 audio.export(output_file_path, format="wav")15 16 return True17 except Exception as e:18 print(f"[Audio Conversion Error]: {e}")19 return False20 