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

polish(chat): animate dictation voice trace

Louis Beaumont946e1ffc040f
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.test.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.test.tsx
index 18bca1c4a..175b0df53 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.test.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.test.tsx
@@ -24,7 +24,7 @@ vi.mock("@/components/chat/standalone/hooks/use-composer-dictation", () => ({
error: mocks.error,
canRetry: mocks.canRetry,
elapsedMs: 2_000,
- waveform: [0.1, 0.3, 0.8, 0.4, 0.2],
+ waveform: [0.1, 0.25, 0.45, 0.7, 1, 0.65, 0.4, 0.2, 0.08],
start: mocks.start,
finish: mocks.finish,
cancel: mocks.cancel,
@@ -96,6 +96,9 @@ describe("ComposerDictationControl", () => {
"aria-label",
"Recording dictation, 0:02",
);
+ const waveform = screen.getByTestId("composer-dictation-waveform");
+ expect(waveform.children).toHaveLength(9);
+ expect(waveform.children[4]).toHaveStyle({ height: "18px", opacity: "1" });
fireEvent.click(screen.getByRole("button", { name: "Cancel dictation" }));
fireEvent.click(screen.getByRole("button", { name: "Finish dictation" }));
expect(mocks.cancel).toHaveBeenCalledTimes(1);
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.tsx
index b077db8f6..55eb7ae77 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/composer-dictation-control.tsx
@@ -87,12 +87,19 @@ export function ComposerDictationControl({
className="flex h-8 shrink-0 items-center gap-1 rounded-md border border-signal/45 bg-signal/10 px-1 text-signal"
data-testid="composer-dictation-recording"
>
- <div className="flex h-4 items-center gap-[2px] px-1" aria-hidden="true">
+ <div
+ className="flex h-5 items-center gap-[2px] px-1"
+ aria-hidden="true"
+ data-testid="composer-dictation-waveform"
+ >
{dictation.waveform.map((level, index) => (
<span
key={index}
- className="w-[2px] rounded-full bg-signal transition-[height] duration-75 motion-reduce:transition-none"
- style={{ height: `${Math.round(4 + level * 12)}px` }}
+ className="w-[2px] rounded-full bg-signal transition-[height,opacity] duration-150 ease-out motion-reduce:transition-none"
+ style={{
+ height: `${Math.round(3 + level * 15)}px`,
+ opacity: 0.45 + level * 0.55,
+ }}
/>
))}
</div>
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.test.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.test.tsx
index ec4bdcd23..fa271da05 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.test.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.test.tsx
@@ -22,6 +22,28 @@ const stopTrack = vi.fn();
const stream = {
getTracks: () => [{ stop: stopTrack }],
} as unknown as MediaStream;
+let frameCallback: FrameRequestCallback | null = null;
+
+class FakeAudioContext {
+ createAnalyser() {
+ return {
+ fftSize: 0,
+ getByteTimeDomainData: (samples: Uint8Array) => {
+ samples.forEach((_, index) => {
+ samples[index] = index % 2 === 0 ? 190 : 66;
+ });
+ },
+ } as AnalyserNode;
+ }
+
+ createMediaStreamSource() {
+ return { connect: vi.fn() } as unknown as MediaStreamAudioSourceNode;
+ }
+
+ close() {
+ return Promise.resolve();
+ }
+}
class FakeMediaRecorder {
static isTypeSupported = () => true;
@@ -53,6 +75,16 @@ describe("useComposerDictation", () => {
stopTrack.mockReset();
transcribeComposerAudio.mockReset();
vi.stubGlobal("MediaRecorder", FakeMediaRecorder);
+ vi.stubGlobal("AudioContext", FakeAudioContext);
+ vi.stubGlobal(
+ "requestAnimationFrame",
+ vi.fn((callback: FrameRequestCallback) => {
+ frameCallback = callback;
+ return 1;
+ }),
+ );
+ vi.stubGlobal("cancelAnimationFrame", vi.fn());
+ frameCallback = null;
Object.defineProperty(navigator, "mediaDevices", {
configurable: true,
value: { getUserMedia: vi.fn().mockResolvedValue(stream) },
@@ -112,4 +144,20 @@ describe("useComposerDictation", () => {
expect(onValueChange).toHaveBeenCalledWith("Ask now about yesterday");
expect(result.current.status).toBe("idle");
});
+
+ it("turns live microphone amplitude into a moving nine-bar trace", async () => {
+ const { result } = setup();
+
+ await act(async () => result.current.start());
+ expect(frameCallback).not.toBeNull();
+ act(() => frameCallback?.(100));
+
+ expect(result.current.waveform).toHaveLength(9);
+ expect(result.current.waveform.at(-1)).toBeGreaterThan(0.5);
+
+ await act(async () => {
+ result.current.cancel();
+ await Promise.resolve();
+ });
+ });
});
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.ts
index 1d077f62b..e188404ab 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-composer-dictation.ts
@@ -27,7 +27,7 @@ type UseComposerDictationOptions = {
};
const MAX_RECORDING_MS = 5 * 60 * 1000;
-const DEFAULT_WAVEFORM = [0.12, 0.12, 0.12, 0.12, 0.12];
+const DEFAULT_WAVEFORM = Array.from({ length: 9 }, () => 0.04);
function preferredAudioType(): string | undefined {
if (typeof MediaRecorder === "undefined") return undefined;
@@ -135,9 +135,10 @@ export function useComposerDictation({
audioContextRef.current = context;
const samples = new Uint8Array(analyser.fftSize);
let lastPaintAt = 0;
+ let smoothedLevel = 0.04;
const paint = (now: number) => {
if (!mountedRef.current || statusRef.current !== "recording") return;
- if (now - lastPaintAt >= 80) {
+ if (now - lastPaintAt >= 64) {
analyser.getByteTimeDomainData(samples);
let squareSum = 0;
for (const sample of samples) {
@@ -145,8 +146,13 @@ export function useComposerDictation({
squareSum += centered * centered;
}
const rms = Math.sqrt(squareSum / samples.length);
- const level = Math.min(1, Math.max(0.08, rms * 5));
- setWaveform((previous) => [...previous.slice(1), level]);
+ const responsiveLevel =
+ rms < 0.015 ? 0.04 : Math.min(1, (rms - 0.015) * 9);
+ smoothedLevel = Math.max(
+ 0.04,
+ smoothedLevel * 0.45 + responsiveLevel * 0.55,
+ );
+ setWaveform((previous) => [...previous.slice(1), smoothedLevel]);
lastPaintAt = now;
}
animationFrameRef.current = requestAnimationFrame(paint);
diff --git a/docs/pr-assets/chat-dictation/after-recording.png b/docs/pr-assets/chat-dictation/after-recording.png
index ec244848d..bb75509ba 100644
Binary files a/docs/pr-assets/chat-dictation/after-recording.png and b/docs/pr-assets/chat-dictation/after-recording.png differ