我目前正在使用music21
并midi2audio
生成.wav
文件以用于机器学习。我观察到一个非常奇怪的事实。
path = '/Users/CatLover/Documents/DataScience/Insight/MusicDetector/music/'
npath = '/Users/CatLover/Documents/DataScience/Insight/MusicDetector/noise/'
nmpath = '/Users/CatLover/Documents/DataScience/Insight/MusicDetector/noisy_music/'
tpath = '/Users/CatLover/Documents/DataScience/Insight/MusicDetector/test_music/'
tnmpath = '/Users/CatLover/Documents/DataScience/Insight/MusicDetector/test_noisy_music/'
def build_dataset(char_list):
dictionary = dict()
for char in char_list:
dictionary[char] = len(dictionary)
reverse_dictionary = dict(zip(dictionary.values(), dictionary.keys()))
return dictionary, reverse_dictionary
def repeating_music(char, length):
preamble = 'tinyNotation: 4/4'
for i in range(length):
preamble = preamble + ' ' + char + '4'
music = music21.converter.parse(preamble)
music.write('midi', fp = tpath + 'test1' + '.midi')
subprocess.call(["midi2audio", tpath + 'test1' + '.midi', tpath + 'test1' + '.wav'])
test_X = segmenting(tpath + 'test1' + '.wav')
test_y = np.full(length, dic[char])
return test_X, test_y
char_list = ["r","CCC","CCC#","DDD","DDD#","EEE","FFF","FFF#","GGG","GGG#","AAA","AAA#","BBB","CC","CC#","DD","DD#","EE","FF","FF#","GG","GG#","AA","AA#","BB","C","C#","D","D#","E","F","F#","G","G#","A","A#","B","c","c#","d","d#","e","f","f#","g","g#","a","a#","b","c'","c'#","d'","d'#","e'","f'","f'#","g'","g'#","a'","a'#","b'","c''","c''#","d''","d''#","e''","f''","f''#","g''","g''#","a''","a''#","b''"]
dic, rdic = build_dataset(char_list)
使用librosa.get_duration()
我可以看到只有.wav
2 个F
注释的文件比.wav
只有一个F
注释的文件长约 50%。此外,这些比率与使用的音符无关,除非r
使用。为什么这是真的?