rolexx commited on
Commit
5a1477e
·
1 Parent(s): 321ba52
src/app/api/voice/route.ts CHANGED
@@ -47,11 +47,19 @@ const VOICES = {
47
 
48
  export async function POST(request: Request) {
49
  try {
50
- const { text, language = 'en' } = await request.json();
51
  console.log('language:', language);
52
  console.log('text:', text);
 
53
 
54
- const voice = VOICES[language as keyof typeof VOICES].LAWYER_VOICE.id;
 
 
 
 
 
 
 
55
  console.log('voice:', voice);
56
 
57
  const response = await fetch(
 
47
 
48
  export async function POST(request: Request) {
49
  try {
50
+ const { text, language = 'en', role } = await request.json();
51
  console.log('language:', language);
52
  console.log('text:', text);
53
+ console.log('role:', role)
54
 
55
+ let voice;
56
+ if (role === 'lawyer') {
57
+ voice = VOICES[language as keyof typeof VOICES].LAWYER_VOICE.id;
58
+ } else if (role === 'judge') {
59
+ voice = VOICES[language as keyof typeof VOICES].JUDGE_VOICE.id;
60
+ } else if (role === 'glitch') {
61
+ voice = VOICES[language as keyof typeof VOICES].GLITCH_VOICE.id;
62
+ }
63
  console.log('voice:', voice);
64
 
65
  const response = await fetch(
src/components/court/Court.tsx CHANGED
@@ -17,6 +17,39 @@ const CourtScene: FC<CourtSceneProps> = ({
17
  }) => {
18
  const [showFirstImage, setShowFirstImage] = useState(true);
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  useEffect(() => {
21
  const timer = setTimeout(() => {
22
  setShowFirstImage(false);
 
17
  }) => {
18
  const [showFirstImage, setShowFirstImage] = useState(true);
19
 
20
+ useEffect(() => {
21
+ const playAudio = async () => {
22
+ try {
23
+ if (!currentQuestion) return;
24
+
25
+ const response = await fetch('/api/voice', {
26
+ method: 'POST',
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ },
30
+ body: JSON.stringify({
31
+ language: 'en', // You may want to make this configurable
32
+ text: reaction !== '' ? reaction + currentQuestion : currentQuestion,
33
+ role: 'judge'
34
+ })
35
+ });
36
+
37
+ if (!response.ok) {
38
+ throw new Error('Failed to generate audio');
39
+ }
40
+
41
+ const audioBlob = await response.blob();
42
+ const audioUrl = URL.createObjectURL(audioBlob);
43
+ const audio = new Audio(audioUrl);
44
+ audio.play();
45
+ } catch (error) {
46
+ console.error('Error playing audio:', error);
47
+ }
48
+ };
49
+
50
+ playAudio();
51
+ }, [currentQuestion]);
52
+
53
  useEffect(() => {
54
  const timer = setTimeout(() => {
55
  setShowFirstImage(false);
src/components/lawyer/Lawyer.tsx CHANGED
@@ -56,7 +56,8 @@ const LawyerScene: FC<LawyerSceneProps> = ({
56
  },
57
  body: JSON.stringify({
58
  language,
59
- text: answer
 
60
  })
61
  });
62
 
 
56
  },
57
  body: JSON.stringify({
58
  language,
59
+ text: answer,
60
+ role: 'lawyer'
61
  })
62
  });
63