import { useState } from "react"; import html2canvas from "html2canvas"; const voiceIdMap = { Rachel: "21m00Tcm4TlvDq8ikWAM", Adam: "pNInz6obpgDQGcFmaJgB", Bella: "EXAVITQu4vr4xnSDxMaL" }; const apiKey = "sk_4e67c39c0e9cbc87462cd2643e1f4d1d9959d7d81203adc2"; export default function App() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(""); const [style, setStyle] = useState("whatsapp"); const [voice, setVoice] = useState("Rachel"); const generateVoice = async (text) => { const voiceId = voiceIdMap[voice]; const response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`, { method: "POST", headers: { "Content-Type": "application/json", "xi-api-key": apiKey }, body: JSON.stringify({ text, model_id: "eleven_monolingual_v1", voice_settings: { stability: 0.5, similarity_boost: 0.75 } }) }); const blob = await response.blob(); const audioUrl = URL.createObjectURL(blob); const audio = new Audio(audioUrl); audio.play(); }; const addMessage = (sender) => { if (!input.trim()) return; const newMsg = { sender, text: input.trim() }; setMessages([...messages, newMsg]); setInput(""); generateVoice(newMsg.text); }; const updateMessage = (index, newText) => { const newMsgs = [...messages]; newMsgs[index].text = newText; setMessages(newMsgs); }; const exportChatAsImage = () => { const chat = document.getElementById("chat-container"); html2canvas(chat).then((canvas) => { const link = document.createElement("a"); link.download = "chat_export.png"; link.href = canvas.toDataURL(); link.click(); }); }; return (