Abdalkaderdev commited on
Commit
e6f387f
Β·
1 Parent(s): 42545fb

Add emotion display and fix Whisper integration

Browse files
Files changed (1) hide show
  1. frontend/app/voice/page.tsx +16 -4
frontend/app/voice/page.tsx CHANGED
@@ -88,9 +88,11 @@ export default function OraVoice() {
88
 
89
  const data = await res.json();
90
  const reply = data.response;
 
91
 
92
  setResponse(reply);
93
- setHistory(prev => [...prev, { role: "user", content: text }, { role: "assistant", content: reply }]);
 
94
 
95
  speak(reply);
96
  } catch (e) {
@@ -147,9 +149,11 @@ export default function OraVoice() {
147
 
148
  const toggleListen = () => {
149
  if (state === "IDLE") {
150
- recognitionRef.current?.start();
 
 
151
  } else if (state === "SPEAKING") {
152
- // Audio will stop naturally or can be stopped via audio element
153
  setState("IDLE");
154
  }
155
  };
@@ -186,12 +190,20 @@ export default function OraVoice() {
186
  <div className="h-32 w-full max-w-2xl text-center px-4 space-y-4">
187
  <p className="text-gray-400 font-light tracking-widest text-sm uppercase">{state}</p>
188
 
 
 
 
 
 
 
 
 
189
  {state === "LISTENING" && (
190
  <p className="text-2xl text-white font-serif italic">"I'm listening..."</p>
191
  )}
192
 
193
  {state === "THINKING" && (
194
- <p className="text-2xl text-purple-300 font-serif italic animate-pulse">Divining wisdom...</p>
195
  )}
196
 
197
  {(state === "SPEAKING" || state === "IDLE") && response && (
 
88
 
89
  const data = await res.json();
90
  const reply = data.response;
91
+ const detectedEmotion = data.emotion;
92
 
93
  setResponse(reply);
94
+ setEmotion(detectedEmotion);
95
+ setHistory((prev: any) => [...prev, { role: "user", content: text }, { role: "assistant", content: reply }]);
96
 
97
  speak(reply);
98
  } catch (e) {
 
149
 
150
  const toggleListen = () => {
151
  if (state === "IDLE") {
152
+ startWhisperRecording();
153
+ } else if (state === "LISTENING") {
154
+ stopWhisperRecording();
155
  } else if (state === "SPEAKING") {
156
+ // Audio will stop naturally
157
  setState("IDLE");
158
  }
159
  };
 
190
  <div className="h-32 w-full max-w-2xl text-center px-4 space-y-4">
191
  <p className="text-gray-400 font-light tracking-widest text-sm uppercase">{state}</p>
192
 
193
+ {/* Emotion Badge */}
194
+ {emotion && state !== "LISTENING" && (
195
+ <div className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-blue-500/20 border border-blue-400/30">
196
+ <span className="text-xl">{emotion === "joy" ? "😊" : emotion === "sadness" ? "πŸ˜”" : emotion === "anger" ? "😠" : emotion === "fear" ? "😰" : "πŸ’­"}</span>
197
+ <span className="text-blue-200 text-sm capitalize">{emotion}</span>
198
+ </div>
199
+ )}
200
+
201
  {state === "LISTENING" && (
202
  <p className="text-2xl text-white font-serif italic">"I'm listening..."</p>
203
  )}
204
 
205
  {state === "THINKING" && (
206
+ <p className="text-2xl text-purple-300 font-serif italic animate-pulse">Seeking wisdom...</p>
207
  )}
208
 
209
  {(state === "SPEAKING" || state === "IDLE") && response && (