Skip to content

TruthGuard Family MVP #63

@180711

Description

@180711

import React, { useEffect, useRef, useState } from "react";

export default function TruthGuardFamily() { const [participants, setParticipants] = useState([]); const [name, setName] = useState(""); const [listening, setListening] = useState(false); const [transcript, setTranscript] = useState([]); const recognitionRef = useRef(null);

useEffect(() => { const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; if (!SpeechRecognition) return;

const recognition = new SpeechRecognition();
recognition.lang = "pt-BR";
recognition.continuous = true;
recognition.interimResults = true;

recognition.onresult = (event) => {
const last = event.results[event.results.length - 1][0].transcript;
const speaker = participants[0] || "Pessoa";
setTranscript((prev) => [...prev, { speaker, text: last }]);

// Simulação simples de inconsistência
if (last.toLowerCase().includes("nunca")) {
speak(${speaker}, atenção: há possível inconsistência no que você está dizendo.);
}
};

recognition.onend = () => {
if (listening) recognition.start();
};

recognitionRef.current = recognition;

}, [participants, listening]);

const speak = (text) => { const utter = new SpeechSynthesisUtterance(text); utter.lang = "pt-BR"; window.speechSynthesis.speak(utter); };

const addParticipant = () => { if (!name.trim()) return; setParticipants([...participants, name]); setName(""); };

const startSession = () => { if (recognitionRef.current) { setListening(true); recognitionRef.current.start(); speak("Sessão iniciada."); } };

const stopSession = () => { setListening(false); recognitionRef.current?.stop(); speak("Sessão encerrada."); };

return (

TruthGuard Family MVP

Versão funcional inicial com microfone e resposta por voz.

Participantes

setName(e.target.value)} className="flex-1 border rounded-lg p-3" placeholder="Nome" /> Adicionar
{participants.join(", ") || "Nenhum participante"}
<div className="bg-white rounded-2xl shadow p-6 flex gap-3">
  <button onClick={startSession} className="flex-1 bg-green-600 text-white rounded-lg p-3">START</button>
  <button onClick={stopSession} className="flex-1 bg-red-600 text-white rounded-lg p-3">STOP</button>
</div>

<div className="bg-white rounded-2xl shadow p-6">
  <h2 className="text-xl font-semibold mb-4">Transcrição</h2>
  <div className="bg-slate-50 rounded-xl p-4 h-72 overflow-auto">
    {transcript.map((t, i) => (
      <p key={i}><b>{t.speaker}:</b> {t.text}</p>
    ))}
    {!transcript.length && <p className="text-slate-400">Aguardando áudio...</p>}
  </div>
</div>

); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions