Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
parseClipboardContent,
uuid
} from '#lib/utils/index.ts';
import { VoiceRecorder, warmUpVoiceCapture } from '#lib/voice/index.ts';
import { unlockVoicePlayback, VoiceRecorder, warmUpVoiceCapture } from '#lib/voice/index.ts';
import { onMount, tick, untrack } from 'svelte';
import type { ClassValue } from 'svelte/elements';
import { toast } from 'svelte-sonner';
Expand Down Expand Up @@ -99,6 +99,8 @@

/** Records voice input; tests and stories pass a fake, the app a VoiceRecorder. */
voiceRecorder?: VoiceRecorderLike;
/** Offers voice mode, a spoken conversation, as the main button of an empty message. */
voiceMode?: boolean;
}

let {
Expand All @@ -121,6 +123,7 @@
singleRow = false,
uploadedFiles = $bindable([]),
value = $bindable(''),
voiceMode = false,
voiceRecorder
}: Props = $props();

Expand Down Expand Up @@ -647,6 +650,16 @@
onSubmit?.();
}

// voice mode leads only when what is said can be transcribed: the chat model hears, or a
// transcription model is set or loaded; else the microphone leads, saying why it cannot
let voiceModeAvailable = $derived(voiceMode && !voice.unavailableReason);

// inside the click: a browser that plays sound only after a gesture lets the replies play later
function handleVoiceModeClick() {
unlockVoicePlayback();
uiStore.voiceModeOpen = true;
}

// Escape drops a recording, wherever the focus is
function handleWindowKeydown(event: KeyboardEvent) {
if (event.key !== KeyboardKey.ESCAPE || !voice.isActive || event.defaultPrevented) return;
Expand Down Expand Up @@ -842,6 +855,7 @@
{onStop}
onSystemPromptClick={() =>
onSystemPromptClick?.({ files: uploadedFiles, message: value })}
onVoiceModeClick={voiceModeAvailable ? handleVoiceModeClick : undefined}
onWorkingDirectoryClick={isWorkingDirectoryInAddMenu
? pickers.handleWorkingDirectoryOpen
: undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
micWarning?: string | null;
/** Why no model can take the recording; disables the button. */
unavailableReason?: string | null;
/** A quieter button, beside the main one (stop or send). */
/** A quieter button, beside the main one: stop, send or voice mode. */
secondary?: boolean;
onMicClick?: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
The chat form's main button while the message is empty: opens voice mode, a spoken conversation with the model.
The microphone beside it records into the message instead.
-->
<script lang="ts">
import { Button } from '@ggml-org/llama-ui/ui/button';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { AudioLines } from '@lucide/svelte';
import { ICON_CLASS_DEFAULT, VOICE_CONVERSATION_MESSAGE } from '#lib/constants/index.ts';

interface Props {
class?: string;
disabled?: boolean;
/** Why voice mode cannot listen; disables the button and says why. */
unavailableReason?: string | null;
onClick?: () => void;
}

let {
class: className = '',
disabled = false,
onClick,
unavailableReason = null
}: Props = $props();
</script>

<div class="flex items-center {className}">
<Tooltip.Root>
<Tooltip.Trigger>
<Button
class="size-8 rounded-full p-0 max-md:size-9"
disabled={disabled || !!unavailableReason}
onclick={onClick}
type="button"
>
<span class="sr-only">{VOICE_CONVERSATION_MESSAGE.open}</span>

<AudioLines class={ICON_CLASS_DEFAULT} />
</Button>
</Tooltip.Trigger>

<Tooltip.Content class="max-w-64">
<p>{unavailableReason ?? VOICE_CONVERSATION_MESSAGE.open}</p>
</Tooltip.Content>
</Tooltip.Root>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { Button } from '@ggml-org/llama-ui/ui/button';
import { SkipForward, Square } from '@lucide/svelte';
import {
ChatFormActionReasoning,
ChatFormActionRecord,
ChatFormActionsAdd,
ChatFormActionSubmit,
ChatFormActionVoiceMode,
ChatFormContextGauge,
ModelsSelector
} from '#lib/components/app/index.ts';
Expand Down Expand Up @@ -42,6 +42,10 @@
workingDirectory?: string | null;
onFileUpload?: () => void;
onMicClick?: () => void;
/** Opens voice mode; left out, the microphone is the main button. */
onVoiceModeClick?: () => void;
/** Why voice mode cannot listen. */
voiceModeUnavailableReason?: string | null;
onStop?: () => void;
onSystemPromptClick?: () => void;
onWorkingDirectoryClick?: () => void;
Expand All @@ -59,11 +63,13 @@
onMicClick,
onStop,
onSystemPromptClick,
onVoiceModeClick,
onWorkingDirectoryClick,
showAddButton = true,
showModelSelector = true,
uploadedFiles = [],
voice,
voiceModeUnavailableReason = null,
workingDirectory = null
}: Props = $props();

Expand Down Expand Up @@ -161,12 +167,12 @@
{/if}

{#if showModelSelector}
<ChatFormActionReasoning />

<!-- the reasoning effort sits in the model picker, under the models -->
<ModelsSelector
bind:this={selectorModelRef}
{disabled}
forceForegroundText
showReasoning
useGlobalSelection
/>
{/if}
Expand Down Expand Up @@ -214,15 +220,25 @@
/>
</Button>
{:else if shouldShowRecordButton}
<!-- with voice mode, the microphone steps back beside it: voice mode is the main button -->
<ChatFormActionRecord
action={voice?.action}
{disabled}
hint={voice?.hint}
{isLoading}
{micWarning}
{onMicClick}
secondary={!!onVoiceModeClick}
unavailableReason={voice?.unavailableReason}
/>

{#if onVoiceModeClick}
<ChatFormActionVoiceMode
{disabled}
onClick={onVoiceModeClick}
unavailableReason={voiceModeUnavailableReason ?? voice?.unavailableReason ?? null}
/>
{/if}
{:else}
<ChatFormActionSubmit
canSend={canSend && (showModelSelector ? hasModelSelected && isSelectedModelInCache : true)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
ChatScreenForm,
ChatScreenServerError,
ChatScreenStreamResumeStatus,
ServerLoadingSplash
ServerLoadingSplash,
VoiceModeScreen
} from '#lib/components/app/index.ts';
import {
CHAT_FORM_BOTTOM_OFFSET,
Expand Down Expand Up @@ -392,6 +393,10 @@
</div>
{/if}

{#if uiStore.voiceModeOpen}
<VoiceModeScreen />
{/if}

<ChatScreenDialogsAndAlerts
{activeErrorDialog}
{emptyFileNames}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,6 @@
onSystemPromptClick={handleSystemPromptClick}
onUploadedFileRemove={handleUploadedFileRemove}
singleRow={settingsStore.config[SETTINGS_KEYS.SINGLE_ROW_CHAT_FORM] !== false}
voiceMode
/>
</div>
Loading