Advertisement
Guest User

Untitled

a guest
Sep 18th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. from pydub import AudioSegment
  2. def convert_audio(input_file, output_file):
  3. audio = AudioSegment.from_mp3(input_file)
  4. audio = audio.set_channels(1) # Convert to mono
  5. audio = audio.set_frame_rate(16000) # Set sample rate to 16kHz
  6. audio = audio.set_sample_width(2) # Set sample width to 2 bytes (16-bit)
  7. audio.export(output_file, format="wav")
  8.  
  9. # Usage
  10. input_mp3 = "r:\\sandi.mp3"
  11. output_wav = "r:\\sandi.wav"
  12. convert_audio(input_mp3, output_wav)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement