UNPKG

react-native-ajora

Version:

The most complete AI agent UI for React Native

39 lines 1.49 kB
import { useEffect } from "react"; import { View, StyleSheet, Button, Alert } from "react-native"; import { useAudioRecorder, AudioModule, RecordingPresets, setAudioModeAsync, useAudioRecorderState, } from "expo-audio"; export default function App() { const audioRecorder = useAudioRecorder(RecordingPresets.HIGH_QUALITY); const recorderState = useAudioRecorderState(audioRecorder); const record = async () => { await audioRecorder.prepareToRecordAsync(); audioRecorder?.record(); }; const stopRecording = async () => { // The recording will be available on `audioRecorder.uri`. await audioRecorder?.stop(); }; useEffect(() => { (async () => { const status = await AudioModule.requestRecordingPermissionsAsync(); if (!status.granted) { Alert.alert("Permission to access microphone was denied"); } setAudioModeAsync({ playsInSilentMode: true, allowsRecording: true, }); })(); }, []); return (<View style={styles.container}> <Button title={recorderState.isRecording ? "Stop Recording" : "Start Recording"} onPress={recorderState.isRecording ? stopRecording : record}/> </View>); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", backgroundColor: "#ecf0f1", padding: 10, }, }); //# sourceMappingURL=Recording.js.map