File size: 1,379 Bytes
77fcf1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { useState } from 'react'
import { FaMicrophone, FaStop } from 'react-icons/fa'

const VoiceControl = ({ language, onCommand }) => {
  const [isListening, setIsListening] = useState(false)

  const toggleListening = () => {
    setIsListening(!isListening)
    // Here you would integrate with Web Speech API
    if (!isListening && onCommand) {
      onCommand(language === 'fa' 
        ? 'دستور صوتی دریافت شد: ساخت یک پروژه React جدید' 
        : 'Voice command received: Create a new React project')
    }
  }

  return (
    <div className="flex items-center justify-center p-4">
      <button
        onClick={toggleListening}
        className={`flex items-center justify-center w-16 h-16 rounded-full text-white text-2xl ${isListening ? 'bg-red-500 animate-pulse' : 'bg-blue-600'}`}
      >
        {isListening ? <FaStop /> : <FaMicrophone />}
      </button>
      <div className="mr-4">
        <p className="font-bold">
          {language === 'fa' ? 'کنترل صوتی' : 'Voice Control'}
        </p>
        <p className="text-sm text-gray-600">
          {isListening 
            ? (language === 'fa' ? 'در حال گوش دادن...' : 'Listening...') 
            : (language === 'fa' ? 'برای صحبت کلیک کنید' : 'Click to speak')}
        </p>
      </div>
    </div>
  )
}

export default VoiceControl