我正在尝试将Magenta.js中的音符序列转换为midi文件,并获取一个url,这样用户就可以下载它,并在我的midi播放器/可视化工具中使用该url。
// Create a magenta note sequence
generateMelody(sendedNotes, 0.7, document.getElementById('bpm').value).then((magentaSequence) => {
// Create midi out of magenteSequence
const magentaMidi = core.sequenceProtoToMidi(magentaSequence);
// Convert byte array to file
const magentaFile = new Blob([magentaMidi], { type: 'audio/midi' })
// Get url of the file
const magentaURL = URL.createObjectURL(magentaFile);
// Create midi elements and populate the template
const magentaContent = melodyTemplate({'id': 2, 'src': magentaURL});
// Add new item to results
document.querySelector('#results').innerHTML += magentaContent;但是我得到了这个错误:
Uncaught (in promise) Error: The sequence you are using with the visualizer does not have a totalTime field set, so the visualizer can't be horizontally sized correctly.发布于 2020-10-06 00:12:05
我通过添加以下内容解决了这个问题:
magentaSequence.notes.forEach(n => n.velocity = bpm);看起来笔记需要一个速度才能让这段代码工作。我在这个链接https://github.com/magenta/magenta-js/issues/462中找到了详细信息
https://stackoverflow.com/questions/64179468
复制相似问题