【发布时间】:2020-04-23 16:08:54
【问题描述】:
我想同时完成两件事:
1) 将声音文件的播放速率更改为 1/2 速度
2) 将音高降低五分之一
最后,我不想使用单独的按钮来播放结果,而是将其连接到音频标签并在那里使用播放按钮。
以下是迄今为止我使用 Tone.js 得到的最接近的结果。我真的在为文档苦苦挣扎,但我知道 Tone.Transport.bpm.value = 60;将 bpm 从 120 更改为 60,Tone.PitchShift 将歌曲移调。我只是不明白如何将两者结合起来“叠加”效果。
以下是我关注的一些链接:
How to change the pitch with JavaScript?
https://tonejs.github.io/docs/r12/PitchShift
https://tonejs.github.io/docs/13.8.25/Transport
提前感谢您的帮助!
<audio id="myAudio" controls preload="none">
<source src="my_tune.m4a" type="audio/mp4" >
</audio>
<script src="https://unpkg.com/tone@next/build/Tone.js"></script>
<script>
Tone.Transport.bpm.value = 60; // setting the bpm like this is not working. where to put this?
var player = new Tone.Player("my_tune.m4a").sync().start(0);
// is it possible to use audio tag instead of creating this player?
var pitchShift = new Tone.PitchShift({
pitch: -5 // this is working and lowers pitch by a fifth
}).toMaster();
player.connect(pitchShift);
window.play = function() {
Tone.Transport.start();
}
<script>
<button onclick="setPlaySpeed()" type="button">separate button</button><br>
【问题讨论】:
-
我认为这里可能存在误解。 Transport 用于定时音乐事件。查看Player Example 以及它如何处理播放速度。播放速率会改变音高和速度,因此您需要通过音高偏移进行补偿。或者您可以考虑创建自己的phase vocoder using web audio
-
这有什么更新吗?我也有同样的问题。
-
@gskema: 更新 ;) 让我知道这是否有帮助。
标签: javascript performance audio pitch