Skip to content

Commit 2186ebc

Browse files
committed
user would be able to switch camera, mute and unmute
1 parent 18f3cd2 commit 2186ebc

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

src/App.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default function App(){
1818
window.onresize=function(){
1919
screen.width>1080?setIsSupported(false):setVideoConstraints({height:720, width:screen.width, facingMode:"environment"})
2020
}
21+
22+
function changeVideoConstraints(){
23+
setVideoConstraints({height:720, width:screen.width, facingMode:"user"})
24+
}
2125

2226
useEffect(()=>{
2327
screen.width>1080?setIsSupported(false):setVideoConstraints({height:720, width:screen.width, facingMode:"environment"})
@@ -26,7 +30,7 @@ export default function App(){
2630
<>
2731
{isSupported?(
2832
<BrowserRouter>
29-
<GlobalContext.Provider value={{ videoConstraints, API_URL }}>
33+
<GlobalContext.Provider value={{ videoConstraints, changeVideoConstraints, API_URL }}>
3034
<Routes>
3135
<Route path="/" element={<MainPage/>}/>
3236
<Route path="/search" element={<SearchPage/>}/>

src/components/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export const drawRect = (detections:any, ctx:any) =>{
2222

2323
// Set styling
2424
const color = Math.floor(Math.random()*16777215).toString(16);
25-
ctx.lineWidth = 20;
25+
ctx.lineWidth = 2;
2626
ctx.strokeStyle = '#' + color
27-
ctx.font = '18px Arial';
27+
ctx.font = '20px Arial';
2828

2929
// Draw rectangles and text
3030
ctx.beginPath();

src/context/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type ContextType={
66
width?:number,
77
facingMode:string
88
},
9+
changeVideoConstraints:any,
910
API_URL:string
1011
}
1112

@@ -15,5 +16,6 @@ export const GlobalContext=createContext<ContextType>({
1516
height: screen.height,
1617
facingMode: "user"
1718
},
19+
changeVideoConstraints:()=>{},
1820
API_URL:""
1921
})

src/pages/MainPage.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import * as cocossd from "@tensorflow-models/coco-ssd";
99
import { drawRect } from "../components/utilities";
1010
import { GlobalContext } from "../context";
1111
import { IoSearch } from "react-icons/io5";
12+
import { IoCameraReverseSharp } from "react-icons/io5";
1213

1314
export default function MainPage() {
1415
const navigate=useNavigate();
15-
const { videoConstraints }=useContext(GlobalContext);
16+
const { videoConstraints, changeVideoConstraints }=useContext(GlobalContext);
1617
const [isLoading, setIsLoading]=useState(true)
1718
const [object,setObject]=useState<any>([]);
1819
const webcamRef:any = useRef(null);
@@ -87,6 +88,18 @@ export default function MainPage() {
8788
):(
8889
<div className="text-center h-screen">
8990
<header className="h-screen flex flex-col items-center justify-center text-white bg-[#14161a]">
91+
<div className="fixed h-[0px] z-10 top-0 left-0 right-0">
92+
<div className="flex bg-none text-white items-center justify-between m-[20px]">
93+
{/*<Link to="/">
94+
<FaChevronLeft className="w-[22px] h-[20px]"/>
95+
</Link>
96+
<p>Search</p>*/}
97+
<button onClick={changeVideoConstraints} className="ml-auto">
98+
<IoCameraReverseSharp className="w-[30px] h-[30px]"/>
99+
</button>
100+
</div>
101+
</div>
102+
90103
<Webcam
91104
ref={webcamRef}
92105
audio={false}

src/pages/SearchPage.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { FaChevronLeft } from "react-icons/fa";
44
import { FiMoreHorizontal } from "react-icons/fi";
55
import { GlobalContext } from "../context";
66
import { FaAngellist } from "react-icons/fa6";
7-
import { HiMiniSpeakerWave } from "react-icons/hi2";
7+
import { HiMiniSpeakerWave, HiMiniSpeakerXMark } from "react-icons/hi2";
88

99
export default function SearchPage(){
1010
const { videoConstraints, API_URL }=useContext(GlobalContext);
11+
const [isMuted,setIsMuted]=useState(true)
1112
const [results,setResults]=useState<any>(<></>)
1213
const [error,setError]=useState("")
1314
const [isLoading,setIsLoading]=useState(true)
@@ -42,6 +43,7 @@ export default function SearchPage(){
4243
}
4344

4445
useEffect(()=>{
46+
window.speechSynthesis.cancel()
4547
getResults()
4648
},[])
4749
return(
@@ -70,7 +72,25 @@ export default function SearchPage(){
7072
<FaAngellist className="w-[22px] h-[22px]"/>
7173
<p className="capitalize">{query}</p>
7274
</div>
73-
<HiMiniSpeakerWave className="w-[22px] h-[22px] ml-auto"/>
75+
{isMuted?(
76+
<HiMiniSpeakerWave onClick={()=>{
77+
setIsMuted(false)
78+
79+
// Create a new instance of SpeechSynthesisUtterance
80+
var speech = new SpeechSynthesisUtterance(results);
81+
// Set the voice, rate, pitch, and language if desired
82+
speech.lang = 'en-US'; // You can change the language
83+
speech.rate = 1; // Speed (default is 1, range: 0.1 to 10)
84+
speech.pitch = 1; // Pitch (default is 1, range: 0 to 2)
85+
// Speak the text
86+
window.speechSynthesis.speak(speech);
87+
}} className="w-[22px] h-[22px] ml-auto"/>
88+
):(
89+
<HiMiniSpeakerXMark onClick={()=>{
90+
setIsMuted(true)
91+
window.speechSynthesis.cancel()
92+
}} className="w-[22px] h-[22px] ml-auto"/>
93+
)}
7494
</div>
7595
</div>
7696
<div className="flex flex-col m-[20px] text-sm">

0 commit comments

Comments
 (0)