'use client' import React, { useCallback, useState } from 'react' interface AudioButtonProps { text: string lang: 'en' | 'de' isDark: boolean size?: 'sm' | 'md' | 'lg' } export function AudioButton({ text, lang, isDark, size = 'md' }: AudioButtonProps) { const [isSpeaking, setIsSpeaking] = useState(false) const speak = useCallback(() => { if (!('speechSynthesis' in window)) return if (isSpeaking) { window.speechSynthesis.cancel() setIsSpeaking(false) return } const utterance = new SpeechSynthesisUtterance(text) utterance.lang = lang === 'de' ? 'de-DE' : 'en-GB' utterance.rate = 0.9 utterance.pitch = 1.0 // Try to find a good voice const voices = window.speechSynthesis.getVoices() const preferred = voices.find((v) => v.lang.startsWith(lang === 'de' ? 'de' : 'en') && v.localService ) || voices.find((v) => v.lang.startsWith(lang === 'de' ? 'de' : 'en')) if (preferred) utterance.voice = preferred utterance.onend = () => setIsSpeaking(false) utterance.onerror = () => setIsSpeaking(false) setIsSpeaking(true) window.speechSynthesis.speak(utterance) }, [text, lang, isSpeaking]) const sizeClasses = { sm: 'w-7 h-7', md: 'w-9 h-9', lg: 'w-11 h-11', } const iconSizes = { sm: 'w-3.5 h-3.5', md: 'w-4 h-4', lg: 'w-5 h-5', } return ( ) }