我正在与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
也许我做得不对,或者是我的方法不好。谢谢你的关注,如果我在英语上犯了错误,我很抱歉!
从混合物中分离出不同的声源称为声源分离。如果您没有关于源的详细信息,则称为盲源分离。总的来说,这是一个具有挑战性的问题,并得到了广泛的研究。您可以尝试的一个简单方法是FastICA:https://scikit-learn.org/stable/auto_examples/decomposition/plot_ica_blind_source_separation.html
音乐可能特别具有挑战性,因为这样的过程往往会产生小的人工制品。您可能需要稍后编辑这些内容。