yasserrmd commited on
Commit
47c8182
·
verified ·
1 Parent(s): 3b4968e

Create static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +55 -0
static/index.html ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Voice Chat Interface</title>
7
+ </head>
8
+ <body>
9
+ <h1>Voice Chat</h1>
10
+ <button id="recordButton">Start Listening</button>
11
+ <button id="generateButton">Generate Speech</button>
12
+ <audio id="audioPlayer" controls></audio>
13
+
14
+ <script>
15
+ let mediaRecorder;
16
+ let audioChunks = [];
17
+
18
+ document.getElementById("recordButton").addEventListener("click", async () => {
19
+ if (!mediaRecorder || mediaRecorder.state === "inactive") {
20
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
21
+ mediaRecorder = new MediaRecorder(stream);
22
+ mediaRecorder.ondataavailable = event => audioChunks.push(event.data);
23
+ mediaRecorder.onstop = async () => {
24
+ const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
25
+ const formData = new FormData();
26
+ formData.append("file", audioBlob, "recording.wav");
27
+
28
+ const response = await fetch("/chat/", {
29
+ method: "POST",
30
+ body: formData
31
+ });
32
+ const audioData = await response.blob();
33
+ document.getElementById("audioPlayer").src = URL.createObjectURL(audioData);
34
+ };
35
+ audioChunks = [];
36
+ mediaRecorder.start();
37
+ setTimeout(() => mediaRecorder.stop(), 5000);
38
+ }
39
+ });
40
+
41
+ document.getElementById("generateButton").addEventListener("click", async () => {
42
+ const text = prompt("Enter text to convert to speech:");
43
+ if (text) {
44
+ const response = await fetch("/tts/", {
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json" },
47
+ body: JSON.stringify({ text })
48
+ });
49
+ const audioData = await response.blob();
50
+ document.getElementById("audioPlayer").src = URL.createObjectURL(audioData);
51
+ }
52
+ });
53
+ </script>
54
+ </body>
55
+ </html>