作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设您有一个名为 audio
的音频变量,它存储了一个声音。
我知道如何改变速度,例如:
audio.playBackRate = 2;
但我不知道如何改变音高。
是否有 audio.pitch
属性,还是我必须自己创建?
我想做这样的事情:
var audio = new Audio();
audio.src = "sound_effect.wav";
audio.pitch = 2 //doubling the pitch but there is no pitch attribute
audio.play();
最佳答案
我认为你需要使用图书馆来申请pitch shifting到您的音频信号。你可以使用 Tone.js PitchShift .参见 this JSFiddle GitHub 用户 Jexim 的工作示例。我从下面这个 fiddle 中复制粘贴了最重要的部分:
Javascript:
var player = new Tone.Player("http://example.com/my-audiofile.mp3").sync().start(0);
var pitchShift = new Tone.PitchShift({
pitch: -5
}).toMaster();
player.connect(pitchShift);
Tone.Buffer.on('load', () => {
alert('Ready for play');
});
window.play = function() {
Tone.Transport.start();
}
HTML:
<script src="https://unpkg.com/tone@next/build/Tone.js"></script>
<button onclick="play()">Play</button>
关于javascript - 如何用 JavaScript 改变音调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53876757/
我是一名优秀的程序员,十分优秀!