@@ -4,16 +4,34 @@ react-native-speech-iflytek 是一个 React Native 下的科大讯飞语音库
4
4
## Support
5
5
- React Native >= 0.47.0 from 0.2.0
6
6
- React Native >= 0.42.0 from 0.1.2
7
- - Android,目前仅支持 Android
7
+ - Android
8
+ - iOS from 1.0.0
8
9
9
10
## Install
10
11
```
11
12
npm i react-native-speech-iflytek --save
12
13
react-native link
13
14
```
14
- 安装后还须进行下面两步:
15
- 1 . 在 [ 讯飞开放平台] ( http://www.xfyun.cn/sdk/dispatcher ) 下载组合服务SDK(选择` 语音听写 ` 与` 在线语音合成 ` )
16
- 2 . 使用下载 SDK 的 ` Android_voice_xxxx_xxxxxxxx/libs ` 文件夹替换 ` YourProject/node_modules/react-native-speech-iflytek/android/libs ` 文件夹,这是因为讯飞语音的原生库与注册应用进行了绑定。
15
+ 安装、链接后还须进行下面两步(以 ` Example ` 工程为例):
16
+ 1 . 在 [ 讯飞开放平台] ( http://www.xfyun.cn/sdk/dispatcher ) 下载组合服务 SDK (选择` 语音听写 ` 与` 在线语音合成 ` ),分别下载 Android 与 iOS 平台 SDK。
17
+ 2 . 替换 SDK 文件:
18
+ 1 . 使用下载 Android SDK 的 ` Android_voice_xxxx_xxxxxxxx/libs ` 文件夹替换 ` Example/node_modules/react-native-speech-iflytek/android/libs ` 文件夹;
19
+ 2 . 使用下载 iOS SDK 的 ` iOS_voice_xxxx_xxxxxxxx/libs ` 文件夹替换 ` Example/node_modules/react-native-speech-iflytek/ios/libs ` 文件夹。
20
+ 3 . iOS 平台还需手动添加部分依赖库:
21
+ 1 . 在 XCode 中打开 ` Example/ios/YourProject.xcodeproj ` ;
22
+ 2 . 将讯飞框架文件 ` Example/node_modules/react-native-speech-iflytek/ios/libs/iflyMSC.framework ` 拖入 Project navigator 的 ` Frameworks ` 下,注意选择 ` Copy items if needed ` ;
23
+ 3 . 添加讯飞依赖的系统库(见:[ 科大讯飞MSC开发指南-iOS-集成流程] ( http://doc.xfyun.cn/msc_ios/302721 ) ):
24
+ - CoreLocation.framework
25
+ - CoreTelephony.framework
26
+ - AVFoundation.framework
27
+ - AddressBook.framework
28
+ - Contacts.framework
29
+ - AudioToolbox.framework
30
+ - SystemConfiguration.framework
31
+ - QuartzCore.framework
32
+ - UIKit.framework
33
+ - Foundation.framework
34
+ - CoreGraphics.framework
17
35
18
36
## Usage
19
37
(详见 Example)引入包:
@@ -23,7 +41,8 @@ import { Recognizer, Synthesizer, SpeechConstant } from "react-native-speech-ifl
23
41
语音识别:
24
42
```
25
43
Recognizer.init("57c7c5b0");
26
- DeviceEventEmitter.addListener("onRecognizerResult", this.onRecognizerResult);
44
+ this.recognizerEventEmitter = new NativeEventEmitter(Recognizer);
45
+ this.recognizerEventEmitter.addListener('onRecognizerResult', this.onRecognizerResult);
27
46
Recognizer.start();
28
47
```
29
48
处理识别结果:
@@ -32,7 +51,6 @@ onRecognizerResult(e) {
32
51
if (!e.isLast) {
33
52
return;
34
53
}
35
- ToastAndroid.show(e.result, ToastAndroid.SHORT);
36
54
this.setState({ text: e.result });
37
55
}
38
56
```
@@ -67,9 +85,11 @@ onRecognizerResult(e) {
67
85
- ` onRecognizerError(JSON error) `
68
86
语音识别出现错误,错误信息与讯飞文档保持一致,其值:
69
87
70
- - `errorCode`: 获取错误码
71
- - `errorDescription`: 获取错误描述,不包含错误码的描述信息
72
- - `plainDescription`: 获取错误描述,包含错误码的描述信息
88
+ - `errorCode`: 获取错误码,关于错误码请见官方文档 [MSC错误码](http://www.xfyun.cn/index.php/default/doccenter/doccenterInner?itemTitle=ZmFx&anchor=Y29udGl0bGU2Ng==) :
89
+ - `errorType`: (仅 iOS)获取错误码类型
90
+ - `errorDesc`: (仅 iOS)获取错误描述
91
+ - `errorDescription`: (仅 Android)获取错误描述,不包含错误码的描述信息
92
+ - `plainDescription`: (仅 Android)获取错误描述,包含错误码的描述信息
73
93
74
94
### Synthesizer
75
95
#### Methods
@@ -90,7 +110,7 @@ onRecognizerResult(e) {
90
110
#### Events
91
111
- ` onSynthesizerBufferCompletedEvent() `
92
112
语音合成缓冲完成时触发该事件
93
- - ` onSynthesizerSpeakCompletedEvent() `
113
+ - ` onSynthesizerSpeakCompletedEvent() `
94
114
语音合成播放完成时触发该事件
95
115
96
116
### SpeechConstant
0 commit comments