0
from pydub import AudioSegment

# Set the paths to the audio files
file1_path = '1.wav'
file2_path = '2.wav'

# Load the audio files
file1 = AudioSegment.from_file(file1_path, format='wav')
file2 = AudioSegment.from_file(file2_path, format='wav')

# Get the duration of the audio files in seconds
original_duration = len(file1)  # in milliseconds
desired_duration = len(file2)  # in milliseconds

# Calculate the factor by which to increase the frame rate
factor =  (round(original_duration)/desired_duration)

# Increase the frame rate by the calculated factor
stretched_audio = file2.set_frame_rate(int(file2.frame_rate * factor)).speedup()

# Save the modified audio
stretched_audio.export("output.wav", format="wav")

This code is not working.

I want to match the duration of two audios with each other, basically trying to make it of the same length, and without trimming it.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
shivam jha
  • 11
  • 4

0 Answers0