From fb91b4d3a36ff2ddf4cf2148c52c8dc6fc5bf932 Mon Sep 17 00:00:00 2001 From: Chris Scott Date: Fri, 28 Nov 2025 19:52:35 -0500 Subject: [PATCH] Add TTS support with OpenAI-compatible endpoint configuration - Add TTS settings schema and configuration UI with validation - Create backend TTS proxy with 24hr file-based caching - Add frontend useTTS hook with Cache API caching - Add TTS playback button on assistant messages (step-finish) - Include test button to verify TTS configuration --- backend/src/index.ts | 5 +- backend/src/routes/tts.ts | 175 ++++++++++ frontend/package.json | 1 + frontend/src/api/types/settings.ts | 20 ++ .../src/components/message/MessagePart.tsx | 47 ++- .../src/components/message/MessageThread.tsx | 9 + .../components/settings/GeneralSettings.tsx | 19 +- .../src/components/settings/TTSSettings.tsx | 317 ++++++++++++++++++ frontend/src/components/ui/slider.tsx | 26 ++ frontend/src/hooks/useTTS.ts | 192 +++++++++++ pnpm-lock.yaml | 33 ++ shared/src/schemas/settings.ts | 20 ++ 12 files changed, 859 insertions(+), 5 deletions(-) create mode 100644 backend/src/routes/tts.ts create mode 100644 frontend/src/components/settings/TTSSettings.tsx create mode 100644 frontend/src/components/ui/slider.tsx create mode 100644 frontend/src/hooks/useTTS.ts diff --git a/backend/src/index.ts b/backend/src/index.ts index 3aae1970..7729e468 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -6,7 +6,7 @@ import { initializeDatabase } from './db/schema' import { createRepoRoutes } from './routes/repos' import { createSettingsRoutes } from './routes/settings' import { createHealthRoutes } from './routes/health' - +import { createTTSRoutes, cleanupExpiredCache } from './routes/tts' import { createFileRoutes } from './routes/files' import { createProvidersRoutes } from './routes/providers' import { ensureDirectoryExists, writeFileContent } from './services/file-operations' @@ -130,6 +130,8 @@ try { await cleanupOrphanedDirectories(db) logger.info('Orphaned directory cleanup completed') + await cleanupExpiredCache() + await ensureDefaultConfigExists() await syncDefaultConfigToDisk() @@ -144,6 +146,7 @@ app.route('/api/settings', createSettingsRoutes(db)) app.route('/api/health', createHealthRoutes(db)) app.route('/api/files', createFileRoutes(db)) app.route('/api/providers', createProvidersRoutes()) +app.route('/api/tts', createTTSRoutes(db)) app.all('/api/opencode/*', async (c) => { const request = c.req.raw diff --git a/backend/src/routes/tts.ts b/backend/src/routes/tts.ts new file mode 100644 index 00000000..4197afd3 --- /dev/null +++ b/backend/src/routes/tts.ts @@ -0,0 +1,175 @@ +import { Hono } from 'hono' +import { z } from 'zod' +import { Database } from 'bun:sqlite' +import { createHash } from 'crypto' +import { mkdir, readFile, writeFile, readdir, stat, unlink } from 'fs/promises' +import { join } from 'path' +import { SettingsService } from '../services/settings' +import { logger } from '../utils/logger' +import { getWorkspacePath } from '@opencode-webui/shared' + +const TTS_CACHE_DIR = join(getWorkspacePath(), 'cache', 'tts') +const CACHE_TTL_MS = 24 * 60 * 60 * 1000 + +const TTSRequestSchema = z.object({ + text: z.string().min(1).max(4096), +}) + +function generateCacheKey(text: string, voice: string, model: string, speed: number): string { + const hash = createHash('sha256') + hash.update(`${text}|${voice}|${model}|${speed}`) + return hash.digest('hex') +} + +async function ensureCacheDir(): Promise { + await mkdir(TTS_CACHE_DIR, { recursive: true }) +} + +async function getCachedAudio(cacheKey: string): Promise { + try { + const filePath = join(TTS_CACHE_DIR, `${cacheKey}.mp3`) + const fileStat = await stat(filePath) + + if (Date.now() - fileStat.mtimeMs > CACHE_TTL_MS) { + await unlink(filePath) + return null + } + + return await readFile(filePath) + } catch { + return null + } +} + +async function cacheAudio(cacheKey: string, audioData: Buffer): Promise { + const filePath = join(TTS_CACHE_DIR, `${cacheKey}.mp3`) + await writeFile(filePath, audioData) +} + +export async function cleanupExpiredCache(): Promise { + try { + await ensureCacheDir() + const files = await readdir(TTS_CACHE_DIR) + let cleanedCount = 0 + + for (const file of files) { + if (!file.endsWith('.mp3')) continue + + const filePath = join(TTS_CACHE_DIR, file) + try { + const fileStat = await stat(filePath) + if (Date.now() - fileStat.mtimeMs > CACHE_TTL_MS) { + await unlink(filePath) + cleanedCount++ + } + } catch { + continue + } + } + + if (cleanedCount > 0) { + logger.info(`TTS cache cleanup: removed ${cleanedCount} expired files`) + } + + return cleanedCount + } catch (error) { + logger.error('TTS cache cleanup failed:', error) + return 0 + } +} + +export function createTTSRoutes(db: Database) { + const app = new Hono() + + app.post('/synthesize', async (c) => { + try { + const body = await c.req.json() + const { text } = TTSRequestSchema.parse(body) + const userId = c.req.query('userId') || 'default' + + const settingsService = new SettingsService(db) + const settings = settingsService.getSettings(userId) + const ttsConfig = settings.preferences.tts + + if (!ttsConfig?.enabled) { + return c.json({ error: 'TTS is not enabled' }, 400) + } + + if (!ttsConfig.apiKey) { + return c.json({ error: 'TTS API key is not configured' }, 400) + } + + const { endpoint, apiKey, voice, model, speed } = ttsConfig + const cacheKey = generateCacheKey(text, voice, model, speed) + + await ensureCacheDir() + + const cachedAudio = await getCachedAudio(cacheKey) + if (cachedAudio) { + logger.info(`TTS cache hit: ${cacheKey.substring(0, 8)}...`) + return new Response(cachedAudio, { + headers: { + 'Content-Type': 'audio/mpeg', + 'X-Cache': 'HIT', + }, + }) + } + + logger.info(`TTS cache miss, calling API: ${cacheKey.substring(0, 8)}...`) + + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Authorization': `Bearer ${apiKey}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + model, + voice, + input: text, + speed, + response_format: 'mp3', + }), + }) + + if (!response.ok) { + const errorText = await response.text() + logger.error(`TTS API error: ${response.status} - ${errorText}`) + const status = response.status >= 400 && response.status < 600 ? response.status as 400 | 500 : 500 + return c.json({ error: 'TTS API request failed', details: errorText }, status) + } + + const audioBuffer = Buffer.from(await response.arrayBuffer()) + + await cacheAudio(cacheKey, audioBuffer) + logger.info(`TTS audio cached: ${cacheKey.substring(0, 8)}...`) + + return new Response(audioBuffer, { + headers: { + 'Content-Type': 'audio/mpeg', + 'X-Cache': 'MISS', + }, + }) + } catch (error) { + logger.error('TTS synthesis failed:', error) + if (error instanceof z.ZodError) { + return c.json({ error: 'Invalid request', details: error.issues }, 400) + } + return c.json({ error: 'TTS synthesis failed' }, 500) + } + }) + + app.get('/status', async (c) => { + const userId = c.req.query('userId') || 'default' + const settingsService = new SettingsService(db) + const settings = settingsService.getSettings(userId) + const ttsConfig = settings.preferences.tts + + return c.json({ + enabled: ttsConfig?.enabled || false, + configured: !!(ttsConfig?.apiKey), + }) + }) + + return app +} diff --git a/frontend/package.json b/frontend/package.json index 410a8570..23dd34b4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -15,6 +15,7 @@ "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-label": "^2.1.7", "@radix-ui/react-select": "^2.2.6", + "@radix-ui/react-slider": "^1.3.6", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-switch": "^1.2.6", "@radix-ui/react-tabs": "^1.1.13", diff --git a/frontend/src/api/types/settings.ts b/frontend/src/api/types/settings.ts index 05f80b0e..6e3dcfaf 100644 --- a/frontend/src/api/types/settings.ts +++ b/frontend/src/api/types/settings.ts @@ -4,6 +4,24 @@ export interface CustomCommand { promptTemplate: string } +export interface TTSConfig { + enabled: boolean + endpoint: string + apiKey: string + voice: string + model: string + speed: number +} + +export const DEFAULT_TTS_CONFIG: TTSConfig = { + enabled: false, + endpoint: 'https://api.openai.com/v1/audio/speech', + apiKey: '', + voice: 'alloy', + model: 'tts-1', + speed: 1.0, +} + export interface CustomAgent { name: string description: string @@ -22,6 +40,7 @@ export interface UserPreferences { customCommands: CustomCommand[] customAgents: CustomAgent[] gitToken?: string + tts?: TTSConfig } export interface SettingsResponse { @@ -87,4 +106,5 @@ export const DEFAULT_USER_PREFERENCES: UserPreferences = { customCommands: [], customAgents: [], gitToken: undefined, + tts: DEFAULT_TTS_CONFIG, } diff --git a/frontend/src/components/message/MessagePart.tsx b/frontend/src/components/message/MessagePart.tsx index b7d6873e..7429e4e8 100644 --- a/frontend/src/components/message/MessagePart.tsx +++ b/frontend/src/components/message/MessagePart.tsx @@ -1,9 +1,10 @@ import { memo } from 'react' import type { components } from '@/api/opencode-types' -import { Copy } from 'lucide-react' +import { Copy, Volume2, Square, Loader2 } from 'lucide-react' import { TextPart } from './TextPart' import { PatchPart } from './PatchPart' import { ToolCallPart } from './ToolCallPart' +import { useTTS } from '@/hooks/useTTS' type Part = components['schemas']['Part'] @@ -13,6 +14,7 @@ interface MessagePartProps { allParts?: Part[] partIndex?: number onFileClick?: (filePath: string, lineNumber?: number) => void + messageTextContent?: string } function getCopyableContent(part: Part, allParts?: Part[]): string { @@ -74,9 +76,49 @@ function CopyButton({ content, title, className = "" }: { content: string; title ) } +interface TTSButtonProps { + content: string + className?: string +} + +export function TTSButton({ content, className = "" }: TTSButtonProps) { + const { speak, stop, isEnabled, isPlaying, isLoading, currentText } = useTTS() + + if (!isEnabled || !content.trim()) { + return null + } + + const isThisPlaying = (isPlaying || isLoading) && currentText === content + + const handleClick = () => { + if (isThisPlaying) { + stop() + } else { + speak(content) + } + } + + return ( + + ) +} -export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick }: MessagePartProps) { + +export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, messageTextContent }: MessagePartProps) { const copyableContent = getCopyableContent(part, allParts) switch (part.type) { @@ -120,6 +162,7 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
${part.cost.toFixed(4)} • {part.tokens.input + part.tokens.output} tokens + {messageTextContent && }
) case 'file': diff --git a/frontend/src/components/message/MessageThread.tsx b/frontend/src/components/message/MessageThread.tsx index 392b890a..d0aff10a 100644 --- a/frontend/src/components/message/MessageThread.tsx +++ b/frontend/src/components/message/MessageThread.tsx @@ -4,6 +4,14 @@ import { useSettings } from '@/hooks/useSettings' import { MessagePart } from './MessagePart' import type { MessageWithParts } from '@/api/types' +function getMessageTextContent(msg: MessageWithParts): string { + return msg.parts + .filter(p => p.type === 'text') + .map(p => p.text || '') + .join('\n\n') + .trim() +} + interface MessageThreadProps { opcodeUrl: string sessionID: string @@ -189,6 +197,7 @@ export const MessageThread = memo(function MessageThread({ opcodeUrl, sessionID, allParts={msg.parts} partIndex={index} onFileClick={onFileClick} + messageTextContent={msg.info.role === 'assistant' ? getMessageTextContent(msg) : undefined} /> ))} diff --git a/frontend/src/components/settings/GeneralSettings.tsx b/frontend/src/components/settings/GeneralSettings.tsx index bbfeb184..984db30d 100644 --- a/frontend/src/components/settings/GeneralSettings.tsx +++ b/frontend/src/components/settings/GeneralSettings.tsx @@ -1,12 +1,22 @@ +import { useState, useEffect } from 'react' import { useSettings } from '@/hooks/useSettings' import { Loader2 } from 'lucide-react' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Switch } from '@/components/ui/switch' import { Input } from '@/components/ui/input' +import { TTSSettings } from './TTSSettings' export function GeneralSettings() { const { preferences, isLoading, updateSettings, isUpdating } = useSettings() + + const [gitToken, setGitToken] = useState('') + + useEffect(() => { + if (preferences) { + setGitToken(preferences.gitToken || '') + } + }, [preferences]) if (isLoading) { return ( @@ -108,8 +118,9 @@ export function GeneralSettings() { id="gitToken" type="password" placeholder="ghp_..." - value={preferences?.gitToken || ''} - onChange={(e) => updateSettings({ gitToken: e.target.value })} + value={gitToken} + onChange={(e) => setGitToken(e.target.value)} + onBlur={() => updateSettings({ gitToken })} className="bg-background border-border text-foreground placeholder:text-muted-foreground" />

@@ -124,6 +135,10 @@ export function GeneralSettings() { )} + +

+ +
) } diff --git a/frontend/src/components/settings/TTSSettings.tsx b/frontend/src/components/settings/TTSSettings.tsx new file mode 100644 index 00000000..7d507e20 --- /dev/null +++ b/frontend/src/components/settings/TTSSettings.tsx @@ -0,0 +1,317 @@ +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import { zodResolver } from '@hookform/resolvers/zod' +import { z } from 'zod' +import { useSettings } from '@/hooks/useSettings' +import { useTTS } from '@/hooks/useTTS' +import { Loader2, Volume2, Square, CheckCircle, XCircle } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { Switch } from '@/components/ui/switch' +import { Slider } from '@/components/ui/slider' +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' +import { DEFAULT_TTS_CONFIG } from '@/api/types/settings' + +const TEST_PHRASE = 'Text to speech is working correctly.' + +const ttsFormSchema = z.object({ + enabled: z.boolean(), + endpoint: z.string().url('Must be a valid URL').min(1, 'Endpoint is required'), + apiKey: z.string().min(1, 'API key is required when TTS is enabled').or(z.literal('')), + voice: z.string().min(1, 'Voice is required'), + model: z.string().min(1, 'Model is required'), + speed: z.number().min(0.25).max(4.0), +}).refine((data) => { + if (data.enabled && !data.apiKey) { + return false + } + return true +}, { + message: 'API key is required when TTS is enabled', + path: ['apiKey'], +}) + +type TTSFormValues = z.infer + +export function TTSSettings() { + const { preferences, isLoading, updateSettings, isUpdating } = useSettings() + const { speak, stop, isPlaying, isLoading: isTTSLoading, error: ttsError } = useTTS() + const [testStatus, setTestStatus] = useState<'idle' | 'success' | 'error'>('idle') + + const form = useForm({ + resolver: zodResolver(ttsFormSchema), + defaultValues: DEFAULT_TTS_CONFIG, + }) + + const { reset, formState: { isDirty, isValid } } = form + const watchEnabled = form.watch('enabled') + const watchApiKey = form.watch('apiKey') + + const canTest = watchEnabled && watchApiKey && !isDirty + + useEffect(() => { + if (preferences?.tts) { + reset({ + enabled: preferences.tts.enabled ?? DEFAULT_TTS_CONFIG.enabled, + endpoint: preferences.tts.endpoint ?? DEFAULT_TTS_CONFIG.endpoint, + apiKey: preferences.tts.apiKey ?? DEFAULT_TTS_CONFIG.apiKey, + voice: preferences.tts.voice ?? DEFAULT_TTS_CONFIG.voice, + model: preferences.tts.model ?? DEFAULT_TTS_CONFIG.model, + speed: preferences.tts.speed ?? DEFAULT_TTS_CONFIG.speed, + }) + } + }, [preferences?.tts, reset]) + + const onSubmit = (data: TTSFormValues) => { + updateSettings({ tts: data }) + } + + const handleTest = async () => { + setTestStatus('idle') + try { + await speak(TEST_PHRASE) + setTestStatus('success') + setTimeout(() => setTestStatus('idle'), 3000) + } catch { + setTestStatus('error') + } + } + + const handleStopTest = () => { + stop() + setTestStatus('idle') + } + + if (isLoading) { + return ( +
+ +
+ ) + } + + return ( +
+
+

Text-to-Speech

+ +
+ +
+ + ( + +
+ Enable TTS + + Allow text-to-speech playback for messages + +
+ + + +
+ )} + /> + + {watchEnabled && ( + <> + ( + + TTS Endpoint + + + + + OpenAI-compatible TTS API endpoint + + + + )} + /> + + ( + + API Key + + + + + API key for the TTS service + + + + )} + /> + + ( + + Voice + + + Voice for text-to-speech output + + + + )} + /> + + ( + + Model + + + TTS model quality + + + + )} + /> + + ( + +
+ Speed + + {field.value.toFixed(2)}x + +
+ + field.onChange(value)} + className="w-full" + /> + + + Playback speed (0.25x to 4.0x) + + +
+ )} + /> + +
+
+
Test TTS
+

+ {isDirty + ? 'Save changes before testing' + : 'Verify your TTS configuration works'} +

+ {ttsError && ( +

+ + {ttsError} +

+ )} + {testStatus === 'success' && ( +

+ + TTS is working +

+ )} +
+ +
+ + )} + + +
+ ) +} diff --git a/frontend/src/components/ui/slider.tsx b/frontend/src/components/ui/slider.tsx new file mode 100644 index 00000000..875dd0ea --- /dev/null +++ b/frontend/src/components/ui/slider.tsx @@ -0,0 +1,26 @@ +import * as React from "react" +import * as SliderPrimitive from "@radix-ui/react-slider" + +import { cn } from "@/lib/utils" + +const Slider = React.forwardRef< + React.ComponentRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + + + + +)) +Slider.displayName = SliderPrimitive.Root.displayName + +export { Slider } diff --git a/frontend/src/hooks/useTTS.ts b/frontend/src/hooks/useTTS.ts new file mode 100644 index 00000000..73a04536 --- /dev/null +++ b/frontend/src/hooks/useTTS.ts @@ -0,0 +1,192 @@ +import { useState, useRef, useCallback, useEffect } from 'react' +import { useSettings } from './useSettings' +import { API_BASE_URL } from '@/config' + +const TTS_CACHE_NAME = 'tts-audio-cache' +const CACHE_TTL_MS = 24 * 60 * 60 * 1000 + +async function generateCacheKey(text: string, voice: string, model: string, speed: number): Promise { + const data = `${text}|${voice}|${model}|${speed}` + const encoder = new TextEncoder() + const dataBuffer = encoder.encode(data) + const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer) + const hashArray = Array.from(new Uint8Array(hashBuffer)) + return hashArray.map(b => b.toString(16).padStart(2, '0')).join('') +} + +async function getCachedAudio(cacheKey: string): Promise { + try { + const cache = await caches.open(TTS_CACHE_NAME) + const response = await cache.match(cacheKey) + + if (!response) return null + + const cachedAt = response.headers.get('x-cached-at') + if (cachedAt && Date.now() - parseInt(cachedAt) > CACHE_TTL_MS) { + await cache.delete(cacheKey) + return null + } + + return await response.blob() + } catch { + return null + } +} + +async function cacheAudio(cacheKey: string, blob: Blob): Promise { + try { + const cache = await caches.open(TTS_CACHE_NAME) + const headers = new Headers({ + 'Content-Type': 'audio/mpeg', + 'x-cached-at': Date.now().toString(), + }) + const response = new Response(blob, { headers }) + await cache.put(cacheKey, response) + } catch { + // Cache API not available, continue without caching + } +} + +export type TTSState = 'idle' | 'loading' | 'playing' | 'paused' | 'error' + +export function useTTS() { + const { preferences } = useSettings() + const [state, setState] = useState('idle') + const [error, setError] = useState(null) + const [currentText, setCurrentText] = useState(null) + const audioRef = useRef(null) + const abortControllerRef = useRef(null) + + const ttsConfig = preferences?.tts + const isEnabled = ttsConfig?.enabled && ttsConfig?.apiKey + + const cleanup = useCallback(() => { + if (audioRef.current) { + audioRef.current.pause() + audioRef.current.src = '' + audioRef.current = null + } + if (abortControllerRef.current) { + abortControllerRef.current.abort() + abortControllerRef.current = null + } + }, []) + + useEffect(() => { + return () => cleanup() + }, [cleanup]) + + const speak = useCallback(async (text: string) => { + if (!isEnabled || !ttsConfig) { + setError('TTS is not configured') + setState('error') + return + } + + cleanup() + setError(null) + setCurrentText(text) + setState('loading') + + try { + const { voice, model, speed } = ttsConfig + const cacheKey = await generateCacheKey(text, voice, model, speed) + + let audioBlob = await getCachedAudio(cacheKey) + + if (!audioBlob) { + abortControllerRef.current = new AbortController() + + const response = await fetch(`${API_BASE_URL}/api/tts/synthesize`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ text }), + signal: abortControllerRef.current.signal, + }) + + if (!response.ok) { + const errorData = await response.json().catch(() => ({})) + throw new Error(errorData.error || 'TTS request failed') + } + + audioBlob = await response.blob() + await cacheAudio(cacheKey, audioBlob) + } + + const audioUrl = URL.createObjectURL(audioBlob) + const audio = new Audio(audioUrl) + audioRef.current = audio + + audio.onplay = () => setState('playing') + audio.onpause = () => { + if (audio.currentTime < audio.duration) { + setState('paused') + } + } + audio.onended = () => { + setState('idle') + setCurrentText(null) + URL.revokeObjectURL(audioUrl) + } + audio.onerror = () => { + setError('Audio playback failed') + setState('error') + URL.revokeObjectURL(audioUrl) + } + + await audio.play() + } catch (err) { + if (err instanceof Error && err.name === 'AbortError') { + setState('idle') + return + } + setError(err instanceof Error ? err.message : 'TTS failed') + setState('error') + } + }, [isEnabled, ttsConfig, cleanup]) + + const stop = useCallback(() => { + cleanup() + setState('idle') + setCurrentText(null) + setError(null) + }, [cleanup]) + + const pause = useCallback(() => { + if (audioRef.current && state === 'playing') { + audioRef.current.pause() + } + }, [state]) + + const resume = useCallback(() => { + if (audioRef.current && state === 'paused') { + audioRef.current.play() + } + }, [state]) + + const toggle = useCallback(() => { + if (state === 'playing') { + pause() + } else if (state === 'paused') { + resume() + } + }, [state, pause, resume]) + + return { + speak, + stop, + pause, + resume, + toggle, + state, + error, + currentText, + isEnabled, + isPlaying: state === 'playing', + isLoading: state === 'loading', + isPaused: state === 'paused', + isIdle: state === 'idle', + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6dc21fe1..5c4c58e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -73,6 +73,9 @@ importers: '@radix-ui/react-select': specifier: ^2.2.6 version: 2.2.6(@types/react-dom@19.2.3)(@types/react@19.2.7)(react-dom@19.2.0)(react@19.2.0) + '@radix-ui/react-slider': + specifier: ^1.3.6 + version: 1.3.6(@types/react-dom@19.2.3)(@types/react@19.2.7)(react-dom@19.2.0)(react@19.2.0) '@radix-ui/react-slot': specifier: ^1.2.3 version: 1.2.4(@types/react@19.2.7)(react@19.2.0) @@ -1248,6 +1251,36 @@ packages: react-remove-scroll: 2.7.1(@types/react@19.2.7)(react@19.2.0) dev: false + /@radix-ui/react-slider@1.3.6(@types/react-dom@19.2.3)(@types/react@19.2.7)(react-dom@19.2.0)(react@19.2.0): + resolution: {integrity: sha512-JPYb1GuM1bxfjMRlNLE+BcmBC8onfCi60Blk7OBqi2MLTFdS+8401U4uFjnwkOr49BLmXxLC6JHkvAsx5OJvHw==} + peerDependencies: + '@types/react': '*' + '@types/react-dom': '*' + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + '@types/react': + optional: true + '@types/react-dom': + optional: true + dependencies: + '@radix-ui/number': 1.1.1 + '@radix-ui/primitive': 1.1.3 + '@radix-ui/react-collection': 1.1.7(@types/react-dom@19.2.3)(@types/react@19.2.7)(react-dom@19.2.0)(react@19.2.0) + '@radix-ui/react-compose-refs': 1.1.2(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-context': 1.1.2(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-direction': 1.1.1(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-primitive': 2.1.3(@types/react-dom@19.2.3)(@types/react@19.2.7)(react-dom@19.2.0)(react@19.2.0) + '@radix-ui/react-use-controllable-state': 1.2.2(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-use-layout-effect': 1.1.1(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-use-previous': 1.1.1(@types/react@19.2.7)(react@19.2.0) + '@radix-ui/react-use-size': 1.1.1(@types/react@19.2.7)(react@19.2.0) + '@types/react': 19.2.7 + '@types/react-dom': 19.2.3(@types/react@19.2.7) + react: 19.2.0 + react-dom: 19.2.0(react@19.2.0) + dev: false + /@radix-ui/react-slot@1.2.3(@types/react@19.2.7)(react@19.2.0): resolution: {integrity: sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==} peerDependencies: diff --git a/shared/src/schemas/settings.ts b/shared/src/schemas/settings.ts index a7822e1c..a1864f10 100644 --- a/shared/src/schemas/settings.ts +++ b/shared/src/schemas/settings.ts @@ -6,6 +6,15 @@ export const CustomCommandSchema = z.object({ promptTemplate: z.string(), }); +export const TTSConfigSchema = z.object({ + enabled: z.boolean(), + endpoint: z.string(), + apiKey: z.string(), + voice: z.string(), + model: z.string(), + speed: z.number().min(0.25).max(4.0), +}); + export const CustomAgentSchema = z.object({ name: z.string(), description: z.string(), @@ -35,8 +44,18 @@ export const UserPreferencesSchema = z.object({ customCommands: z.array(CustomCommandSchema), customAgents: z.array(CustomAgentSchema), gitToken: z.string().optional(), + tts: TTSConfigSchema.optional(), }); +export const DEFAULT_TTS_CONFIG = { + enabled: false, + endpoint: "https://api.openai.com/v1/audio/speech", + apiKey: "", + voice: "alloy", + model: "tts-1", + speed: 1.0, +}; + export const DEFAULT_USER_PREFERENCES = { theme: "dark" as const, mode: "build" as const, @@ -47,6 +66,7 @@ export const DEFAULT_USER_PREFERENCES = { customCommands: [], customAgents: [], gitToken: undefined, + tts: DEFAULT_TTS_CONFIG, }; export const SettingsResponseSchema = z.object({