Я пытаюсь с Numpy и Librosa вырезать некоторые определенные частоты из песни, используя сэмпл, сделанный из окна этой песни.
Пояснения : у меня есть песня 4:30 минуты,Я выбираю сэмпл в 2,667 секунды в этой песне и хочу удалить частоты, которые появляются в этом сэмпле.
После импорта моей песни я сталкиваюсь с проблемой удаления особых частот в моей песне: длина моего сэмпла меньше, чем длина всей моей песни, поэтому я не могу вычесть частоты моего сэмпла из моегопесня (которая, я думаю, может быть хорошим методом для удаления частот).
У вас есть идея, как мне поступить?Вот мой код:
import numpy as np
import librosa.display
# song importation
y, sr = librosa.load("my_song.wav") # y: audio time series, sr: sampling rate
# creation of a sample
song_duration = librosa.get_duration(y=y, sr=sr) # duration of song in seconds
sample_start = 0.384 # start of the sample (in seconds) here: 0.384
sample_end = 3.051 # end of the sample (in seconds) here: 3.051
sample_duration = sample_end - sample_start # sample duration in seconds
position_start = int((sample_start*len(y))/song_duration) # the starting position of the sample
position_end = position_start + int((sample_duration*len(y))/song_duration) # the end of the sample
sample = y[position_start:position_end] # the sample (fraction of y)
scaled = np.int16(sample/np.max(np.abs(sample)) * sr) # need to scale to have integer and not float
fft_y = np.fft.fft(y) # 1D discrete Fourier Transform of entire song
fft_sample = np.fft.fft(sample) # 1D discrete Fourier Transform of the sample
n_y = y.size
n_sample = sample.size
time_step = 1/sr
freq_y = np.fft.fftfreq(n_y, time_step) # Discrete Fourier Transform frequencies of entire song
freq_sample = np.fft.fftfreq(n_sample, time_step) # Discrete Fourier Transform frequencies of sample
print("y length: {0}, fft_y length: {1}, fft_sample length {2}".format(len(y), len(fft_y), len(fft_sample)))
# returns: y length: 6431544, fft_y length: 6431544, fft_sample length 58807
print("freq_y length: {0}, freq_sample length: {1}".format(len(freq_y), len(freq_sample)))
# returns: freq_y length: 6431544, freq_sample length: 58807
Возможно, я что-то не так сделал правильно, или это мой подход, который не очень хорош.Спасибо за внимание и извиняюсь за ошибки на английском!