-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
100 lines (87 loc) · 2.05 KB
/
App.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, {Component} from 'react'
import {
Container, Content, Button, Icon, Text, Fab, Header,
Title, Body, Left, Spinner
} from 'native-base'
import Permissions from 'react-native-permissions'
import {StyleSheet, View, Alert, } from 'react-native'
import {SpeechToText} from 'react-native-watson'
export default class App extends Component{
constructor(){
super()
this.state = {
text:'...',
recording: false
}
}
record(){
this.setState({recording:true})
SpeechToText.startStreaming((error, text)=>{
console.log(text)
this.setState({text})
})
}
stopRecord(){
this.setState({recording:false})
Alert.alert('stopped recoding:')
SpeechToText.stopStreaming()
}
componentDidMount(){
this.checkPermissions()
SpeechToText.initialize(YOUR_IBM_WATSON_USERNAME, YOUR_IBM_WATSON_PASSWORD)
}
checkPermissions = ()=>{
const p= Permissions.check('microphone')
//Alert.alert('permission check',p)
if(p==='authorized') return;
this.requestPermission()
}
requestPermission(){
const p = Permissions.request('microphone')
//Alert.alert('permission request',p)
}
render(){
return(
<Container>
<Header>
<Left />
<Body>
<Title>Genius List</Title>
</Body>
</Header>
<View style={{flex:1}}>
<Text style={styles.txt}>{this.state.text}</Text>
{this.state.recording?(
<Spinner
color='blue' />
):(
<Text style={styles.txt1} note>record now</Text>
)}
<Fab
position='bottomRight'
onPressIn={()=>this.record()}
onPressOut={()=>this.stopRecord()}
>
<Icon name='mic' />
</Fab>
</View>
</Container>
)
}
}
const styles = StyleSheet.create({
fab: {
backgroundColor: '#5067FF',
position: 'absolute',
bottom: 30,
right:25
},
txt:{
padding: 50,
fontSize: 25
},
txt1:{
padding: 50,
fontSize: 30
}
})