File size: 1,260 Bytes
0a42605
 
e5949c2
0a42605
e5949c2
 
 
 
 
 
 
0a42605
 
 
e5949c2
0a42605
 
 
e5949c2
0a42605
 
e5949c2
0a42605
 
 
e5949c2
0a42605
 
 
 
 
 
e5949c2
0a42605
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1"><title>Droidchatts</title></head>
<body>
  <h1>Droid Chat + TTS</h1>
  <textarea id="chat" placeholder="Say something..."></textarea><br>
  <button onclick="sendChat()">Send Chat</button><br>
  <p id="reply"></p>
  <textarea id="speak" placeholder="Text to speak..."></textarea><br>
  <button onclick="sendTTS()">Speak</button><br>
  <audio id="audio" controls></audio>

  <script>
    async function sendChat() {
      const text = document.getElementById("chat").value;
      const res = await fetch("/chat", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ prompt: text })
      });
      const data = await res.json();
      document.getElementById("reply").innerText = data.response;
    }

    async function sendTTS() {
      const text = document.getElementById("speak").value;
      const res = await fetch("/tts", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ text })
      });
      const blob = await res.blob();
      document.getElementById("audio").src = URL.createObjectURL(blob);
    }
  </script>
</body>
</html>