Spaces:
Sleeping
Sleeping
wip
Browse files- .env +1 -1
- src/app/api/voice/route.ts +6 -0
- src/components/lawyer/Lawyer.tsx +33 -0
.env
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
ELEVEN_LABS_API_KEY="
|
2 |
MISTRAL_API_KEY="lyDFvx5djb2d5JqhqrHh1sXr8dovlgnE"
|
|
|
1 |
+
ELEVEN_LABS_API_KEY="sk_97fa12a6d73a3b7145dbd5f41affb96f7fcf9452262cd0f1"
|
2 |
MISTRAL_API_KEY="lyDFvx5djb2d5JqhqrHh1sXr8dovlgnE"
|
src/app/api/voice/route.ts
CHANGED
@@ -37,6 +37,8 @@ const VOICES = {
|
|
37 |
export async function POST(request: Request) {
|
38 |
try {
|
39 |
const { text, language = 'en' } = await request.json();
|
|
|
|
|
40 |
|
41 |
if (!VOICES[language as keyof typeof VOICES]) {
|
42 |
return NextResponse.json(
|
@@ -92,6 +94,8 @@ export async function POST(request: Request) {
|
|
92 |
}
|
93 |
}
|
94 |
|
|
|
|
|
95 |
// Si aucun segment glitch n'a été trouvé, on génère la voix normale
|
96 |
const response = await fetch(
|
97 |
`https://api.elevenlabs.io/v1/text-to-speech/${VOICES[language as keyof typeof VOICES].LAWYER_VOICE.id}`,
|
@@ -113,6 +117,8 @@ export async function POST(request: Request) {
|
|
113 |
}
|
114 |
);
|
115 |
|
|
|
|
|
116 |
if (!response.ok) {
|
117 |
throw new Error('Failed to generate voice');
|
118 |
}
|
|
|
37 |
export async function POST(request: Request) {
|
38 |
try {
|
39 |
const { text, language = 'en' } = await request.json();
|
40 |
+
console.log('language:', language)
|
41 |
+
console.log('text:', text)
|
42 |
|
43 |
if (!VOICES[language as keyof typeof VOICES]) {
|
44 |
return NextResponse.json(
|
|
|
94 |
}
|
95 |
}
|
96 |
|
97 |
+
console.log('process.env.ELEVEN_LABS_API_KEY:', process.env.ELEVEN_LABS_API_KEY)
|
98 |
+
|
99 |
// Si aucun segment glitch n'a été trouvé, on génère la voix normale
|
100 |
const response = await fetch(
|
101 |
`https://api.elevenlabs.io/v1/text-to-speech/${VOICES[language as keyof typeof VOICES].LAWYER_VOICE.id}`,
|
|
|
117 |
}
|
118 |
);
|
119 |
|
120 |
+
console.log('response:', response);
|
121 |
+
|
122 |
if (!response.ok) {
|
123 |
throw new Error('Failed to generate voice');
|
124 |
}
|
src/components/lawyer/Lawyer.tsx
CHANGED
@@ -43,6 +43,39 @@ const LawyerScene: FC<LawyerSceneProps> = ({
|
|
43 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44 |
}, []); // Only run once on mount
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
useEffect(() => {
|
47 |
setVisible(true);
|
48 |
setRound(round + 1);
|
|
|
43 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44 |
}, []); // Only run once on mount
|
45 |
|
46 |
+
useEffect(() => {
|
47 |
+
const playAudio = async () => {
|
48 |
+
try {
|
49 |
+
const response = await fetch('/api/voice', {
|
50 |
+
method: 'POST',
|
51 |
+
headers: {
|
52 |
+
'Content-Type': 'application/json',
|
53 |
+
},
|
54 |
+
body: JSON.stringify({
|
55 |
+
language,
|
56 |
+
text: answer
|
57 |
+
})
|
58 |
+
});
|
59 |
+
|
60 |
+
if (!response.ok) {
|
61 |
+
throw new Error('Failed to generate audio');
|
62 |
+
}
|
63 |
+
|
64 |
+
const audioBlob = await response.blob();
|
65 |
+
const audioUrl = URL.createObjectURL(audioBlob);
|
66 |
+
const audio = new Audio(audioUrl);
|
67 |
+
audio.play();
|
68 |
+
} catch (error) {
|
69 |
+
console.error('Error playing audio:', error);
|
70 |
+
}
|
71 |
+
};
|
72 |
+
|
73 |
+
if (answer) {
|
74 |
+
playAudio();
|
75 |
+
}
|
76 |
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
77 |
+
}, [answer])
|
78 |
+
|
79 |
useEffect(() => {
|
80 |
setVisible(true);
|
81 |
setRound(round + 1);
|