import { useState, useRef } from 'react'; import { Volume2, Play, Download } from 'lucide-react'; export default function PocketTTS() { const [text, setText] = useState('Hello, this is a test of PocketTTS integration.'); const [audioUrl, setAudioUrl] = useState(''); const [loading, setLoading] = useState(false); const audioRef = useRef(null); const handleSynthesize = async () => { if (!text.trim()) return; setLoading(true); setAudioUrl(''); try { const response = await fetch('/api/tts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text }), }); if (!response.ok) throw new Error('TTS Generation failed'); const blob = await response.blob(); const url = URL.createObjectURL(blob); setAudioUrl(url); } catch (err) { console.error(err); alert('Failed to generate audio'); } finally { setLoading(false); } }; const playAudio = () => { if (audioRef.current) { audioRef.current.play(); } }; return (
); }