-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMicButton.js
56 lines (48 loc) · 1.17 KB
/
MicButton.js
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
import React, {useEffect} from 'react';
import ContainerCenter from './ContainerCenter';
import IconButton from './IconButton';
import Icon from 'react-native-vector-icons/Feather';
import Voice from '@react-native-community/voice';
function MicButton({lang, func}) {
useEffect(() => {
const onSpeechResults = (e) => {
func(e.value);
};
Voice.onSpeechResults = onSpeechResults;
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, []);
const startRecognizing = async () => {
func([]);
try {
await Voice.start(lang);
} catch (e) {
console.error(e);
}
};
return (
<ContainerCenter ml={100}>
<IconButton
m={10}
onPress={() => startRecognizing()}
bg="blue"
width={84}
height={84}
borderRadius={50}
style={{
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 4,
},
shadowOpacity: 0.5,
shadowRadius: 4,
elevation: 8,
}}>
<Icon name="mic" size={48} color="white" />
</IconButton>
</ContainerCenter>
);
}
export default MicButton;