Created
November 23, 2021 17:13
-
-
Save kingardor/8764e1fb4230a1efe57b2443783e1f5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
import scipy.io.wavfile | |
import scipy.signal | |
if __name__ == '__main__': | |
dir = 'test/audio/' | |
newdir = 'testnew/audio/' | |
files = os.listdir(dir) | |
samplerate = 22050 | |
counter = 0 | |
for f in files: | |
counter += 1 | |
rate, data = scipy.io.wavfile.read(dir+f) | |
print('Count: {}, File: {} | Rate: {} | Samples: {}'.format(counter, f, rate, len(data))) | |
# Calculate new sample | |
samples = len(data) * int(22050/8000) | |
_ = scipy.signal.resample(data, samples).astype(np.int16) | |
n = len(_) | |
assert n == samples | |
# value = _[-1] | |
# __ = np.append(_, value) | |
# n = len(__) | |
# print(n) | |
# assert n == samplerate | |
scipy.io.wavfile.write(newdir+f, samplerate, _) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment