YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: expandable speaker rows with voice samples + similar speaker matching
Louis Beaumont187b40321d4e
diff --git a/apps/screenpipe-app-tauri/components/settings/speakers-section.tsx b/apps/screenpipe-app-tauri/components/settings/speakers-section.tsxindex d68ceedb9..15dfc01c1 100644--- a/apps/screenpipe-app-tauri/components/settings/speakers-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/speakers-section.tsx@@ -6,7 +6,6 @@import React, { useState, useEffect, useCallback } from "react";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";-import { Badge } from "@/components/ui/badge";import { Skeleton } from "@/components/ui/skeleton";import { useToast } from "@/components/ui/use-toast";import {@@ -15,24 +14,272 @@ import {Check,X,Loader2,- GitMerge,Search,- Play,- Volume2,+ ChevronDown,+ ChevronRight,UserCheck,UserX,+ ThumbsUp,+ ThumbsDown,+ GitMerge,} from "lucide-react";+interface AudioSample {+ path: string;+ transcript: string;+ start_time: number;+ end_time: number;+}+interface Speaker {id: number;name: string;metadata: string;}-interface SpeakerWithDetails extends Speaker {- segment_count?: number;- last_seen?: string;- audio_sample_path?: string;+interface SimilarSpeaker {+ id: number;+ name: string;+ metadata: string;+}++function parseSamples(metadata: string): AudioSample[] {+ try {+ const parsed = JSON.parse(metadata);+ return parsed?.audio_samples || [];+ } catch {+ return [];+ }+}++function SpeakerDetail({+ speaker,+ onMerge,+ onRefresh,+}: {+ speaker: Speaker;+ onMerge: (keepId: number, mergeId: number) => Promise<void>;+ onRefresh: () => void;+}) {+ const [similar, setSimilar] = useState<SimilarSpeaker[]>([]);+ const [loadingSimilar, setLoadingSimilar] = useState(true);+ const { toast } = useToast();++ const samples = parseSamples(speaker.metadata);++ useEffect(() => {+ setLoadingSimilar(true);+ fetch(`http://localhost:3030/speakers/similar?speaker_id=${speaker.id}&limit=5`)+ .then((r) => r.json())+ .then((data) => setSimilar(Array.isArray(data) ? data : []))+ .catch(() => setSimilar([]))+ .finally(() => setLoadingSimilar(false));+ }, [speaker.id]);++ const reassign = async (audioPath: string, newSpeakerName: string) => {+ // Find the audio chunk and reassign — for now just show what would happen+ toast({ title: `would reassign to "${newSpeakerName}"` });+ };++ return (+ <div className="px-3 py-3 space-y-4 border-t border-border/50 bg-muted/20">+ {/* Audio samples */}+ <div className="space-y-1.5">+ <h4 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">+ voice samples ({samples.length})+ </h4>+ {samples.length === 0 && (+ <p className="text-xs text-muted-foreground">no audio samples stored</p>+ )}+ {samples.map((s, i) => (+ <div+ key={i}+ className="flex items-center gap-2 text-xs bg-background rounded px-2 py-1.5 border border-border/30"+ >+ <span className="text-muted-foreground font-mono shrink-0">+ {s.start_time.toFixed(1)}s+ </span>+ <span className="flex-1 truncate">“{s.transcript}”</span>+ <span className="text-muted-foreground shrink-0">+ {(s.end_time - s.start_time).toFixed(1)}s+ </span>+ </div>+ ))}+ </div>++ {/* Similar speakers — "is this the same person?" */}+ <div className="space-y-1.5">+ <h4 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">+ sounds similar — same person?+ </h4>+ {loadingSimilar && (+ <div className="space-y-1">+ <Skeleton className="h-8 w-full" />+ <Skeleton className="h-8 w-full" />+ </div>+ )}+ {!loadingSimilar && similar.length === 0 && (+ <p className="text-xs text-muted-foreground">no similar speakers found</p>+ )}+ {similar.map((s) => {+ const simSamples = parseSamples(s.metadata);+ const preview = simSamples[0]?.transcript || "(no sample)";+ return (+ <div+ key={s.id}+ className="flex items-center gap-2 text-xs bg-background rounded px-2 py-1.5 border border-border/30"+ >+ <div className="h-6 w-6 rounded-full bg-muted flex items-center justify-center text-[10px] shrink-0">+ {s.name ? s.name.slice(0, 2).toUpperCase() : "?"}+ </div>+ <div className="flex-1 min-w-0">+ <span className="font-medium">{s.name || `Speaker #${s.id}`}</span>+ <span className="text-muted-foreground ml-1.5 truncate">+ “{preview.slice(0, 40)}”+ </span>+ </div>+ <Button+ variant="ghost"+ size="icon"+ className="h-6 w-6 text-green-600 hover:text-green-700 hover:bg-green-50"+ title={`yes, merge into ${speaker.name || "this speaker"}`}+ onClick={() => onMerge(speaker.id, s.id)}+ >+ <ThumbsUp className="h-3 w-3" />+ </Button>+ <Button+ variant="ghost"+ size="icon"+ className="h-6 w-6 text-red-500 hover:text-red-600 hover:bg-red-50"+ title="no, different person"+ >+ <ThumbsDown className="h-3 w-3" />+ </Button>+ </div>+ );+ })}+ </div>+ </div>+ );+}++function SpeakerRow({+ speaker,+ isNamed,+ expanded,+ onToggle,+ onEdit,+ onDelete,+ onHallucination,+ onMerge,+ onRefresh,+}: {+ speaker: Speaker;+ isNamed: boolean;+ expanded: boolean;+ onToggle: () => void;+ onEdit: (id: number, name: string) => Promise<void>;+ onDelete: (id: number) => Promise<void>;+ onHallucination: (id: number) => Promise<void>;+ onMerge: (keepId: number, mergeId: number) => Promise<void>;+ onRefresh: () => void;+}) {+ const [editing, setEditing] = useState(false);+ const [editName, setEditName] = useState(speaker.name);+ const [saving, setSaving] = useState(false);+ const [deleting, setDeleting] = useState(false);++ const samples = parseSamples(speaker.metadata);++ const save = async () => {+ if (!editName.trim()) return;+ setSaving(true);+ await onEdit(speaker.id, editName.trim());+ setSaving(false);+ setEditing(false);+ };++ return (+ <div className="border border-border rounded-md overflow-hidden">+ <div+ className="flex items-center gap-3 px-3 py-2 cursor-pointer hover:bg-muted/30 transition-colors group"+ onClick={() => !editing && onToggle()}+ >+ <button className="shrink-0" onClick={(e) => { e.stopPropagation(); onToggle(); }}>+ {expanded ? <ChevronDown className="h-3.5 w-3.5" /> : <ChevronRight className="h-3.5 w-3.5" />}+ </button>+ <div className="h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-mono shrink-0">+ {isNamed ? speaker.name.slice(0, 2).toUpperCase() : "?"}+ </div>+ {editing ? (+ <div className="flex items-center gap-1.5 flex-1" onClick={(e) => e.stopPropagation()}>+ <Input+ value={editName}+ onChange={(e) => setEditName(e.target.value)}+ placeholder="enter name..."+ className="h-7 text-sm"+ autoFocus+ onKeyDown={(e) => {+ if (e.key === "Enter") save();+ if (e.key === "Escape") setEditing(false);+ }}+ />+ <Button variant="ghost" size="icon" className="h-7 w-7" disabled={saving} onClick={save}>+ {saving ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Check className="h-3.5 w-3.5" />}+ </Button>+ <Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => setEditing(false)}>+ <X className="h-3.5 w-3.5" />+ </Button>+ </div>+ ) : (+ <>+ <div className="flex-1 min-w-0">+ <span className="text-sm">{isNamed ? speaker.name : `Speaker #${speaker.id}`}</span>+ {samples.length > 0 && (+ <span className="text-xs text-muted-foreground ml-2">+ {samples.length} sample{samples.length !== 1 ? "s" : ""}+ </span>+ )}+ </div>+ <span className="text-xs text-muted-foreground">#{speaker.id}</span>+ <div className="flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity" onClick={(e) => e.stopPropagation()}>+ <Button+ variant="ghost"+ size="icon"+ className="h-7 w-7"+ title={isNamed ? "rename" : "assign name"}+ onClick={() => { setEditing(true); setEditName(speaker.name || ""); }}+ >+ {isNamed ? <Pencil className="h-3 w-3" /> : <UserCheck className="h-3 w-3" />}+ </Button>+ {!isNamed && (+ <Button+ variant="ghost"+ size="icon"+ className="h-7 w-7"+ title="false detection"+ onClick={() => onHallucination(speaker.id)}+ >+ <UserX className="h-3 w-3" />+ </Button>+ )}+ <Button+ variant="ghost"+ size="icon"+ className="h-7 w-7 text-destructive"+ title="delete"+ disabled={deleting}+ onClick={async () => { setDeleting(true); await onDelete(speaker.id); setDeleting(false); }}+ >+ {deleting ? <Loader2 className="h-3 w-3 animate-spin" /> : <Trash2 className="h-3 w-3" />}+ </Button>+ </div>+ </>+ )}+ </div>+ {expanded && <SpeakerDetail speaker={speaker} onMerge={onMerge} onRefresh={onRefresh} />}+ </div>+ );}export function SpeakersSection() {@@ -40,10 +287,7 @@ export function SpeakersSection() {const [unnamed, setUnnamed] = useState<Speaker[]>([]);const [loading, setLoading] = useState(true);const [searchQuery, setSearchQuery] = useState("");- const [editingId, setEditingId] = useState<number | null>(null);- const [editName, setEditName] = useState("");- const [saving, setSaving] = useState<number | null>(null);- const [deleting, setDeleting] = useState<number | null>(null);+ const [expandedId, setExpandedId] = useState<number | null>(null);const { toast } = useToast();const fetchSpeakers = useCallback(async () => {@@ -52,103 +296,67 @@ export function SpeakersSection() {fetch("http://localhost:3030/speakers/search"),fetch("http://localhost:3030/speakers/unnamed?limit=50"),]);- if (namedRes.ok) {- const data = await namedRes.json();- setSpeakers(Array.isArray(data) ? data : []);- }- if (unnamedRes.ok) {- const data = await unnamedRes.json();- setUnnamed(Array.isArray(data) ? data : []);- }- } catch {- // server not running- } finally {- setLoading(false);- }+ if (namedRes.ok) setSpeakers(await namedRes.json().then((d: any) => (Array.isArray(d) ? d : [])));+ if (unnamedRes.ok) setUnnamed(await unnamedRes.json().then((d: any) => (Array.isArray(d) ? d : [])));+ } catch { /* server not running */ }+ finally { setLoading(false); }}, []);- useEffect(() => {- fetchSpeakers();- }, [fetchSpeakers]);+ useEffect(() => { fetchSpeakers(); }, [fetchSpeakers]);const updateSpeaker = async (id: number, name: string) => {- setSaving(id);- try {- const res = await fetch("http://localhost:3030/speakers/update", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ id, name }),- });- if (!res.ok) throw new Error("failed to update");- toast({ title: `speaker renamed to "${name}"` });- setEditingId(null);- fetchSpeakers();- } catch {- toast({ title: "failed to update speaker", variant: "destructive" });- } finally {- setSaving(null);- }+ const res = await fetch("http://localhost:3030/speakers/update", {+ method: "POST", headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ id, name }),+ });+ if (!res.ok) throw new Error("failed");+ toast({ title: `speaker renamed to "${name}"` });+ fetchSpeakers();};const deleteSpeaker = async (id: number) => {- setDeleting(id);- try {- const res = await fetch("http://localhost:3030/speakers/delete", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ speaker_id: id }),- });- if (!res.ok) throw new Error("failed to delete");- toast({ title: "speaker deleted" });- fetchSpeakers();- } catch {- toast({ title: "failed to delete speaker", variant: "destructive" });- } finally {- setDeleting(null);- }+ const res = await fetch("http://localhost:3030/speakers/delete", {+ method: "POST", headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ speaker_id: id }),+ });+ if (!res.ok) throw new Error("failed");+ toast({ title: "speaker deleted" });+ if (expandedId === id) setExpandedId(null);+ fetchSpeakers();};const markHallucination = async (id: number) => {- try {- const res = await fetch("http://localhost:3030/speakers/hallucination", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ speaker_id: id }),- });- if (!res.ok) throw new Error("failed");- toast({ title: "marked as false detection" });- fetchSpeakers();- } catch {- toast({ title: "failed to mark hallucination", variant: "destructive" });- }+ const res = await fetch("http://localhost:3030/speakers/hallucination", {+ method: "POST", headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ speaker_id: id }),+ });+ if (!res.ok) throw new Error("failed");+ toast({ title: "marked as false detection" });+ fetchSpeakers();};const mergeSpeakers = async (keepId: number, mergeId: number) => {- try {- const res = await fetch("http://localhost:3030/speakers/merge", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ speaker_id_to_keep: keepId, speaker_id_to_merge: mergeId }),- });- if (!res.ok) throw new Error("failed");- toast({ title: "speakers merged" });- fetchSpeakers();- } catch {- toast({ title: "failed to merge speakers", variant: "destructive" });- }+ const res = await fetch("http://localhost:3030/speakers/merge", {+ method: "POST", headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ speaker_id_to_keep: keepId, speaker_id_to_merge: mergeId }),+ });+ if (!res.ok) throw new Error("failed");+ toast({ title: "speakers merged" });+ fetchSpeakers();};- const filteredSpeakers = speakers.filter(- (s) => !searchQuery || s.name.toLowerCase().includes(searchQuery.toLowerCase())+ const allSpeakers = [+ ...speakers.map((s) => ({ ...s, isNamed: true })),+ ...unnamed.map((s) => ({ ...s, isNamed: false })),+ ].filter(+ (s) => !searchQuery || s.name.toLowerCase().includes(searchQuery.toLowerCase()) || `#${s.id}`.includes(searchQuery));if (loading) {return (<div className="space-y-4"><Skeleton className="h-8 w-full" />- {[1, 2, 3, 4].map((i) => (- <Skeleton key={i} className="h-16 w-full" />- ))}+ {[1, 2, 3, 4].map((i) => <Skeleton key={i} className="h-14 w-full" />)}</div>);}@@ -156,7 +364,7 @@ export function SpeakersSection() {return (<div className="space-y-5" data-testid="section-settings-speakers"><p className="text-muted-foreground text-sm">- manage detected speakers. rename unknowns, merge duplicates, and remove false detections.+ manage detected speakers. click to expand, confirm similar voices, and merge duplicates.</p><div className="relative">@@ -169,166 +377,31 @@ export function SpeakersSection() {/></div>- {/* Named speakers */}- <div className="space-y-1">- <h3 className="text-sm font-medium text-foreground">- named speakers ({filteredSpeakers.length})- </h3>- <div className="space-y-1">- {filteredSpeakers.length === 0 && (- <p className="text-xs text-muted-foreground py-4 text-center">- {searchQuery ? "no speakers match your search" : "no named speakers yet"}- </p>- )}- {filteredSpeakers.map((s) => (- <div- key={s.id}- className="flex items-center gap-3 px-3 py-2 border border-border rounded-md group"- >- <div className="h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-mono shrink-0">- {s.name.slice(0, 2).toUpperCase()}- </div>- {editingId === s.id ? (- <div className="flex items-center gap-1.5 flex-1">- <Input- value={editName}- onChange={(e) => setEditName(e.target.value)}- className="h-7 text-sm"- autoFocus- onKeyDown={(e) => {- if (e.key === "Enter" && editName.trim()) updateSpeaker(s.id, editName.trim());- if (e.key === "Escape") setEditingId(null);- }}- />- <Button- variant="ghost"- size="icon"- className="h-7 w-7"- disabled={saving === s.id}- onClick={() => editName.trim() && updateSpeaker(s.id, editName.trim())}- >- {saving === s.id ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Check className="h-3.5 w-3.5" />}- </Button>- <Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => setEditingId(null)}>- <X className="h-3.5 w-3.5" />- </Button>- </div>- ) : (- <>- <span className="text-sm flex-1">{s.name}</span>- <span className="text-xs text-muted-foreground">#{s.id}</span>- <div className="flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">- <Button- variant="ghost"- size="icon"- className="h-7 w-7"- title="rename"- onClick={() => { setEditingId(s.id); setEditName(s.name); }}- >- <Pencil className="h-3 w-3" />- </Button>- <Button- variant="ghost"- size="icon"- className="h-7 w-7 text-destructive"- title="delete speaker"- disabled={deleting === s.id}- onClick={() => deleteSpeaker(s.id)}- >- {deleting === s.id ? <Loader2 className="h-3 w-3 animate-spin" /> : <Trash2 className="h-3 w-3" />}- </Button>- </div>- </>- )}- </div>- ))}- </div>+ <div className="text-xs text-muted-foreground">+ {speakers.length} named · {unnamed.length} unnamed</div>- {/* Unnamed speakers */}- {unnamed.length > 0 && (- <div className="space-y-1">- <h3 className="text-sm font-medium text-foreground">- unnamed speakers ({unnamed.length})- </h3>- <p className="text-xs text-muted-foreground">- assign names to improve auto-detection accuracy+ <div className="space-y-1.5">+ {allSpeakers.length === 0 && (+ <p className="text-sm text-muted-foreground py-8 text-center">+ {searchQuery ? "no speakers match your search" : "no speakers detected yet"}</p>- <div className="space-y-1">- {unnamed.map((s) => (- <div- key={s.id}- className="flex items-center gap-3 px-3 py-2 border border-border/50 rounded-md group"- >- <div className="h-8 w-8 rounded-full bg-muted/50 flex items-center justify-center text-xs text-muted-foreground shrink-0">- ?- </div>- {editingId === s.id ? (- <div className="flex items-center gap-1.5 flex-1">- <Input- value={editName}- onChange={(e) => setEditName(e.target.value)}- placeholder="enter name..."- className="h-7 text-sm"- autoFocus- onKeyDown={(e) => {- if (e.key === "Enter" && editName.trim()) updateSpeaker(s.id, editName.trim());- if (e.key === "Escape") setEditingId(null);- }}- />- <Button- variant="ghost"- size="icon"- className="h-7 w-7"- disabled={saving === s.id}- onClick={() => editName.trim() && updateSpeaker(s.id, editName.trim())}- >- {saving === s.id ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <Check className="h-3.5 w-3.5" />}- </Button>- <Button variant="ghost" size="icon" className="h-7 w-7" onClick={() => setEditingId(null)}>- <X className="h-3.5 w-3.5" />- </Button>- </div>- ) : (- <>- <span className="text-sm text-muted-foreground flex-1">Speaker #{s.id}</span>- <div className="flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity">- <Button- variant="ghost"- size="icon"- className="h-7 w-7"- title="assign name"- onClick={() => { setEditingId(s.id); setEditName(""); }}- >- <UserCheck className="h-3 w-3" />- </Button>- <Button- variant="ghost"- size="icon"- className="h-7 w-7"- title="false detection"- onClick={() => markHallucination(s.id)}- >- <UserX className="h-3 w-3" />- </Button>- <Button- variant="ghost"- size="icon"- className="h-7 w-7 text-destructive"- title="delete"- disabled={deleting === s.id}- onClick={() => deleteSpeaker(s.id)}- >- {deleting === s.id ? <Loader2 className="h-3 w-3 animate-spin" /> : <Trash2 className="h-3 w-3" />}- </Button>- </div>- </>- )}- </div>- ))}- </div>- </div>- )}+ )}+ {allSpeakers.map((s) => (+ <SpeakerRow+ key={s.id}+ speaker={s}+ isNamed={s.isNamed}+ expanded={expandedId === s.id}+ onToggle={() => setExpandedId(expandedId === s.id ? null : s.id)}+ onEdit={updateSpeaker}+ onDelete={deleteSpeaker}+ onHallucination={markHallucination}+ onMerge={mergeSpeakers}+ onRefresh={fetchSpeakers}+ />+ ))}+ </div></div>);}