【发布时间】:2019-12-07 11:07:48
【问题描述】:
我关注了this example of Music Synchronization with Dynamic Time Warping
但是,当我这样做时:
import matplolib.pyplot as plt
import librosa
import librosa.display
x_1, fs = librosa.load('musicdata/slow_melody.wav')
plt.figure(figsize=(16, 4))
librosa.display.waveplot(x_1, sr=fs)
plt.title('Slower Version $X_1$')
plt.tight_layout()
对于更快的版本也是如此,我得到了这个结果:
我可以在色度表示中正确地达到 wav 文件的音高等级,并且 wav 文件中没有问题。
我创建了这样的 wav 文件的快速和慢速版本:
# Tone-duration sequence
melody = [('E', 0.3), ('E', 0.3), ('F', 0.3), ('G', 0.3)]
slow_melody = [('E', 0.6), ('E', 0.6), ('F', 0.6), ('G', 0.6)]
melody_output = np.array([])
# Construct the audio signal based on the chord sequence
for item in melody:
input_tone = item[0]
duration = item[1]
synthesized_tone = synthesizer(tone_freq_map[input_tone], duration, amplitude, sampling_freq)
melody_output = np.append(melody_output, synthesized_tone, axis=0)
# Write to the output file
name = 'melody' + '.wav'
write(name, sampling_freq, melody_output)
slow_melody_output = np.array([])
# Construct the audio signal based on the chord sequence
for item in slow_melody:
input_tone = item[0]
duration = item[1]
synthesized_tone = synthesizer(tone_freq_map[input_tone], duration, amplitude, sampling_freq)
slow_melody_output = np.append(slow_melody_output, synthesized_tone, axis=0)
# Write to the output file
name = 'slow_melody' + '.wav'
write(name, sampling_freq, slow_melody_output)
我从以下位置获取音调频率:
{ “一”:440, “锐利”:466, “B”:494, “C”:523, “Csharp”:554, “D”:587, “锐利”:622, “E”:659, “F”:698, “锐化”:740, “G”:784, “Gsharp”:831 }
合成器是:
def synthesizer(freq, duration, amp=1.0, sampling_freq=44100):
# Build the time axis
t = np.linspace(0, duration, duration * sampling_freq)
# Construct the audio signal
audio = amp * np.sin(2 * np.pi * freq * t)
return audio.astype(np.int16)
另外,输入参数是:
duration = 2
amplitude = 10000
sampling_freq = 44100
那么,为什么我不能正确地可视化波形图?它们看起来像这样的原因可能是什么?
【问题讨论】:
-
既然你用的是matplotlib,你能不能试试
plt.plot(x_1); plot.show()看看会发生什么?