import { useAudioData, visualizeAudio } from "@remotion/media-utils"; import { AbsoluteFill, Audio, useCurrentFrame, useVideoConfig } from "remotion"; import { FPS, type AudiogramSquareProps } from "../schema"; import { theme } from "../theme"; import { Logo, ProgressBar } from "./shared"; import { Starfield } from "./Starfield"; const BARS = 48; export function audiogramDuration(props: AudiogramSquareProps): number { return Math.max(FPS, Math.round(props.durationS * FPS)); } function Waveform({ src, accent }: { src: string; accent: string }) { const frame = useCurrentFrame(); const { fps } = useVideoConfig(); const audio = useAudioData(src); const values = audio ? visualizeAudio({ fps, frame, audioData: audio, numberOfSamples: 64, smoothing: true }).slice(0, BARS) : Array.from({ length: BARS }, () => 0.02); return (
{values.map((v, i) => { const h = Math.max(6, Math.min(1, v * 6) * 240); return (
); })}
); } /** 1:1 audiogram: title, live waveform, the current line of the conversation and who is speaking. */ export function AudiogramSquare(props: AudiogramSquareProps) { const accent = props.brand.accent ?? theme.blue; const frame = useCurrentFrame(); const ms = (frame / FPS) * 1000; const current = props.segments.find((s) => ms >= s.startMs && ms < s.endMs); const speaker = current?.speaker === "host_b" ? "Host B" : "Host A"; return ( ); }