Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@anlg/plugin-deeplink2": "workspace:*",
"@anlg/plugin-detect": "workspace:*",
"@anlg/plugin-dictation": "workspace:*",
"@anlg/plugin-shortcut": "workspace:*",
"@anlg/plugin-export": "workspace:*",
"@anlg/plugin-fs-sync": "workspace:*",
"@anlg/plugin-fs2": "workspace:*",
Expand Down
22 changes: 22 additions & 0 deletions apps/desktop/public/dictation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Anarlog Dictation</title>
<style>
html, body { margin: 0; width: 100%; height: 100%; background: #191919; color: white; font: 14px system-ui; }
body { display: flex; align-items: center; justify-content: center; gap: 12px; }
.light { width: 10px; height: 10px; border-radius: 50%; background: #ff5757; animation: pulse 1s infinite alternate; }
.processing { display: none; }
[data-phase="processing"] .recording { display: none; }
[data-phase="processing"] .processing { display: inline; }
[data-phase="processing"] .light { background: #aaa; }
@keyframes pulse { to { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .light { animation: none; } }
</style>
<body data-phase="recording">
<span class="light"></span>
<span class="recording">Listening…</span>
<span class="processing">Transcribing…</span>
</body>
</html>
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn main() {
.plugin(
tauri_plugin_window_state::Builder::default()
.with_state_flags(tauri_plugin_windows::persisted_window_state_flags())
.with_denylist(&["composer"])
.with_denylist(&["composer", "dictation-overlay"])
.build(),
)
.plugin(tauri_plugin_transcription::init())
Expand Down Expand Up @@ -397,6 +397,7 @@ pub fn main() {
.on_window_event(tauri_plugin_windows::on_window_event)
.setup(move |app| {
let app_handle = app.handle().clone();
tauri_plugin_shortcut::initialize_global_shortcuts(&app_handle);

specta_builder.mount_events(&app_handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ describe("useDictation", () => {
await result.current.start();
});
expect(result.current.phase).toBe("recording");
expect(mocks.startRecording).toHaveBeenCalledWith("Built-in Microphone");
expect(mocks.startRecording).toHaveBeenCalledWith(
"Built-in Microphone",
mocks.useRunBatch.mock.calls[0][0],
);

await act(async () => {
await result.current.stop();
Expand Down
35 changes: 27 additions & 8 deletions apps/desktop/src/chat/components/input/use-dictation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ export function useDictation({

const result = await dictationCommands.startRecording(
microphoneDevice || null,
transcriptionSessionId,
);
if (result.status === "error") {
throw new Error(result.error);
}
if (!mountedRef.current) {
await cancelActiveRecording();
await cancelActiveRecording(transcriptionSessionId);
return;
}

Expand All @@ -93,7 +94,7 @@ export function useDictation({
}
}, 250);
} catch (error) {
await cancelActiveRecording();
await cancelActiveRecording(transcriptionSessionId);
if (!mountedRef.current) {
return;
}
Expand All @@ -103,7 +104,14 @@ export function useDictation({
});
console.error("[chat-dictation] failed to start recording", error);
}
}, [disabled, microphoneDevice, setPhase, stopElapsedTimer, t]);
}, [
disabled,
microphoneDevice,
setPhase,
stopElapsedTimer,
t,
transcriptionSessionId,
]);

const stop = useCallback(async () => {
if (phaseRef.current !== "recording") {
Expand All @@ -115,7 +123,9 @@ export function useDictation({
let recordedPath: string | null = null;

try {
const result = await dictationCommands.stopRecording();
const result = await dictationCommands.stopRecording(
transcriptionSessionId,
);
if (result.status === "error") {
throw new Error(result.error);
}
Expand Down Expand Up @@ -163,7 +173,14 @@ export function useDictation({
editorRef.current?.focus();
}
}
}, [editorRef, runBatch, setPhase, stopElapsedTimer, t]);
}, [
editorRef,
runBatch,
setPhase,
stopElapsedTimer,
t,
transcriptionSessionId,
]);
stopRef.current = stop;

useMountEffect(() => {
Expand All @@ -172,7 +189,7 @@ export function useDictation({
mountedRef.current = false;
stopElapsedTimer();
if (phaseRef.current === "starting" || phaseRef.current === "recording") {
void cancelActiveRecording();
void cancelActiveRecording(transcriptionSessionId);
}
};
});
Expand All @@ -185,9 +202,11 @@ export function useDictation({
};
}

async function cancelActiveRecording() {
async function cancelActiveRecording(transcriptionSessionId: string) {
try {
const result = await dictationCommands.cancelRecording();
const result = await dictationCommands.cancelRecording(
transcriptionSessionId,
);
if (result.status === "error") {
throw new Error(result.error);
}
Expand Down
Loading
Loading