新增全语言翻译器

This commit is contained in:
2025-10-06 18:50:00 +08:00
parent be78ca3976
commit 609ac69778
12 changed files with 340 additions and 95 deletions

View File

@@ -0,0 +1,40 @@
import { useRef, useEffect } from "react";
export function useAudioPlayer() {
const audioRef = useRef<HTMLAudioElement | null>(null);
useEffect(() => {
audioRef.current = new Audio();
return () => {
if (audioRef.current) {
audioRef.current.pause();
audioRef.current = null;
}
};
}, []);
const playAudio = (audioUrl: string) => {
if (audioRef.current) {
audioRef.current.src = audioUrl;
audioRef.current.play().catch(error => {
console.error('播放失败:', error);
});
}
};
const pauseAudio = () => {
if (audioRef.current) {
audioRef.current.pause();
}
};
const stopAudio = () => {
if (audioRef.current) {
audioRef.current.pause();
audioRef.current.currentTime = 0;
}
};
return {
playAudio,
pauseAudio,
stopAudio
};
}