Skip to content

Commit 1a68599

Browse files
committed
update iflytekLibs and README
1 parent a5c9203 commit 1a68599

File tree

16 files changed

+3653
-34
lines changed

16 files changed

+3653
-34
lines changed

Example/index.android.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import React, { Component } from "react";
8-
import { AppRegistry, StyleSheet, Text, TextInput, Button, View, DeviceEventEmitter, ToastAndroid } from "react-native";
8+
import { AppRegistry, StyleSheet, Text, TextInput, View, DeviceEventEmitter, ToastAndroid } from "react-native";
9+
import Button from "react-native-button";
910
import { Recognizer, Synthesizer } from "react-native-speech-iflytek";
1011

1112
class Example extends Component {
@@ -37,48 +38,54 @@ class Example extends Component {
3738

3839
render() {
3940
return (
40-
<View style={styles.container}>
41-
<TextInput
42-
style={{ height: 40, borderColor: "gray", borderWidth: 1 }}
43-
onChangeText={text => this.setState({ text })}
44-
value={this.state.text}
45-
/>
46-
<Text
47-
onStartShouldSetResponder={this.onRecordStart}
48-
onResponderRelease={this.onRecordEnd}
41+
<View style={styles.container} onStartShouldSetResponder={() => true}>
42+
<TextInput onChangeText={text => this.setState({ text })} value={this.state.text} />
43+
<Button
44+
containerStyle={styles.containerStyle}
45+
style={{ color: "white" }}
46+
onPress={this.onRecordEnd}
47+
onPressIn={this.onRecordStart}
48+
activeOpacity={0.8}
4949
onResponderTerminationRequest={() => true}
50-
onPress={this.onRecordBtnPress}
51-
style={styles.recordBtn}
50+
onResponderTerminate={this.onRecordCancel}
5251
>
5352
{this.state.recordBtnText}
54-
</Text>
55-
<Button title="Tap to speak" onPress={this.onSyntheBtnPress} />
53+
</Button>
54+
<Button
55+
containerStyle={styles.containerStyle}
56+
style={{ color: "white" }}
57+
onPress={this.onSyntheBtnPress}
58+
activeOpacity={0.8}
59+
>
60+
Tap to speak
61+
</Button>
5662
</View>
5763
);
5864
}
5965

6066
onRecordStart() {
61-
ToastAndroid.show("开始录音", ToastAndroid.SHORT);
67+
ToastAndroid.show("Begin to record", ToastAndroid.SHORT);
6268
this.setState({ recordBtnText: "Release to stop" });
6369
Recognizer.start();
64-
65-
// setTimeout(() => {
66-
// this.setState({ recordBtnText: "Press to record" });
67-
// Recognizer.stop();
68-
// }, 5000);
6970
}
7071

7172
onRecordEnd() {
72-
ToastAndroid.show("结束录音", ToastAndroid.SHORT);
73+
ToastAndroid.show("End to record", ToastAndroid.SHORT);
7374
this.setState({ recordBtnText: "Press to record" });
7475
Recognizer.stop();
7576
}
7677

78+
onRecordCancel(evt) {
79+
ToastAndroid.show("cancel", ToastAndroid.SHORT);
80+
// setTimeout(() => {
81+
// Recognizer.cancel();
82+
// }, 500);
83+
}
84+
7785
onSpeechRecognizerResult(e) {
7886
if (!e.isLast) {
7987
return;
8088
}
81-
ToastAndroid.show(e.result, ToastAndroid.SHORT);
8289
this.setState({ text: e.result });
8390
}
8491

@@ -95,8 +102,7 @@ const styles = StyleSheet.create({
95102
flex: 1,
96103
justifyContent: "center",
97104
alignItems: "stretch",
98-
paddingLeft: 5,
99-
paddingRight: 5
105+
padding: 5
100106
},
101107
result: {
102108
fontSize: 20,
@@ -111,6 +117,12 @@ const styles = StyleSheet.create({
111117
borderWidth: 1,
112118
borderRadius: 4,
113119
borderColor: "#ccc"
120+
},
121+
containerStyle: {
122+
backgroundColor: "#0275d8",
123+
margin: 4,
124+
padding: 4,
125+
borderRadius: 2
114126
}
115127
});
116128

0 commit comments

Comments
 (0)