Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.54k stars 988 forks source link

Pitch change does not affect to the html5 video audio. #1264

Open rrehltp opened 4 months ago

rrehltp commented 4 months ago

Hi there.

I am building a browser extension that plays video in Chrome and Safari. I want to change the pitch of the Video audio in the HTML5 video tag.

Here is some codebase that I implemented.

    // Play the video content to start the audio context.
    this.player.play();

    // Initialize the pitch shift effect and set its window size.
    pitchShift = new Tone.PitchShift().toDestination();
    pitchShift.windowSize = 0.01;

    // Create a media source from the video container and connect it to the pitch shift effect.
    const mediaSource = Tone.context.createMediaElementSource(this.player.container);
    Tone.connect(mediaSource, pitchShift);

   pitchSlider.addEventListener('change', (e) => { 
      pitchShift.pitch = parseFloat(e.target.value);
    });

Fortunately, it works well in Chrome but not in Safari.

Is it possible to change the pitch level in Safari for HTML5 video audio?

Expected behavior

I want to change the video audio pitch using a slider bar.

What I've tried I noticed that Tone.context.state was "suspended", so I implemented the resume() mechanism with video playing. I also activated the auto-play video in Safari and found that Tone.context.state was changed to "running". However, the pitch doesn't change in Safari.

Hoping to hear from you soon. All the best.

yasz commented 1 month ago

+1 hope for ur reply!