1

I was trying to combine multiple wav files in python using pydub but the output song's playback speed was kinda slower than I wanted. So I referred to this question and tried the same.

import os, glob 
import random
from pydub import AudioSegment 

FRAMERATE = 44100 # The frequency of default wav file 
OUTPUT_FILE = 'MySong/random.wav'

audio_data = [AudioSegment.from_wav(wavfile) 
                for wavfile in glob.glob(os.path.join('wav_files/', '*.wav'))]

my_music = sum([random.choice(audio_data)for i in range(100)])

my_music = my_music.set_frame_rate(FRAMERATE * 4)
my_music.export(OUTPUT_FILE, format='wav') 

But this isn't working. Is there any technical reason I'm unaware of, or is there any better way of doing it?

Community
  • 1
  • 1
hashcode55
  • 5,622
  • 4
  • 27
  • 40
  • set_frame_rate does a conversion - it doesn’t (at least shouldn’t) affect playback speed. Is it playing back in slowmo (with lowered pitches and speed together) or is it playing accurately and you would like to keep pitch the same but increase the pace? – Jiaaro Jan 10 '17 at 14:19
  • @Jiaaro Nopes, its not playing in slowmo. And yeah I want to keep the pitch same, just increase the pace. – hashcode55 Jan 10 '17 at 14:33

1 Answers1

0

to increase pace without changing pitch, you’ll need to do something a little fancier than changing the frame rate (which will give you a “chipmunk” effect).

If you’re dealing with spoken word, you can try stripping out silence with the (unfortunately undocumented) functions in pydub.silence.

You can also look at AudioSegment().speedup() which is a naive attempt at resampling. You can also make a copy of that function and try to improve it (and contribute back to pydub?)

Jiaaro
  • 74,485
  • 42
  • 169
  • 190