app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from pydub import AudioSegment def hhmmss_to_milliseconds(time_str): h, m, s = map(int, time_str.split(':')) return ((h * 3600) + (m * 60) + s) * 1000 # Load audio file song = AudioSegment.from_file("sample.mp3", format="mp3") # Take input from user start_time = input("Enter start time (HH:MM:SS): ") end_time = input("Enter end time (HH:MM:SS): ") # Convert to milliseconds start_ms = hhmmss_to_milliseconds(start_time) end_ms = hhmmss_to_milliseconds(end_time) # Slice the audio clip = song[start_ms:end_ms] # Export new audio clip clip.export("Mid.mp3", format="mp3") print("New Audio file is created and saved as Mid.mp3") |