HTMLMediaElement.preservesPitch

Baseline 2023

Newly available

Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

HTMLMediaElement.preservesPitch プロパティは、 HTMLMediaElement.playbackRate の設定で行われた再生速度の変更を補償するために、ブラウザーが音声の音程を調整すべきかどうかを決定します。

論理値で、既定値は true です。

preservesPitch プロパティの設定

この例には、 <audio> 要素、再生速度を制御する範囲コントロール、preservesPitchを設定するチェックボックスがあります。

音声を再生し、再生速度を調整し、チェックボックスを有効・無効にしてみてください。

html
<audio
  controls
  src="https://mdn.github.io/webaudio-examples/audio-basics/outfoxing.mp3"></audio>

<div>
  <label for="rate">Adjust playback rate:</label>
  <input id="rate" type="range" min="0.25" max="3" step="0.05" value="1" />
</div>

<div>
  <label for="pitch">Preserve pitch:</label>
  <input type="checkbox" id="pitch" name="pitch" checked />
</div>
js
const audio = document.querySelector("audio");

const rate = document.querySelector("#rate");
rate.addEventListener("input", () => (audio.playbackRate = rate.value));

const pitch = document.querySelector("#pitch");
pitch.addEventListener("change", () => {
  if ("preservesPitch" in audio) {
    audio.preservesPitch = pitch.checked;
  } else if ("mozPreservesPitch" in audio) {
    //deprecated
    audio.mozPreservesPitch = pitch.checked;
  }
});

仕様書

Specification
HTML Standard
# dom-media-preservespitch-dev

ブラウザーの互換性

BCD tables only load in the browser

関連情報