-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
68 lines (60 loc) · 1.68 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as React from 'react';
import { View, StyleSheet, Button, Picker, TextInput, Text } from 'react-native';
import * as Speech from 'expo-speech';
export default function App() {
const [text, setText] = React.useState('Mateus')
const [voice, setVoice] = React.useState<Speech.Voice | undefined>()
const [voices, setVoices] = React.useState<Speech.Voice[]>([])
const [loading, setLoading] = React.useState(true)
React.useEffect(() => {
(async () => {
const availableVoices = await Speech.getAvailableVoicesAsync()
setVoices(availableVoices)
setVoice(availableVoices[0])
setLoading(false)
})()
}, [])
const speak = () => {
Speech.speak(text, { language: voice?.language, voice: voice?.identifier });
};
return !loading
? (
<View style={styles.container}>
<Text>Language:</Text>
<Picker
style={styles.input}
selectedValue={voice?.identifier}
onValueChange={value => setVoice(voices.find(v => v.identifier == value))}
>
{voices.map(v =>
<Picker.Item label={v.name} value={v.identifier} />
)}
</Picker>
<Text>Something to say:</Text>
<TextInput
style={styles.input}
value={text}
onChangeText={value => setText(value)}
/>
<Button
title="Press to hear"
onPress={speak}
/>
</View>
)
: <>Carregando...</>;
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
},
});