Last active
May 3, 2025 04:50
-
-
Save oovz/71b07d4beb6a85e7e3f86e65052f65fc to your computer and use it in GitHub Desktop.
Revisions
-
oovz revised this gist
May 3, 2025 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,6 @@ export default function App() { const [isLoading, setIsLoading] = useState(true); useEffect(() => { const fetchNumber = async () => { try { const voices = await Speech.getAvailableVoicesAsync(); @@ -17,12 +16,12 @@ export default function App() { console.error("Error fetching voices.length:", error); setVoicesNumber('Error'); } finally { setIsLoading(false); } }; fetchNumber(); }, []); return ( <SafeAreaView style={styles.container}> -
oovz created this gist
May 2, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ import { Text, SafeAreaView, StyleSheet, ActivityIndicator, View } from 'react-native'; import React, { useState, useEffect } from 'react'; import * as Speech from 'expo-speech'; export default function App() { const [voicesNumber, setVoicesNumber] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { // Define an async function inside useEffect const fetchNumber = async () => { try { const voices = await Speech.getAvailableVoicesAsync(); setVoicesNumber(voices.length); } catch (error) { console.error("Error fetching voices.length:", error); setVoicesNumber('Error'); } finally { setIsLoading(false); // Set loading to false in both success and error cases } }; fetchNumber(); // Call the async function }, []); // Runs once on mount return ( <SafeAreaView style={styles.container}> <View style={styles.loadingContainer}> {isLoading ? ( <ActivityIndicator size="large" color="#0000ff" /> ) : ( <Text style={styles.numberDisplay}> Voice length is: {voicesNumber} </Text> )} </View> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', backgroundColor: '#ecf0f1', padding: 8, } });