55 */
66
77import React , { Component } from "react" ;
8- import { AppRegistry , StyleSheet , Text , TextInput , View , DeviceEventEmitter , ToastAndroid } from "react-native" ;
9- import Button from "react-native-button" ;
8+ import { AppRegistry , StyleSheet , View , TextInput , ToastAndroid , DeviceEventEmitter } from "react-native" ;
109import { Recognizer , Synthesizer } from "react-native-speech-iflytek" ;
10+ import Button from "react-native-button" ;
1111
12- class Example extends Component {
12+ export default class Example extends Component {
1313 constructor ( props ) {
1414 super ( props ) ;
1515
@@ -20,20 +20,22 @@ class Example extends Component {
2020
2121 this . onRecordStart = this . onRecordStart . bind ( this ) ;
2222 this . onRecordEnd = this . onRecordEnd . bind ( this ) ;
23- this . onSpeechRecognizerResult = this . onSpeechRecognizerResult . bind ( this ) ;
23+ this . onRecordCancel = this . onRecordCancel . bind ( this ) ;
24+ this . onRecognizerResult = this . onRecognizerResult . bind ( this ) ;
25+ this . onRecognizerVolumeChanged = this . onRecognizerVolumeChanged . bind ( this ) ;
2426 this . onSyntheBtnPress = this . onSyntheBtnPress . bind ( this ) ;
2527 }
2628
2729 componentDidMount ( ) {
2830 Synthesizer . init ( "57c7c5b0" ) ;
2931 Recognizer . init ( "57c7c5b0" ) ;
30- DeviceEventEmitter . addListener ( "onSpeechRecognizerResult " , this . onSpeechRecognizerResult ) ;
31- DeviceEventEmitter . addListener ( "onSpeechRecognizerVolumeChanged " , this . onSpeechRecognizerVolumeChanged ) ;
32+ DeviceEventEmitter . addListener ( "onRecognizerResult " , this . onRecognizerResult ) ;
33+ DeviceEventEmitter . addListener ( "onRecognizerVolumeChanged " , this . onRecognizerVolumeChanged ) ;
3234 }
3335
3436 componentWillUnmount ( ) {
35- DeviceEventEmitter . removeListener ( "onSpeechRecognizerResult " , this . onSpeechRecognizerResult ) ;
36- DeviceEventEmitter . addListener ( "onSpeechRecognizerVolumeChanged " , this . onSpeechRecognizerVolumeChanged ) ;
37+ DeviceEventEmitter . removeListener ( "onRecognizerResult " , this . onRecognizerResult ) ;
38+ DeviceEventEmitter . addListener ( "onRecognizerVolumeChanged " , this . onRecognizerVolumeChanged ) ;
3739 }
3840
3941 render ( ) {
@@ -51,12 +53,7 @@ class Example extends Component {
5153 >
5254 { this . state . recordBtnText }
5355 </ Button >
54- < Button
55- containerStyle = { styles . containerStyle }
56- style = { { color : "white" } }
57- onPress = { this . onSyntheBtnPress }
58- activeOpacity = { 0.8 }
59- >
56+ < Button containerStyle = { styles . containerStyle } style = { { color : "white" } } onPress = { this . onSyntheBtnPress } activeOpacity = { 0.8 } >
6057 Tap to speak
6158 </ Button >
6259 </ View >
@@ -82,14 +79,16 @@ class Example extends Component {
8279 // }, 500);
8380 }
8481
85- onSpeechRecognizerResult ( e ) {
82+ onRecognizerResult ( e ) {
8683 if ( ! e . isLast ) {
8784 return ;
8885 }
8986 this . setState ( { text : e . result } ) ;
9087 }
9188
92- onSpeechRecognizerVolumeChanged = ( ) => { } ;
89+ onRecognizerVolumeChanged ( ) {
90+
91+ }
9392
9493 async onSyntheBtnPress ( ) {
9594 let isSpeaking = await Synthesizer . isSpeaking ( ) ;
@@ -126,5 +125,4 @@ const styles = StyleSheet.create({
126125 }
127126} ) ;
128127
129- export default Example ;
130128AppRegistry . registerComponent ( "Example" , ( ) => Example ) ;
0 commit comments