import React, { useState, useEffect } from 'react'; import { Play, Pause, Volume2, Loader2 } from 'lucide-react'; interface FishAudioPlayerProps { modelId: string; className?: string; } export const FishAudioPlayer: React.FC = ({ modelId, className = "" }) => { const [audioUrl, setAudioUrl] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [isPlaying, setIsPlaying] = useState(false); const audioRef = React.useRef(null); useEffect(() => { const fetchModel = async () => { try { setLoading(true); const response = await fetch(`https://api.fish.audio/model/${modelId}`); if (!response.ok) throw new Error('Failed to fetch model info'); const data = await response.json(); if (data.samples && data.samples.length > 0 && data.samples[0].audio) { setAudioUrl(data.samples[0].audio); } else { setError('No audio sample found'); } } catch (err) { console.error('Error loading Fish Audio:', err); setError('Error loading preview'); } finally { setLoading(false); } }; if (modelId) { fetchModel(); } }, [modelId]); const togglePlay = () => { if (!audioRef.current) return; if (isPlaying) { audioRef.current.pause(); } else { audioRef.current.play(); } setIsPlaying(!isPlaying); }; if (loading) { return (
); } if (error || !audioUrl) { return null; // Don't show anything if there's an error } return (
Demo de Voz
{/* We could add a proper progress bar here if we wanted to be more fancy */}
); };