Help with Pitch and Scrubbing Issues in WaveSurfer #4005
Replies: 2 comments
-
You could use WebAudio + a custom pitch shifting effect like in this example: https://wavesurfer.xyz/examples/?phase-vocoder/index.js (Source code: https://github.com/katspaugh/wavesurfer.js/tree/main/examples/phase-vocoder) |
Beta Was this translation helpful? Give feedback.
-
@katspaugh Thanks for answer. Now pitch preservation works correctly with plugin, but seeking through the waveform by clicking no longer works. I've tried both 'WebAudio' and 'MediaElement' backends, but neither preserves the seeking functionality. `export const AudioPlayer = ({ const [localDuration, setLocalDuration] = useState('00:00'); const { setCurrentAudio, currentAudioId, isPlaying, playbackSpeed } = useEffect(() => {
}, [fileUrl]); useEffect(() => {
}, [playbackSpeed, currentAudioId]); |
Beta Was this translation helpful? Give feedback.
-
Hello!
I am currently working with WaveSurfer.js to implement an audio player in my React application. I am facing an issue when trying to preserve the pitch of the audio while changing the playback speed and also enabling scrubbing/seek functionality.
Here is the problem I am encountering:
I need to find a way to preserve the normal pitch even when I change the playback speed and keep the scrubbing/seek functionality working as expected.
`import './AudioPlayer.scss';
import { useEffect, useRef, useState } from 'react';
import WaveSurfer from 'wavesurfer.js';
type AudioPlayerProps = {
fileUrl: string;
playIcon: JSX.Element;
pauseIcon: JSX.Element;
variant?: 'meeting' | 'input' | 'message';
audioId: string;
};
export const AudioPlayer = ({
fileUrl,
playIcon,
variant = 'message',
audioId,
pauseIcon,
}: AudioPlayerProps) => {
const containerRef = useRef(null);
const wavesurferRef = useRef<WaveSurfer | null>(null);
const [localDuration, setLocalDuration] = useState('00:00');
const [isWaveformReady, setIsWaveformReady] = useState(false);
const { setCurrentAudio, currentAudioId, isPlaying, playbackSpeed } = useAudioPlayerStore();
useEffect(() => {
if (!containerRef.current) return;
}, [fileUrl]);
useEffect(() => {
if (wavesurferRef.current && currentAudioId === audioId) {
wavesurferRef.current.setPlaybackRate(playbackSpeed);
}
}, [playbackSpeed]);
const handlePlayPause = () => {
if (!isWaveformReady || !wavesurferRef.current) return;
if (currentAudioId !== audioId) {
setCurrentAudio(audioId, variant, wavesurferRef.current);
} else {
useAudioPlayerStore.getState().togglePlayPause();
}
};
return (
{isPlaying && currentAudioId === audioId ? pauseIcon : playIcon}
{localDuration}
);
};
`
Beta Was this translation helpful? Give feedback.
All reactions