Skip to content

Commit

Permalink
update: wake-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinceBaghel258025 committed Sep 25, 2024
1 parent c4e4ff8 commit ecc4c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"react-intersection-observer": "9.5.2",
"react-markdown": "8.0.7",
"react-mic": "12.4.6",
"react-screen-wake-lock": "^3.0.2",
"react-syntax-highlighter": "15.5.0",
"react-textarea-autosize": "8.4.1",
"remark-gfm": "3.0.1",
Expand All @@ -120,7 +121,6 @@
"terser": "^5.33.0",
"tldraw": "2.0.2",
"typescript": "5.0.3",
"use-stay-awake": "^0.1.7",
"vaul": "0.8.0",
"zod": "3.22.4",
"zustand": "4.4.6"
Expand Down
14 changes: 10 additions & 4 deletions src/components/VadAudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useMicVAD, utils } from "@ricky0123/vad-react";
import { Microphone, StopCircle } from "@phosphor-icons/react";
import { Button } from "@/components/button";
import { cn } from "@/lib/utils";
import useStayAwake from "use-stay-awake";

import { useWakeLock } from "react-screen-wake-lock";
interface VadAudioProps {
onAudioCapture: (audioFile: File) => void;
onStartListening: () => void;
Expand All @@ -25,7 +25,13 @@ export default function VadAudio({
const audioChunks = useRef<Blob[]>([]);
const timerRef = useRef<NodeJS.Timeout | null>(null);
const startTimeRef = useRef<number | null>(null);
const device = useStayAwake();
const { isSupported, released, request, release } = useWakeLock({
onRequest: () => {},
onError: () => {
console.error("Error requesting wake lock");
},
onRelease: () => {},
});

const vad = useMicVAD({
onSpeechEnd: (audio: Float32Array) => {
Expand Down Expand Up @@ -53,7 +59,7 @@ export default function VadAudio({
const handleStartListening = useCallback(() => {
vad.start();
startTimer();
device.preventSleeping();
request();
onStartListening();
setIsListening(true);
audioChunks.current = [];
Expand All @@ -65,7 +71,7 @@ export default function VadAudio({
vad.pause();
resetDuration();
clearTimer();
device.allowSleeping();
release();
}, [vad]);

const startTimer = () => {
Expand Down

0 comments on commit ecc4c2a

Please sign in to comment.