Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pydub import AudioSegment
- from pydub.utils import make_chunks
- import csv
- import os
- from pprint import pprint
- chunk_s = 2000
- natives = {}
- with open('speakers_all.csv', 'r') as f:
- reader = csv.reader(f)
- next(reader) # skipting header
- for row in reader:
- native = row[4]
- filename = row[3]
- fn = 'recordings/' + filename + '.wav'
- if native in natives:
- natives[native].append(fn)
- else:
- natives[native] = [fn]
- # pprint(natives)
- for k, v in natives.items():
- fp = 'recordings/' + k
- os.mkdir(fp)
- for fn in v:
- audio = AudioSegment.from_wav(fn)
- chunks = make_chunks(audio, chunk_s)
- l = len(chunks)
- for i, ch in enumerate(chunks):
- if i == 0 or i == (l - 1):
- continue
- ch.export(fp + '/' + k + str(i) + '.wav', format='wav')
Add Comment
Please, Sign In to add comment