// /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$ /$$ /$$ /$$$$$$$$ /$$$$$$ /$$$$$ /$$$$$$ /$$$$$$$ // /$$__ $$|_ $$_/| $$ | $$| $$_____/ | $$$ /$$$| $$_____/ /$$__ $$ |__ $$ /$$__ $$| $$__ $$ // | $$ \__/ | $$ | $$ | $$| $$ | $$$$ /$$$$| $$ | $$ \ $$ | $$| $$ \ $$| $$ \ $$ // | $$ /$$$$ | $$ | $$ / $$/| $$$$$ | $$ $$/$$ $$| $$$$$ | $$$$$$$$ | $$| $$ | $$| $$$$$$$ // | $$|_ $$ | $$ \ $$ $$/ | $$__/ | $$ $$$| $$| $$__/ | $$__ $$ /$$ | $$| $$ | $$| $$__ $$ // | $$ \ $$ | $$ \ $$$/ | $$ | $$\ $ | $$| $$ | $$ | $$ | $$ | $$| $$ | $$| $$ \ $$ // | $$$$$$/ /$$$$$$ \ $/ | $$$$$$$$ | $$ \/ | $$| $$$$$$$$ | $$ | $$ | $$$$$$/| $$$$$$/| $$$$$$$/ // \______/ |______/ \_/ |________/ |__/ |__/|________/ |__/ |__/ \______/ \______/ |_______/ // // Hi, I'm Roland and i'm looking for a job. // Resume in /public/resume.pdf // roland.vrignon@roland.com // https://www.linkedin.com/in/roland-vrignon/ // 'use client'; import { FC, useEffect, useState, useRef } from 'react'; import Image from 'next/image'; interface Verdict { verdict: boolean; argument: string; prisonYears: number; } interface EndSceneProps { language: 'fr' | 'en' | 'es'; setNextScene: () => void; verdict: Verdict | null; } const EndScene: FC = ({ language, setNextScene, verdict }) => { const [isLoading, setIsLoading] = useState(true); const audioRef = useRef(null); useEffect(() => { if (verdict) { setIsLoading(false); const playVerdict = async () => { try { const response = await fetch('/api/voice', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ language, text: verdict.argument, role: 'judge' }) }); if (!response.ok) { throw new Error('Failed to generate audio'); } const audioBlob = await response.blob(); const audioUrl = URL.createObjectURL(audioBlob); if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } const audio = new Audio(audioUrl); audioRef.current = audio; await audio.play(); } catch (error) { console.error('Error playing verdict audio:', error); } }; playVerdict(); } return () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [verdict]); const handleNextScene = () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } setNextScene(); }; const getLoadingText = () => { if (language === 'fr') { return 'Le juge délibère...'; } else if (language === 'en') { return 'The judge is deliberating...'; } else { return 'El juez está deliberando...'; } }; const getVerdictText = () => { if (language === 'fr') { return verdict?.verdict ? 'NON COUPABLE' : 'COUPABLE'; } else if (language === 'en') { return verdict?.verdict ? 'NOT GUILTY' : 'GUILTY'; } else { return verdict?.verdict ? 'NO CULPABLE' : 'CULPABLE'; } }; const getSentenceText = () => { if (language === 'fr') { return verdict?.prisonYears && verdict?.prisonYears > 0 ? `${verdict?.prisonYears} ans de prison` : 'Libéré'; } else if (language === 'en') { return verdict?.prisonYears && verdict?.prisonYears > 0 ? `${verdict?.prisonYears} years in prison` : 'Released'; } else { return verdict?.prisonYears && verdict?.prisonYears > 0 ? `${verdict?.prisonYears} años de prisión` : 'Liberado'; } }; return (
Background
{isLoading ? (

{getLoadingText()}

) : (

{language === 'fr' ? 'Verdict' : language === 'en' ? 'Verdict' : 'Veredicto' }

{getVerdictText()}

{getSentenceText()}

{verdict?.argument}

)}
); }; export default EndScene;