File size: 703 Bytes
3dee94a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState } from 'react'

export default function VoiceButton({ onResult }) {
  const [listening, setListening] = useState(false)

  const startListening = () => {
    const recognition = new window.webkitSpeechRecognition()
    recognition.lang = 'pt-BR'
    recognition.onresult = e => {
      const transcript = e.results[0][0].transcript
      onResult(transcript)
    }
    recognition.onend = () => setListening(false)
    recognition.start()
    setListening(true)
  }

  return (
    <button

      className={`px-3 py-2 rounded ${listening ? 'bg-red-500' : 'bg-green-600'} text-white`}

      onClick={startListening}

    >

      🎙️ Voz

    </button>
  )
}