Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from pydub import AudioSegment
- from os import listdir, chdir
- from os.path import isfile, join
- from scipy.fft import *
- from scipy.io import wavfile
- from termcolor import colored
- path = "C:\\Users\\HP\\Downloads\\TMF\\TMF-audio\\"
- chdir(path)
- def amplitude(file): #.wav files only
- return AudioSegment.from_wav(path + file).max
- def duration(file):
- return AudioSegment.from_wav(path + file).duration_seconds*1000
- def freq(file):
- start_time = 0
- end_time = duration(file)
- sr, data = wavfile.read(file)
- if data.ndim > 1:
- data = data[:, 0]
- else:
- pass
- dataToRead = data[int(start_time * sr / 1000) : int(end_time * sr / 1000) + 1]
- N = len(dataToRead)
- yf = rfft(dataToRead)
- xf = rfftfreq(N, 1 / sr)
- idx = np.argmax(np.abs(yf))
- freq = xf[idx]
- return freq
- amplitudes = list()
- for audio in list(f for f in listdir(path) if isfile(join(path, f))):
- try:
- amplitudes.append(amplitude(audio))
- print(colored((audio + " - " + str(amplitude(audio)) + " dbFS, " + str(freq(audio)) + " Hz"), "green"))
- except:
- pass
- amplitudes.sort()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement