This commit is contained in:
Timothy Jaeryang Baek
2026-06-17 11:33:36 +02:00
Unverified
parent 6fdcbcfaa5
commit 82e312832b
14 changed files with 129 additions and 26 deletions
@@ -25,6 +25,7 @@
let ttsVoice = $state('alloy');
let ttsFormat = $state('mp3');
let ttsPlaybackSpeed = $state(1);
let ttsAutoStreamEnabled = $state(false);
let hasExistingTtsKey = $state(false);
let voiceModeSystemPrompt = $state('');
let voiceModeSttMode = $state<'browser' | 'provider'>('browser');
@@ -49,6 +50,7 @@
ttsFormat = (config['audio.tts_format'] as string) || 'mp3';
const speed = Number(config['audio.tts_playback_speed']);
ttsPlaybackSpeed = Number.isFinite(speed) ? Math.min(Math.max(speed, 0.5), 2) : 1;
ttsAutoStreamEnabled = config['audio.tts_auto_stream_enabled'] === true;
hasExistingTtsKey = !!config['audio.tts_api_key'];
voiceModeSystemPrompt = (config['audio.voice_mode_system_prompt'] as string) || '';
voiceModeSttMode =
@@ -72,6 +74,7 @@
'audio.tts_voice': ttsVoice,
'audio.tts_format': ttsFormat,
'audio.tts_playback_speed': ttsPlaybackSpeed,
'audio.tts_auto_stream_enabled': ttsAutoStreamEnabled,
'audio.voice_mode_system_prompt': voiceModeSystemPrompt,
'audio.voice_mode_stt_mode': voiceModeSttMode
};
@@ -105,23 +108,41 @@
<div class="flex flex-col gap-2.5">
<label class="flex items-center justify-between cursor-pointer">
<span class="text-xs text-gray-600 dark:text-gray-400">{$t('admin.audio.enableVoiceMemos')}</span>
<ToggleSwitch value={voiceMemosEnabled} onchange={(v) => { voiceMemosEnabled = v; }} />
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.audio.enableVoiceMemos')}</span
>
<ToggleSwitch
value={voiceMemosEnabled}
onchange={(v) => {
voiceMemosEnabled = v;
}}
/>
</label>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{$t('admin.audio.voiceMemosHint')}
</p>
<label class="flex items-center justify-between cursor-pointer">
<span class="text-xs text-gray-600 dark:text-gray-400">{$t('admin.audio.autoTranscribe')}</span>
<ToggleSwitch value={transcribeEnabled} onchange={(v) => { transcribeEnabled = v; }} />
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.audio.autoTranscribe')}</span
>
<ToggleSwitch
value={transcribeEnabled}
onchange={(v) => {
transcribeEnabled = v;
}}
/>
</label>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{transcribeEnabled ? $t('admin.audio.transcribeOnHint') : $t('admin.audio.transcribeOffHint')}
{transcribeEnabled
? $t('admin.audio.transcribeOnHint')
: $t('admin.audio.transcribeOffHint')}
</p>
<div class="flex items-center justify-between">
<span class="text-xs text-gray-600 dark:text-gray-400">{$t('admin.audio.recordingQuality')}</span>
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.audio.recordingQuality')}</span
>
<select
bind:value={quality}
class="bg-transparent text-xs text-gray-600 dark:text-gray-400 outline-none cursor-pointer"
@@ -132,7 +153,11 @@
</select>
</div>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{quality === 'high' ? $t('admin.audio.qualityHintHigh') : quality === 'medium' ? $t('admin.audio.qualityHintMedium') : $t('admin.audio.qualityHintLow')}
{quality === 'high'
? $t('admin.audio.qualityHintHigh')
: quality === 'medium'
? $t('admin.audio.qualityHintMedium')
: $t('admin.audio.qualityHintLow')}
</p>
</div>
@@ -141,7 +166,9 @@
<div class="flex flex-col gap-2.5">
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-base-url">{$t('connections.baseUrl')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-base-url"
>{$t('connections.baseUrl')}</label
>
<input
id="stt-base-url"
type="text"
@@ -151,7 +178,9 @@
/>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-api-key">{$t('connections.apiKey')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-api-key"
>{$t('connections.apiKey')}</label
>
<input
id="stt-api-key"
type="password"
@@ -161,7 +190,9 @@
/>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-model">{$t('automations.model')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="stt-model"
>{$t('automations.model')}</label
>
<input
id="stt-model"
type="text"
@@ -181,13 +212,34 @@
<div class="flex flex-col gap-2.5">
<label class="flex items-center justify-between cursor-pointer">
<span class="text-xs text-gray-600 dark:text-gray-400">{$t('admin.audio.enableTts')}</span>
<ToggleSwitch value={ttsEnabled} onchange={(v) => { ttsEnabled = v; }} />
<ToggleSwitch
value={ttsEnabled}
onchange={(v) => {
ttsEnabled = v;
}}
/>
</label>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{$t('admin.audio.ttsEnabledHint')}
</p>
<label class="flex items-center justify-between cursor-pointer">
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.audio.ttsAutoStream')}</span
>
<ToggleSwitch
value={ttsAutoStreamEnabled}
onchange={(v) => {
ttsAutoStreamEnabled = v;
}}
/>
</label>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{$t('admin.audio.ttsAutoStreamHint')}
</p>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-base-url">{$t('connections.baseUrl')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-base-url"
>{$t('connections.baseUrl')}</label
>
<input
id="tts-base-url"
type="text"
@@ -197,7 +249,9 @@
/>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-api-key">{$t('connections.apiKey')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-api-key"
>{$t('connections.apiKey')}</label
>
<input
id="tts-api-key"
type="password"
@@ -207,7 +261,9 @@
/>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-model">{$t('automations.model')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-model"
>{$t('automations.model')}</label
>
<input
id="tts-model"
type="text"
@@ -217,7 +273,9 @@
/>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-voice">{$t('admin.audio.ttsVoice')}</label>
<label class="text-xs text-gray-600 dark:text-gray-400" for="tts-voice"
>{$t('admin.audio.ttsVoice')}</label
>
<input
id="tts-voice"
type="text"
@@ -254,7 +312,9 @@
bind:value={ttsPlaybackSpeed}
class="w-28 accent-gray-700 dark:accent-gray-300"
/>
<span class="w-9 text-right text-xs text-gray-500 dark:text-gray-400">{ttsPlaybackSpeed.toFixed(2)}x</span>
<span class="w-9 text-right text-xs text-gray-500 dark:text-gray-400"
>{ttsPlaybackSpeed.toFixed(2)}x</span
>
</div>
</div>
<p class="text-[11px] text-gray-400 dark:text-gray-600">
@@ -263,11 +323,15 @@
</div>
<!-- Voice Mode -->
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">{$t('admin.audio.voiceMode')}</h3>
<h3 class="text-xs text-gray-400 dark:text-gray-600 mb-2 mt-5">
{$t('admin.audio.voiceMode')}
</h3>
<div class="flex flex-col gap-2.5">
<div class="flex items-center justify-between">
<span class="text-xs text-gray-600 dark:text-gray-400">{$t('admin.audio.voiceModeSttMode')}</span>
<span class="text-xs text-gray-600 dark:text-gray-400"
>{$t('admin.audio.voiceModeSttMode')}</span
>
<select
bind:value={voiceModeSttMode}
class="bg-transparent text-xs text-gray-600 dark:text-gray-400 outline-none cursor-pointer"
@@ -277,7 +341,9 @@
</select>
</div>
<p class="text-[11px] text-gray-400 dark:text-gray-600 -mt-1">
{voiceModeSttMode === 'browser' ? $t('admin.audio.voiceModeBrowserSttHint') : $t('admin.audio.voiceModeProviderSttHint')}
{voiceModeSttMode === 'browser'
? $t('admin.audio.voiceModeBrowserSttHint')
: $t('admin.audio.voiceModeProviderSttHint')}
</p>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="voice-mode-system-prompt">
@@ -297,12 +363,14 @@
</div>
<!-- Save -->
<div class="mt-auto pt-6 flex justify-end">
<div
class="sticky bottom-0 -mx-4 md:-mx-5 mt-6 flex justify-end border-t border-gray-100 bg-white/95 px-4 py-3 backdrop-blur dark:border-white/6 dark:bg-black/95 md:px-5"
>
<button
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-50"
onclick={() => save()}
disabled={saving}
>{$t('settings.save')}</button>
disabled={saving}>{$t('settings.save')}</button
>
</div>
{/if}
</div>
@@ -38,6 +38,7 @@
ttsConfigured,
ttsFormat,
setTtsAudioPlaybackSource,
ttsAutoStreamEnabled,
ttsPlaybackEnabled,
ttsVoice,
unlockTtsAudioPlayback,
@@ -952,6 +953,10 @@
return $ttsEnabled && $ttsConfigured && ($ttsPlaybackEnabled || $voiceModeEnabled);
}
function shouldStreamTts() {
return $ttsEnabled && $ttsConfigured && ($voiceModeEnabled || $ttsAutoStreamEnabled);
}
function resetTtsBuffer() {
ttsBuffer = '';
ttsInsideCodeFence = false;
@@ -1023,7 +1028,7 @@
}
function handleTtsDelta(messageId: string, delta: string) {
if (!shouldUseTts()) return;
if (!shouldStreamTts()) return;
if (!delta.trim()) return;
const active = allMessages.find((m) => m.id === messageId);
@@ -1043,7 +1048,7 @@
}
function flushTtsBuffer() {
if (!shouldUseTts()) return;
if (!shouldStreamTts()) return;
const chunk = cleanSpeechText(ttsBuffer);
resetTtsBuffer();
if (chunk.length > 1) enqueueSpeech(chunk);
@@ -1242,6 +1247,7 @@
if (generation === ttsGeneration) ttsPlaying = false;
if (generation === ttsGeneration) speakingMessageId = null;
if (generation === ttsGeneration) ttsStopRequested = false;
if (generation === ttsGeneration && !$voiceModeEnabled) ttsPlaybackEnabled.set(false);
}
}
</script>
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Text-to-Speech aktivieren",
"admin.audio.ttsEnabledHint": "Aktiviert den Sprachmodus und die Vorlesen-Schaltflächen, wenn ein TTS-Schlüssel verfügbar ist.",
"admin.audio.ttsAutoStream": "Stream-Antworten vorlesen",
"admin.audio.ttsAutoStreamHint": "Liest jede Assistentenantwort beim Streamen laut vor, auch außerhalb des Sprachmodus.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -593,6 +593,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -477,6 +477,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
@@ -478,6 +478,8 @@
"admin.audio.tts": "Text-to-Speech",
"admin.audio.enableTts": "Enable Text-to-Speech",
"admin.audio.ttsEnabledHint": "Enables voice mode and assistant speak buttons when a TTS key is available.",
"admin.audio.ttsAutoStream": "Speak streamed responses",
"admin.audio.ttsAutoStreamHint": "Read every assistant response aloud as it streams, even outside voice mode.",
"admin.audio.ttsKeyPlaceholder": "Leave blank to reuse STT key",
"admin.audio.ttsVoice": "Voice",
"admin.audio.ttsFormat": "Format",
+9 -2
View File
@@ -22,10 +22,13 @@ export const ttsConfigured = writable<boolean>(false);
export const ttsVoice = writable<string>('alloy');
export const ttsFormat = writable<string>('mp3');
export const ttsPlaybackSpeed = writable<number>(1);
export const ttsAutoStreamEnabled = writable<boolean>(false);
export const voiceModeEnabled = writable<boolean>(false);
export const voiceModeSttMode = writable<'browser' | 'provider'>('browser');
export const ttsPlaybackEnabled = writable<boolean>(
typeof localStorage !== 'undefined' ? localStorage.getItem('ttsPlaybackEnabled') === 'true' : false
typeof localStorage !== 'undefined'
? localStorage.getItem('ttsPlaybackEnabled') === 'true'
: false
);
const SILENT_WAV =
@@ -74,7 +77,8 @@ export async function unlockTtsAudioPlayback() {
const unlocks: Promise<unknown>[] = [];
const AudioContextCtor =
window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
window.AudioContext ||
(window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
try {
if (AudioContextCtor) {
ttsAudioContext ??= new AudioContextCtor();
@@ -128,6 +132,7 @@ export async function refreshAudioState() {
tts_voice: string;
tts_format: string;
tts_playback_speed?: number;
tts_auto_stream_enabled?: boolean;
voice_mode_stt_mode?: string;
}>('/api/audio/state');
voiceMemosEnabled.set(data.voice_memos_enabled === true);
@@ -142,6 +147,7 @@ export async function refreshAudioState() {
ttsFormat.set(data.tts_format || 'mp3');
const speed = Number(data.tts_playback_speed);
ttsPlaybackSpeed.set(Number.isFinite(speed) ? Math.min(Math.max(speed, 0.5), 2) : 1);
ttsAutoStreamEnabled.set(data.tts_auto_stream_enabled === true);
voiceModeSttMode.set(data.voice_mode_stt_mode === 'provider' ? 'provider' : 'browser');
} catch {
voiceMemosEnabled.set(false);
@@ -149,6 +155,7 @@ export async function refreshAudioState() {
ttsEnabled.set(false);
ttsConfigured.set(false);
ttsPlaybackSpeed.set(1);
ttsAutoStreamEnabled.set(false);
voiceModeSttMode.set('browser');
}
}
+2
View File
@@ -55,6 +55,7 @@ class AudioStateResponse(BaseModel):
tts_voice: str
tts_format: str
tts_playback_speed: float
tts_auto_stream_enabled: bool
voice_mode_stt_mode: str
@@ -218,6 +219,7 @@ async def audio_state(request: Request):
tts_voice=str((await Config.get("audio.tts_voice")) or "alloy"),
tts_format=str((await Config.get("audio.tts_format")) or "mp3"),
tts_playback_speed=playback_speed,
tts_auto_stream_enabled=await Config.get("audio.tts_auto_stream_enabled") is True,
voice_mode_stt_mode=str((await Config.get("audio.voice_mode_stt_mode")) or "browser"),
)