generated from USNightOwl/reactjs-vite-tailwindcss-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
150 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
import "regenerator-runtime/runtime"; | ||
import SpeechRecognition, { useSpeechRecognition } from "react-speech-recognition"; | ||
import { Button, Heading, HStack, Textarea, VStack } from "@chakra-ui/react"; | ||
import React from "react"; | ||
import { CircleStop, Mic } from "lucide-react"; | ||
import TextDiff from "./TextDiff"; | ||
|
||
const SpellCheckPage = () => { | ||
return <div>SpellCheckPage</div>; | ||
const { transcript, listening, resetTranscript, browserSupportsSpeechRecognition } = useSpeechRecognition(); | ||
const [targetTranscript, setTargetTranscript] = React.useState<string>(""); | ||
|
||
if (!browserSupportsSpeechRecognition) { | ||
return <span>Browser doesn’t support speech recognition.</span>; | ||
} | ||
|
||
const handleStartListening = () => { | ||
resetTranscript(); | ||
SpeechRecognition.startListening({ continuous: true }); | ||
}; | ||
|
||
const handleStopListening = () => { | ||
SpeechRecognition.stopListening(); | ||
}; | ||
|
||
return ( | ||
<div className="mb-5"> | ||
<VStack marginTop={"10px"} marginBottom={"20px"}> | ||
<Heading size="lg" textTransform="uppercase"> | ||
Spelling check | ||
</Heading> | ||
</VStack> | ||
<HStack flexWrap={"wrap"} gap={"30px"} alignItems={"flex-start"}> | ||
<VStack w={{ base: "100%", md: "50%" }} gap={"15px"} alignItems={"flex-start"}> | ||
<VStack gap={"10px"} alignItems={"flex-start"} w="full"> | ||
<Heading size="lg">Target transcript</Heading> | ||
<Textarea | ||
width={"full"} | ||
rows={4} | ||
minH={"100px"} | ||
variant={"outline"} | ||
value={targetTranscript} | ||
onChange={(e) => setTargetTranscript(e.target.value)} | ||
/> | ||
</VStack> | ||
<VStack gap={"10px"} alignItems={"flex-start"} w="full"> | ||
<Heading size="lg">Speech to text</Heading> | ||
<Textarea width={"full"} rows={4} minH={"200px"} variant={"outline"} isReadOnly value={transcript} /> | ||
{!listening ? ( | ||
<Button | ||
colorScheme="blue" | ||
textTransform="uppercase" | ||
rightIcon={<Mic className="w-5 h-5" />} | ||
onClick={handleStartListening} | ||
> | ||
start recording | ||
</Button> | ||
) : ( | ||
<Button | ||
colorScheme="blue" | ||
textTransform="uppercase" | ||
rightIcon={<CircleStop className="w-5 h-5" />} | ||
onClick={handleStopListening} | ||
> | ||
stop recording | ||
</Button> | ||
)} | ||
</VStack> | ||
</VStack> | ||
<div className="flex-1"> | ||
<VStack gap={"10px"} alignItems={"flex-start"} w="full"> | ||
<Heading size="lg">Comparision</Heading> | ||
<TextDiff text1={targetTranscript.toLowerCase()} text2={transcript.toLowerCase()} /> | ||
</VStack> | ||
</div> | ||
</HStack> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SpellCheckPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import { diffChars } from "diff"; | ||
|
||
type Props = { | ||
text1: string; | ||
text2: string; | ||
}; | ||
|
||
const TextDiff = ({ text1, text2 }: Props) => { | ||
const differences = diffChars(text1, text2); | ||
const renderDifference = (part: { value: string; added?: boolean; removed?: boolean }, index: number) => { | ||
const style: React.CSSProperties = { | ||
color: part.added ? "red" : part.removed ? "red" : "green", | ||
fontSize: "25px", | ||
}; | ||
|
||
return ( | ||
<span key={index} style={style}> | ||
{part.value} | ||
</span> | ||
); | ||
}; | ||
|
||
return <div>{differences.map(renderDifference)}</div>; | ||
}; | ||
|
||
export default TextDiff; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters