2024-03-25 18:14:12 +08:00
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
|
import VolumeUpIcon from "@mui/icons-material/VolumeUp";
|
|
|
|
|
import { useTextAudio } from "../../hooks/Audio";
|
|
|
|
|
|
|
|
|
|
export default function AudioBtn({ text, lan = "uk" }) {
|
2024-03-25 21:00:39 +08:00
|
|
|
const { error, ready, playing, onPlay } = useTextAudio(text, lan);
|
2024-03-25 18:14:12 +08:00
|
|
|
|
2024-03-25 21:00:39 +08:00
|
|
|
if (error || !ready) {
|
2024-03-25 18:14:12 +08:00
|
|
|
return (
|
2024-04-15 18:04:35 +08:00
|
|
|
<IconButton disabled size="small">
|
2024-04-16 11:25:04 +08:00
|
|
|
<VolumeUpIcon fontSize="inherit" />
|
2024-03-25 18:14:12 +08:00
|
|
|
</IconButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playing) {
|
|
|
|
|
return (
|
2024-04-15 18:04:35 +08:00
|
|
|
<IconButton color="primary" size="small">
|
2024-04-16 11:25:04 +08:00
|
|
|
<VolumeUpIcon fontSize="inherit" />
|
2024-03-25 18:14:12 +08:00
|
|
|
</IconButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2024-04-15 18:04:35 +08:00
|
|
|
<IconButton onClick={onPlay} size="small">
|
2024-04-16 11:25:04 +08:00
|
|
|
<VolumeUpIcon fontSize="inherit" />
|
2024-03-25 18:14:12 +08:00
|
|
|
</IconButton>
|
|
|
|
|
);
|
|
|
|
|
}
|