Skip to content

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

feat: add speakers in search pipe

Louis Beaumont277c6d24ad16
diff --git a/pipes/search/bun.lockb b/pipes/search/bun.lockb
index f0e625d6b..0bf321cba 100755
Binary files a/pipes/search/bun.lockb and b/pipes/search/bun.lockb differ
diff --git a/pipes/search/package.json b/pipes/search/package.json
index 60e1c9444..69ef60a41 100644
--- a/pipes/search/package.json
+++ b/pipes/search/package.json
@@ -1,6 +1,6 @@
{
"name": "search",
- "version": "0.1.14",
+ "version": "0.1.15",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
@@ -10,6 +10,7 @@
},
"dependencies": {
"@radix-ui/react-accordion": "^1.2.2",
+ "@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-label": "^2.1.1",
diff --git a/pipes/search/src/components/search-chat.tsx b/pipes/search/src/components/search-chat.tsx
index 30b7168ab..2c17c49d9 100644
--- a/pipes/search/src/components/search-chat.tsx
+++ b/pipes/search/src/components/search-chat.tsx
@@ -1077,6 +1077,8 @@ export function SearchChat() {
filePath={item.content.filePath}
startTime={item.content.startTime}
endTime={item.content.endTime}
+ speaker={item.content.speaker}
+
/>
</div>
) : (
diff --git a/pipes/search/src/components/ui/avatar.tsx b/pipes/search/src/components/ui/avatar.tsx
new file mode 100644
index 000000000..51e507ba9
--- /dev/null
+++ b/pipes/search/src/components/ui/avatar.tsx
@@ -0,0 +1,50 @@
+"use client"
+
+import * as React from "react"
+import * as AvatarPrimitive from "@radix-ui/react-avatar"
+
+import { cn } from "@/lib/utils"
+
+const Avatar = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Root
+ ref={ref}
+ className={cn(
+ "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
+ className
+ )}
+ {...props}
+ />
+))
+Avatar.displayName = AvatarPrimitive.Root.displayName
+
+const AvatarImage = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Image>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Image
+ ref={ref}
+ className={cn("aspect-square h-full w-full", className)}
+ {...props}
+ />
+))
+AvatarImage.displayName = AvatarPrimitive.Image.displayName
+
+const AvatarFallback = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Fallback>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Fallback
+ ref={ref}
+ className={cn(
+ "flex h-full w-full items-center justify-center rounded-full bg-muted",
+ className
+ )}
+ {...props}
+ />
+))
+AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
+
+export { Avatar, AvatarImage, AvatarFallback }
diff --git a/pipes/search/src/components/video.tsx b/pipes/search/src/components/video.tsx
index a7cfce539..73f4b364b 100644
--- a/pipes/search/src/components/video.tsx
+++ b/pipes/search/src/components/video.tsx
@@ -1,6 +1,13 @@
import { memo, useCallback, useEffect, useState, useRef, useMemo } from "react";
import { getMediaFile } from "@/lib/actions/video-actions";
import { cn } from "@/lib/utils";
+import { Speaker } from "@screenpipe/browser";
+import { motion } from "framer-motion";
+import { Slider } from "@/components/ui/slider";
+import { Button } from "@/components/ui/button";
+import { Avatar, AvatarFallback } from "@/components/ui/avatar";
+import { Pause, Play, Pencil, Save, X } from "lucide-react";
+import { Input } from "@/components/ui/input";
export const VideoComponent = memo(function VideoComponent({
filePath,
@@ -8,12 +15,14 @@ export const VideoComponent = memo(function VideoComponent({
className,
startTime,
endTime,
+ speaker,
}: {
filePath: string;
customDescription?: string;
className?: string;
startTime?: number;
endTime?: number;
+ speaker?: Speaker;
}) {
const [mediaSrc, setMediaSrc] = useState<string | null>(null);
const [error, setError] = useState<string | null>(null);
@@ -30,14 +39,21 @@ export const VideoComponent = memo(function VideoComponent({
.replace(/\//g, "/");
}, []);
const renderFileLink = () => (
- <div className="mt-2 text-center text-xs text-gray-500 truncate px-2" title={filePath}>
+ <div
+ className="mt-2 text-center text-xs text-gray-500 truncate px-2"
+ title={filePath}
+ >
{customDescription || filePath}
</div>
);
- const validateMedia = async(path: string): Promise<string> => {
+ const validateMedia = async (path: string): Promise<string> => {
try {
- const response = await fetch(`http://localhost:3030/experimental/validate/media?file_path=${encodeURIComponent(path)}`);
+ const response = await fetch(
+ `http://localhost:3030/experimental/validate/media?file_path=${encodeURIComponent(
+ path
+ )}`
+ );
const result = await response.json();
return result.status;
} catch (error) {
@@ -57,12 +73,12 @@ export const VideoComponent = memo(function VideoComponent({
}
const validationStatus = await validateMedia(sanitizedPath);
- console.log("Media file:", validationStatus)
+ console.log("Media file:", validationStatus);
if (validationStatus === "valid media file") {
setIsAudio(
sanitizedPath.toLowerCase().includes("input") ||
- sanitizedPath.toLowerCase().includes("output")
+ sanitizedPath.toLowerCase().includes("output")
);
const { data, mimeType } = await getMediaFile(sanitizedPath);
const binaryData = atob(data);
@@ -73,11 +89,19 @@ export const VideoComponent = memo(function VideoComponent({
const blob = new Blob([bytes], { type: mimeType });
setMediaSrc(URL.createObjectURL(blob));
} else if (validationStatus.startsWith("media file does not exist")) {
- throw new Error(`${isAudio ? "audio" : "video" } file not exists, it might get deleted`);
+ throw new Error(
+ `${
+ isAudio ? "audio" : "video"
+ } file not exists, it might get deleted`
+ );
} else if (validationStatus.startsWith("invalid media file")) {
- throw new Error(`the ${isAudio ? "audio" : "video" } file is not written completely, please try again later`);
- } else {
- throw new Error("unknown media validation status");
+ throw new Error(
+ `the ${
+ isAudio ? "audio" : "video"
+ } file is not written completely, please try again later`
+ );
+ } else {
+ throw new Error("unknown media validation status");
}
} catch (error) {
console.warn("Failed to load media:", error);
@@ -124,6 +148,7 @@ export const VideoComponent = memo(function VideoComponent({
startTime={startTime}
endTime={endTime}
mediaSrc={mediaSrc}
+ speaker={speaker}
/>
) : (
<video controls className="w-full rounded-md">
@@ -142,16 +167,56 @@ const AudioPlayer = memo(function AudioPlayer({
startTime,
endTime,
mediaSrc,
+ speaker,
}: {
startTime?: number;
endTime?: number;
mediaSrc: string;
+ speaker?: Speaker;
}) {
const [duration, setDuration] = useState<number>(0);
const [currentTime, setCurrentTime] = useState<number>(0);
const [isPlaying, setIsPlaying] = useState(false);
+ const [isEditing, setIsEditing] = useState(false);
+ const [speakerName, setSpeakerName] = useState(speaker?.name || "");
+ const [speakers, setSpeakers] = useState<Speaker[]>([]);
+ const [isSearching, setIsSearching] = useState(false);
+ const [showSpeakerNames, setShowSpeakerNames] = useState(false);
const audioRef = useRef<HTMLAudioElement>(null);
+ const handleUpdateSpeakerName = async () => {
+ try {
+ await fetch(`http://localhost:3030/speakers/update`, {
+ method: "POST",
+ body: JSON.stringify({
+ id: speaker?.id,
+ name: speakerName,
+ }),
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ setIsEditing(false);
+ } catch (error) {
+ console.error("error updating speaker name:", error);
+ }
+ };
+
+ const fetchSpeakers = async (searchTerm: string) => {
+ setIsSearching(true);
+ try {
+ const response = await fetch(
+ `http://localhost:3030/speakers/search?name=${searchTerm}`
+ );
+ const result = await response.json();
+ setSpeakers(result);
+ } catch (error) {
+ console.error("error fetching speakers:", error);
+ } finally {
+ setIsSearching(false);
+ }
+ };
+
const audioElement = useMemo(
() => (
<audio
@@ -198,20 +263,16 @@ const AudioPlayer = memo(function AudioPlayer({
}
};
- const handleTimeChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
+ const handleTimeChange = async (value: number) => {
if (!audioRef.current) return;
- const time = parseFloat(e.target.value);
const wasPlaying = isPlaying;
-
if (wasPlaying) {
audioRef.current.pause();
}
- // Set the time directly on the audio element first
- audioRef.current.currentTime = time;
- // Then update the state
- setCurrentTime(time);
+ audioRef.current.currentTime = value;
+ setCurrentTime(value);
if (wasPlaying) {
try {
@@ -223,79 +284,175 @@ const AudioPlayer = memo(function AudioPlayer({
}
};
+ const formatTime = (seconds: number): string => {
+ const mins = Math.floor(seconds / 60);
+ const secs = Math.floor(seconds % 60);
+ return `${mins}:${secs.toString().padStart(2, "0")}`;
+ };
+
return (
- <div className="bg-gray-100 px-4 py-6 rounded-md">
- <div className="relative">
- {startTime !== null && (
- <div
- className="absolute top-[-8px] h-6 w-0.5 bg-black z-10"
- style={{
- left: `calc(88px + ${
- (startTime || 0) / duration
- } * calc(100% - 176px))`,
- }}
- >
- <div className="absolute -top-4 left-1/2 -translate-x-1/2 text-xs">
- Start
- </div>
+ <motion.div
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ className="rounded-lg border bg-card p-4 space-y-4"
+ >
+ {speaker && (
+ <div className="mb-3 flex items-center gap-2">
+ <div className="w-8 h-8 rounded-full bg-black flex items-center justify-center text-white">
+ {speakerName?.[0]?.toUpperCase() || "S"}
</div>
- )}
- {endTime !== null && (
- <div
- className="absolute top-[-8px] h-6 w-0.5 bg-black z-10"
- style={{
- left: `calc(88px + ${
- (endTime || 0) / duration
- } * calc(100% - 176px))`,
- }}
- >
- <div className="absolute -top-4 left-1/2 -translate-x-1/2 text-xs">
- End
- </div>
+ <div className="text-sm flex-1">
+ {isEditing ? (
+ <div className="flex items-center gap-2">
+ <div className="relative flex-1">
+ <Input
+ value={speakerName}
+ onChange={(e) => {
+ setSpeakerName(e.target.value);
+ fetchSpeakers(e.target.value);
+ }}
+ onFocus={() => setShowSpeakerNames(true)}
+ onBlur={() =>
+ setTimeout(() => setShowSpeakerNames(false), 200)
+ }
+ className="h-8"
+ placeholder="Enter speaker name"
+ />
+ {showSpeakerNames && speakerName && (
+ <div className="absolute z-10 w-full mt-1 bg-white border rounded-md shadow-lg max-h-48 overflow-y-auto">
+ {isSearching ? (
+ <div className="flex justify-center items-center p-4">
+ <div className="animate-spin rounded-full h-6 w-6 border-b-2 border-gray-900"></div>
+ </div>
+ ) : (
+ <ul className="py-1">
+ {speakers.map((s) => (
+ <li
+ key={s.id}
+ className="px-3 py-2 hover:bg-gray-100 cursor-pointer truncate"
+ onClick={() => {
+ setSpeakerName(s.name || "");
+ setShowSpeakerNames(false);
+ }}
+ >
+ {s.name}
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ )}
+ </div>
+ <Button
+ size="sm"
+ onClick={handleUpdateSpeakerName}
+ disabled={!speakerName}
+ >
+ <Save className="h-4 w-4" />
+ </Button>
+ <Button
+ size="sm"
+ variant="ghost"
+ onClick={() => {
+ setIsEditing(false);
+ setSpeakerName(speaker.name || "");
+ }}
+ >
+ <X className="h-4 w-4" />
+ </Button>
+ </div>
+ ) : (
+ <div className="flex items-center gap-2">
+ <div className="font-medium">
+ {speakerName || "Speaker " + speaker.id}
+ </div>
+ <Button
+ size="sm"
+ variant="ghost"
+ className="h-6 w-6 p-0"
+ onClick={() => setIsEditing(true)}
+ >
+ <Pencil className="h-3 w-3" />
+ </Button>
+ </div>
+ )}
+ {speaker.metadata && !isEditing && (
+ <div className="text-xs text-gray-600">{speaker.metadata}</div>
+ )}
</div>
- )}
- <button
- onClick={togglePlay}
- className="absolute left-4 top-1/2 -translate-y-1/2 w-8 h-8 flex items-center justify-center bg-black hover:bg-gray-800 text-white rounded-full"
- >
- {isPlaying ? (
- <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
- <rect x="6" y="4" width="4" height="16" />
- <rect x="14" y="4" width="4" height="16" />
- </svg>
- ) : (
- <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
- <path d="M8 5v14l11-7z" />
- </svg>
- )}
- </button>
- <div className="mx-[88px] relative">
- <div className="h-1 bg-gray-300 rounded-full overflow-hidden">
- <div
- className="h-full bg-black"
- style={{
- width: `${(currentTime / duration) * 100}%`,
- }}
+ </div>
+ )}
+
+ <div className="space-y-2">
+ <div className="flex items-center gap-4">
+ <Button
+ variant="outline"
+ size="icon"
+ onClick={togglePlay}
+ className="h-8 w-8 rounded-full"
+ >
+ {isPlaying ? (
+ <Pause className="h-4 w-4" />
+ ) : (
+ <Play className="h-4 w-4" />
+ )}
+ </Button>
+
+ <div className="relative flex-1">
+ {startTime !== undefined && endTime !== undefined && (
+ <div
+ className="absolute top-[60%] bg-primary/20 rounded-full"
+ style={{
+ left: `${(startTime / duration) * 100}%`,
+ width: `${((endTime - startTime) / duration) * 100}%`,
+ }}
+ />
+ )}
+
+ <Slider
+ value={[currentTime]}
+ max={duration}
+ step={0.1}
+ onValueChange={([value]) => handleTimeChange(value)}
+ className="cursor-pointer"
/>
+
+ {startTime !== undefined && (
+ <div
+ className="absolute top-4 w-2 h-2 bg-primary rounded-full -translate-x-1/2"
+ title="start time where we found this audio transcript in the recorded file"
+ style={{
+ left: `${(startTime / duration) * 100}%`,
+ }}
+ >
+ <div className="absolute -bottom-5 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground">
+ {formatTime(startTime)}
+ </div>
+ </div>
+ )}
+
+ {endTime !== undefined && (
+ <div
+ className="absolute top-4 w-2 h-2 bg-primary rounded-full -translate-x-1/2"
+ title="end time where we found this audio transcript in the recorded file"
+ style={{
+ left: `${(endTime / duration) * 100}%`,
+ }}
+ >
+ <div className="absolute -bottom-5 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground">
+ {formatTime(endTime)}
+ </div>
+ </div>
+ )}
</div>
- <div
- className="absolute top-1/2 -translate-x-1/3 -translate-y-1/2 w-2 h-2 bg-black rounded-full cursor-pointer hover:bg-gray-800 hover:h-4 hover:w-4"
- style={{
- left: `${(currentTime / duration) * 100}%`,
- }}
- />
- <input
- type="range"
- min={0}
- max={duration}
- value={currentTime}
- onChange={handleTimeChange}
- className="absolute inset-0 w-full opacity-0 cursor-pointer"
- step="any"
- />
</div>
- {audioElement}
+
+ <div className="flex justify-between text-xs text-muted-foreground">
+ <span>{formatTime(currentTime)}</span>
+ <span>{formatTime(duration)}</span>
+ </div>
</div>
- </div>
+ {audioElement}
+ </motion.div>
);
});