0

我目前正在使用music21midi2audio生成.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()我可以看到只有.wav2 个F注释的文件比.wav只有一个F注释的文件长约 50%。此外,这些比率与使用的音符无关,除非r使用。为什么这是真的?

4

1 回答 1

0

2-note 文件的长度是 1-note 文件长度的 150%(而不是 200%)可能是music21默认情况下添加的单个尾随休止符的结果。有一个提议的增强功能来提供一个关键字来绕过这样做。引用该问题:

默认情况下,结束延迟是打开的,因为许多 MIDI 播放器会呈现尖锐的弹出结束以切断仍在播放波形中的声音。

于 2022-03-05T03:55:05.790 回答