|
| 1 | +import { useState, useEffect } from "react"; |
| 2 | +import useSpeech from "use-speech18"; |
| 3 | + |
| 4 | +function App() { |
| 5 | + const [index, setIndex] = useState(0); |
| 6 | + const [speaktext, setSpeaktext] = useState( |
| 7 | + `` |
| 8 | + ); |
| 9 | + const { Speak, speak_utils } = useSpeech(); |
| 10 | + |
| 11 | + useEffect(() => { |
| 12 | + speak_utils.setVoice( |
| 13 | + speak_utils.Voices[index % speak_utils.Voices.length].name |
| 14 | + ); |
| 15 | + }, [index]); |
| 16 | + |
| 17 | + return ( |
| 18 | + <div className="app"> |
| 19 | + <h3 className="text-3xl font-bold mb-8"> |
| 20 | + Current Voice: {speak_utils.selectedVoice?.name} |
| 21 | + </h3> |
| 22 | + <div className="flex items-center justify-center"> |
| 23 | + <div |
| 24 | + className="inline-flex shadow-md hover:shadow-lg focus:shadow-lg" |
| 25 | + role="group" |
| 26 | + > |
| 27 | + <button |
| 28 | + type="button" |
| 29 | + className="rounded-l inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase hover:bg-blue-700 focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out" |
| 30 | + onClick={() => Speak(speaktext)} |
| 31 | + > |
| 32 | + Speak |
| 33 | + </button> |
| 34 | + <button |
| 35 | + type="button" |
| 36 | + className=" inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase hover:bg-blue-700 focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out" |
| 37 | + onClick={() => setIndex((prev) => prev + 1)} |
| 38 | + > |
| 39 | + Next Voice |
| 40 | + </button> |
| 41 | + <button |
| 42 | + type="button" |
| 43 | + className=" rounded-r inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase hover:bg-blue-700 focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out" |
| 44 | + onClick={() => setIndex((prev) => prev - 1)} |
| 45 | + > |
| 46 | + Prev Voice |
| 47 | + </button> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + <div className="flex justify-center"> |
| 51 | + <div className="mb-3 xl:w-96"> |
| 52 | + <label |
| 53 | + for="exampleFormControlInput1" |
| 54 | + className="form-label inline-block mb-2 text-gray-700" |
| 55 | + > |
| 56 | + Please enter the text you want the computer to speak! |
| 57 | + </label> |
| 58 | + <input |
| 59 | + type="text" |
| 60 | + className=" |
| 61 | + form-control |
| 62 | + block |
| 63 | + w-full |
| 64 | + px-3 |
| 65 | + py-1.5 |
| 66 | + text-base |
| 67 | + font-normal |
| 68 | + text-gray-700 |
| 69 | + bg-white bg-clip-padding |
| 70 | + border border-solid border-gray-300 |
| 71 | + rounded |
| 72 | + transition |
| 73 | + ease-in-out |
| 74 | + m-0 |
| 75 | + focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none |
| 76 | + " |
| 77 | + onChange={(event) => setSpeaktext(`${event.target.value}`)} |
| 78 | + id="exampleFormControlInput1" |
| 79 | + placeholder="Enter text" |
| 80 | + /> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + ); |
| 85 | +} |
| 86 | + |
| 87 | +export default App; |
0 commit comments