fix(mobile): keep screen awake during dictation (#12227)
This commit is contained in:
1 parent
0150c6a53b
commit
dd9528a974
4 files changed
+28
-8
No files matched your search
@@ -93,6 +93,7 @@
|
||||
"expo-image": "~57.0.3",
|
||||
"expo-image-manipulator": "~57.0.17",
|
||||
"expo-image-picker": "~57.0.14",
|
||||
"expo-keep-awake": "~57.0.2",
|
||||
"expo-linking": "~57.0.8",
|
||||
"expo-network": "~57.0.1",
|
||||
"expo-notifications": "~57.0.15",
|
||||
|
||||
@@ -7,8 +7,9 @@ import {
|
||||
type RecordingStatus,
|
||||
} from "expo-audio";
|
||||
import { File } from "expo-file-system";
|
||||
import { activateKeepAwakeAsync, deactivateKeepAwake } from "expo-keep-awake";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
||||
import { AppState } from "react-native";
|
||||
import { useSharedValue } from "react-native-reanimated";
|
||||
|
||||
@@ -71,6 +72,8 @@ export function useVoiceInputController(input: {
|
||||
}) {
|
||||
const [state, setState] = useState<VoiceInputState>(INITIAL_STATE);
|
||||
const [elapsedSeconds, setElapsedSeconds] = useState(0);
|
||||
const keepAwakeId = useId();
|
||||
const keepAwakeSessionRef = useRef(0);
|
||||
const elapsedSecondsRef = useRef(0);
|
||||
const audioLevelsRef = useRef(Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0));
|
||||
const audioLevels = useSharedValue(audioLevelsRef.current);
|
||||
@@ -156,6 +159,18 @@ export function useVoiceInputController(input: {
|
||||
|
||||
useEffect(() => () => controller.dispose(), [controller]);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.phase !== "recording") return;
|
||||
|
||||
const tag = `voice-input:${keepAwakeId}:${++keepAwakeSessionRef.current}`;
|
||||
const activation = activateKeepAwakeAsync(tag);
|
||||
void activation.catch(() => {});
|
||||
return () => {
|
||||
// Release after activation settles, even if the recording ends immediately.
|
||||
void activation.then(() => deactivateKeepAwake(tag)).catch(() => {});
|
||||
};
|
||||
}, [keepAwakeId, state.phase]);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.phase !== "preparing" && state.phase !== "recording") return;
|
||||
|
||||
|
||||
@@ -131,7 +131,8 @@ recording started, ready for you to review and edit before sending.
|
||||
The first use may download Apple's speech model and needs a network connection.
|
||||
Later transcription works offline for that language. Recordings can be up to five
|
||||
minutes long. Canceling, leaving the screen, or an audio interruption discards the
|
||||
recording and preserves your existing draft.
|
||||
recording and preserves your existing draft. While recording, the screen stays
|
||||
awake; it can sleep normally once recording stops.
|
||||
|
||||
Transcription runs on your device. T3 Code deletes the temporary audio after
|
||||
transcription or cancellation; only the message text is sent when you submit.
|
||||
|
||||
Generated
+9
-6
Reference in new issue
Block a user