import React, { useState, useRef } from 'react' import { Play, Pause, Volume2 } from 'lucide-react' interface AudioPlayerProps { text: string className?: string autoPlay?: boolean voice?: 'us' | 'uk' speed?: number } export default function AudioPlayer({ text, className = '', autoPlay = false, voice = 'us', speed = 1.0 }: AudioPlayerProps) { const [isPlaying, setIsPlaying] = useState(false) const [isLoading, setIsLoading] = useState(false) const audioRef = useRef(null) const handlePlay = async () => { if (!text.trim()) return try { setIsLoading(true) // 簡單的TTS模擬 - 實際應該調用TTS API const utterance = new SpeechSynthesisUtterance(text) utterance.lang = voice === 'us' ? 'en-US' : 'en-GB' utterance.rate = speed utterance.onstart = () => { setIsPlaying(true) setIsLoading(false) } utterance.onend = () => { setIsPlaying(false) } utterance.onerror = () => { setIsPlaying(false) setIsLoading(false) } window.speechSynthesis.speak(utterance) } catch (error) { console.error('TTS Error:', error) setIsLoading(false) setIsPlaying(false) } } const handleStop = () => { window.speechSynthesis.cancel() setIsPlaying(false) } return ( ) }