首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将magenta.js音符序列转换为midi文件?

如何将magenta.js音符序列转换为midi文件?
EN

Stack Overflow用户
提问于 2020-10-03 07:59:14
回答 1查看 426关注 0票数 0

我正在尝试将Magenta.js中的音符序列转换为midi文件,并获取一个url,这样用户就可以下载它,并在我的midi播放器/可视化工具中使用该url。

代码语言:javascript
复制
// 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;

但是我得到了这个错误:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-06 00:12:05

我通过添加以下内容解决了这个问题:

代码语言:javascript
复制
magentaSequence.notes.forEach(n => n.velocity = bpm);

看起来笔记需要一个速度才能让这段代码工作。我在这个链接https://github.com/magenta/magenta-js/issues/462中找到了详细信息

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64179468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档