Skip to content

Commit 9a15e0c

Browse files
committed
feature: SpeechConstant
1 parent bd632ca commit 9a15e0c

File tree

4 files changed

+172
-46
lines changed

4 files changed

+172
-46
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.zphhhhh.speech;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
* Created by zph on 2017/8/5.
11+
*/
12+
13+
public class SpeechConstantModule extends ReactContextBaseJavaModule {
14+
15+
public SpeechConstantModule(ReactApplicationContext reactContext) {
16+
super(reactContext);
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "SpeechConstantModule";
22+
}
23+
24+
@Override
25+
public Map<String, Object> getConstants() {
26+
final Map<String, Object> constants = new HashMap<>();
27+
constants.put("APPID", com.iflytek.cloud.SpeechConstant.APPID);
28+
constants.put("NET_TYPE", com.iflytek.cloud.SpeechConstant.NET_TYPE);
29+
constants.put("FORCE_LOGIN", com.iflytek.cloud.SpeechConstant.FORCE_LOGIN);
30+
constants.put("LIB_NAME", com.iflytek.cloud.SpeechConstant.LIB_NAME);
31+
constants.put("RESULT_TYPE", com.iflytek.cloud.SpeechConstant.RESULT_TYPE);
32+
constants.put("RESULT_LEVEL", com.iflytek.cloud.SpeechConstant.RESULT_LEVEL);
33+
constants.put("LANGUAGE", com.iflytek.cloud.SpeechConstant.LANGUAGE);
34+
constants.put("ACCENT", com.iflytek.cloud.SpeechConstant.ACCENT);
35+
constants.put("DOMAIN", com.iflytek.cloud.SpeechConstant.DOMAIN);
36+
constants.put("VAD_ENABLE", com.iflytek.cloud.SpeechConstant.VAD_ENABLE);
37+
constants.put("VAD_BOS", com.iflytek.cloud.SpeechConstant.VAD_BOS);
38+
constants.put("VAD_EOS", com.iflytek.cloud.SpeechConstant.VAD_EOS);
39+
constants.put("SAMPLE_RATE", com.iflytek.cloud.SpeechConstant.SAMPLE_RATE);
40+
constants.put("PARAMS", com.iflytek.cloud.SpeechConstant.PARAMS);
41+
constants.put("NET_CHECK", com.iflytek.cloud.SpeechConstant.NET_CHECK);
42+
constants.put("NET_TIMEOUT", com.iflytek.cloud.SpeechConstant.NET_TIMEOUT);
43+
constants.put("KEY_SPEECH_TIMEOUT", com.iflytek.cloud.SpeechConstant.KEY_SPEECH_TIMEOUT);
44+
constants.put("ENGINE_MODE", com.iflytek.cloud.SpeechConstant.ENGINE_MODE);
45+
constants.put("ENGINE_TYPE", com.iflytek.cloud.SpeechConstant.ENGINE_TYPE);
46+
constants.put("AUDIO_SOURCE", com.iflytek.cloud.SpeechConstant.AUDIO_SOURCE);
47+
constants.put("ASR_SOURCE_PATH", com.iflytek.cloud.SpeechConstant.ASR_SOURCE_PATH);
48+
constants.put("FILTER_AUDIO_TIME", com.iflytek.cloud.SpeechConstant.FILTER_AUDIO_TIME);
49+
constants.put("LOCAL_GRAMMAR", com.iflytek.cloud.SpeechConstant.LOCAL_GRAMMAR);
50+
constants.put("CLOUD_GRAMMAR", com.iflytek.cloud.SpeechConstant.CLOUD_GRAMMAR);
51+
constants.put("GRAMMAR_TYPE", com.iflytek.cloud.SpeechConstant.GRAMMAR_TYPE);
52+
constants.put("GRAMMAR_NAME", com.iflytek.cloud.SpeechConstant.GRAMMAR_NAME);
53+
constants.put("GRAMMAR_LIST", com.iflytek.cloud.SpeechConstant.GRAMMAR_LIST);
54+
constants.put("LOCAL_GRAMMAR_PACKAGE", com.iflytek.cloud.SpeechConstant.LOCAL_GRAMMAR_PACKAGE);
55+
constants.put("NOTIFY_RECORD_DATA", com.iflytek.cloud.SpeechConstant.NOTIFY_RECORD_DATA);
56+
constants.put("MIXED_THRESHOLD", com.iflytek.cloud.SpeechConstant.MIXED_THRESHOLD);
57+
constants.put("MIXED_TYPE", com.iflytek.cloud.SpeechConstant.MIXED_TYPE);
58+
constants.put("MIXED_TIMEOUT", com.iflytek.cloud.SpeechConstant.MIXED_TIMEOUT);
59+
constants.put("ASR_THRESHOLD", com.iflytek.cloud.SpeechConstant.ASR_THRESHOLD);
60+
constants.put("LEXICON_TYPE", com.iflytek.cloud.SpeechConstant.LEXICON_TYPE);
61+
constants.put("ASR_NBEST", com.iflytek.cloud.SpeechConstant.ASR_NBEST);
62+
constants.put("ASR_WBEST", com.iflytek.cloud.SpeechConstant.ASR_WBEST);
63+
constants.put("ASR_PTT", com.iflytek.cloud.SpeechConstant.ASR_PTT);
64+
constants.put("ASR_SCH", com.iflytek.cloud.SpeechConstant.ASR_SCH);
65+
constants.put("ASR_DWA", com.iflytek.cloud.SpeechConstant.ASR_DWA);
66+
constants.put("NLP_VERSION", com.iflytek.cloud.SpeechConstant.NLP_VERSION);
67+
constants.put("SCENE", com.iflytek.cloud.SpeechConstant.SCENE);
68+
constants.put("TYPE_LOCAL", com.iflytek.cloud.SpeechConstant.TYPE_LOCAL);
69+
constants.put("TYPE_CLOUD", com.iflytek.cloud.SpeechConstant.TYPE_CLOUD);
70+
constants.put("TYPE_MIX", com.iflytek.cloud.SpeechConstant.TYPE_MIX);
71+
constants.put("TYPE_DISTRIBUTED", com.iflytek.cloud.SpeechConstant.TYPE_DISTRIBUTED);
72+
constants.put("TYPE_AUTO", com.iflytek.cloud.SpeechConstant.TYPE_AUTO);
73+
constants.put("ISV_SST", com.iflytek.cloud.SpeechConstant.ISV_SST);
74+
constants.put("ISV_PWDT", com.iflytek.cloud.SpeechConstant.ISV_PWDT);
75+
constants.put("ISV_VID", com.iflytek.cloud.SpeechConstant.ISV_VID);
76+
constants.put("ISV_RGN", com.iflytek.cloud.SpeechConstant.ISV_RGN);
77+
constants.put("ISV_PWD", com.iflytek.cloud.SpeechConstant.ISV_PWD);
78+
constants.put("ISV_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.ISV_AUDIO_PATH);
79+
constants.put("ISV_CMD", com.iflytek.cloud.SpeechConstant.ISV_CMD);
80+
constants.put("ISV_INTERRUPT_ERROR", com.iflytek.cloud.SpeechConstant.ISV_INTERRUPT_ERROR);
81+
constants.put("WFR_SST", com.iflytek.cloud.SpeechConstant.WFR_SST);
82+
constants.put("ISE_USER_MODEL_ID", com.iflytek.cloud.SpeechConstant.ISE_USER_MODEL_ID);
83+
constants.put("ISE_CATEGORY", com.iflytek.cloud.SpeechConstant.ISE_CATEGORY);
84+
constants.put("ISE_PARSED", com.iflytek.cloud.SpeechConstant.ISE_PARSED);
85+
constants.put("ISE_AUTO_TRACKING", com.iflytek.cloud.SpeechConstant.ISE_AUTO_TRACKING);
86+
constants.put("ISE_TRACK_TYPE", com.iflytek.cloud.SpeechConstant.ISE_TRACK_TYPE);
87+
constants.put("ISE_INTERRUPT_ERROR", com.iflytek.cloud.SpeechConstant.ISE_INTERRUPT_ERROR);
88+
constants.put("ISE_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.ISE_AUDIO_PATH);
89+
constants.put("ISE_SOURCE_PATH", com.iflytek.cloud.SpeechConstant.ISE_SOURCE_PATH);
90+
constants.put("IVW_SST", com.iflytek.cloud.SpeechConstant.IVW_SST);
91+
constants.put("IVW_WORD_PATH", com.iflytek.cloud.SpeechConstant.IVW_WORD_PATH);
92+
constants.put("IVW_THRESHOLD", com.iflytek.cloud.SpeechConstant.IVW_THRESHOLD);
93+
constants.put("KEEP_ALIVE", com.iflytek.cloud.SpeechConstant.KEEP_ALIVE);
94+
constants.put("IVW_SHOT_WORD", com.iflytek.cloud.SpeechConstant.IVW_SHOT_WORD);
95+
constants.put("IVW_ENROLL_RES_PATH", com.iflytek.cloud.SpeechConstant.IVW_ENROLL_RES_PATH);
96+
constants.put("IVW_ENROLL_DEST_PATH", com.iflytek.cloud.SpeechConstant.IVW_ENROLL_DEST_PATH);
97+
constants.put("IVW_ENROLL_TMIN", com.iflytek.cloud.SpeechConstant.IVW_ENROLL_TMIN);
98+
constants.put("IVW_ENROLL_TMAX", com.iflytek.cloud.SpeechConstant.IVW_ENROLL_TMAX);
99+
constants.put("IVW_VOL_CHECK", com.iflytek.cloud.SpeechConstant.IVW_VOL_CHECK);
100+
constants.put("IVW_ENROLL_TIMES", com.iflytek.cloud.SpeechConstant.IVW_ENROLL_TIMES);
101+
constants.put("IVW_RES_PATH", com.iflytek.cloud.SpeechConstant.IVW_RES_PATH);
102+
constants.put("IVW_NET_MODE", com.iflytek.cloud.SpeechConstant.IVW_NET_MODE);
103+
constants.put("IVW_CHANNEL_NUM", com.iflytek.cloud.SpeechConstant.IVW_CHANNEL_NUM);
104+
constants.put("IVW_RESET_AIMIC", com.iflytek.cloud.SpeechConstant.IVW_RESET_AIMIC);
105+
constants.put("IVW_ALSA_CARD", com.iflytek.cloud.SpeechConstant.IVW_ALSA_CARD);
106+
constants.put("IVW_ALSA_RATE", com.iflytek.cloud.SpeechConstant.IVW_ALSA_RATE);
107+
constants.put("IVW_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.IVW_AUDIO_PATH);
108+
constants.put("VOICE_NAME", com.iflytek.cloud.SpeechConstant.VOICE_NAME);
109+
constants.put("EMOT", com.iflytek.cloud.SpeechConstant.EMOT);
110+
constants.put("NEXT_TEXT", com.iflytek.cloud.SpeechConstant.NEXT_TEXT);
111+
constants.put("LOCAL_SPEAKERS", com.iflytek.cloud.SpeechConstant.LOCAL_SPEAKERS);
112+
constants.put("SPEED", com.iflytek.cloud.SpeechConstant.SPEED);
113+
constants.put("PITCH", com.iflytek.cloud.SpeechConstant.PITCH);
114+
constants.put("VOLUME", com.iflytek.cloud.SpeechConstant.VOLUME);
115+
constants.put("BACKGROUND_SOUND", com.iflytek.cloud.SpeechConstant.BACKGROUND_SOUND);
116+
constants.put("TTS_BUFFER_TIME", com.iflytek.cloud.SpeechConstant.TTS_BUFFER_TIME);
117+
constants.put("TTS_PLAY_STATE", com.iflytek.cloud.SpeechConstant.TTS_PLAY_STATE);
118+
constants.put("TTS_DATA_NOTIFY", com.iflytek.cloud.SpeechConstant.TTS_DATA_NOTIFY);
119+
constants.put("TTS_INTERRUPT_ERROR", com.iflytek.cloud.SpeechConstant.TTS_INTERRUPT_ERROR);
120+
constants.put("TTS_SPELL_INFO", com.iflytek.cloud.SpeechConstant.TTS_SPELL_INFO);
121+
constants.put("AUDIO_FORMAT", com.iflytek.cloud.SpeechConstant.AUDIO_FORMAT);
122+
constants.put("STREAM_TYPE", com.iflytek.cloud.SpeechConstant.STREAM_TYPE);
123+
constants.put("KEY_REQUEST_FOCUS", com.iflytek.cloud.SpeechConstant.KEY_REQUEST_FOCUS);
124+
constants.put("TTS_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.TTS_AUDIO_PATH);
125+
constants.put("DATA_TYPE", com.iflytek.cloud.SpeechConstant.DATA_TYPE);
126+
constants.put("SUBJECT", com.iflytek.cloud.SpeechConstant.SUBJECT);
127+
constants.put("ASR_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.ASR_AUDIO_PATH);
128+
constants.put("ASR_INTERRUPT_ERROR", com.iflytek.cloud.SpeechConstant.ASR_INTERRUPT_ERROR);
129+
constants.put("ASR_NOMATCH_ERROR", com.iflytek.cloud.SpeechConstant.ASR_NOMATCH_ERROR);
130+
constants.put("ASR_NET_PERF", com.iflytek.cloud.SpeechConstant.ASR_NET_PERF);
131+
constants.put("ENG_ASR", com.iflytek.cloud.SpeechConstant.ENG_ASR);
132+
constants.put("ENG_TTS", com.iflytek.cloud.SpeechConstant.ENG_TTS);
133+
constants.put("ENG_NLU", com.iflytek.cloud.SpeechConstant.ENG_NLU);
134+
constants.put("ENG_IVW", com.iflytek.cloud.SpeechConstant.ENG_IVW);
135+
constants.put("ENG_IVP", com.iflytek.cloud.SpeechConstant.ENG_IVP);
136+
constants.put("ENG_WFR", com.iflytek.cloud.SpeechConstant.ENG_WFR);
137+
constants.put("ENG_EVA", com.iflytek.cloud.SpeechConstant.ENG_EVA);
138+
constants.put("MODE_MSC", com.iflytek.cloud.SpeechConstant.MODE_MSC);
139+
constants.put("MODE_PLUS", com.iflytek.cloud.SpeechConstant.MODE_PLUS);
140+
constants.put("MODE_AUTO", com.iflytek.cloud.SpeechConstant.MODE_AUTO);
141+
constants.put("TEXT_ENCODING", com.iflytek.cloud.SpeechConstant.TEXT_ENCODING);
142+
constants.put("TEXT_BOM", com.iflytek.cloud.SpeechConstant.TEXT_BOM);
143+
constants.put("AUTH_ID", com.iflytek.cloud.SpeechConstant.AUTH_ID);
144+
constants.put("MFV_SST", com.iflytek.cloud.SpeechConstant.MFV_SST);
145+
constants.put("MFV_VCM", com.iflytek.cloud.SpeechConstant.MFV_VCM);
146+
constants.put("MFV_SCENES", com.iflytek.cloud.SpeechConstant.MFV_SCENES);
147+
constants.put("MFV_AFC", com.iflytek.cloud.SpeechConstant.MFV_AFC);
148+
constants.put("MFV_DATA_PATH", com.iflytek.cloud.SpeechConstant.MFV_DATA_PATH);
149+
constants.put("MFV_INTERRUPT_ERROR", com.iflytek.cloud.SpeechConstant.MFV_INTERRUPT_ERROR);
150+
constants.put("PROT_TYPE", com.iflytek.cloud.SpeechConstant.PROT_TYPE);
151+
constants.put("PLUS_LOCAL_TTS", com.iflytek.cloud.SpeechConstant.PLUS_LOCAL_TTS);
152+
constants.put("PLUS_LOCAL_ASR", com.iflytek.cloud.SpeechConstant.PLUS_LOCAL_ASR);
153+
constants.put("PLUS_LOCAL_IVW", com.iflytek.cloud.SpeechConstant.PLUS_LOCAL_IVW);
154+
constants.put("PLUS_LOCAL_ALL", com.iflytek.cloud.SpeechConstant.PLUS_LOCAL_ALL);
155+
constants.put("IST_SESSION_ID", com.iflytek.cloud.SpeechConstant.IST_SESSION_ID);
156+
constants.put("IST_SYNC_ID", com.iflytek.cloud.SpeechConstant.IST_SYNC_ID);
157+
constants.put("IST_AUDIO_UPLOADED", com.iflytek.cloud.SpeechConstant.IST_AUDIO_UPLOADED);
158+
constants.put("IST_AUDIO_PATH", com.iflytek.cloud.SpeechConstant.IST_AUDIO_PATH);
159+
constants.put("IST_SESSION_TRY", com.iflytek.cloud.SpeechConstant.IST_SESSION_TRY);
160+
return constants;
161+
}
162+
}

android/src/main/java/com/zphhhhh/speech/SpeechPackage.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ public List<NativeModule> createNativeModules(ReactApplicationContext reactConte
2222

2323
modules.add(new SpeechRecognizerModule(reactContext));
2424
modules.add(new SpeechSynthesizerModule(reactContext));
25+
modules.add(new SpeechConstantModule(reactContext));
2526

2627
return modules;
2728
}
2829

29-
@Override
30-
public List<Class<? extends JavaScriptModule>> createJSModules() {
31-
return Collections.emptyList();
32-
}
33-
3430
@Override
3531
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
3632
return Collections.emptyList();

android/src/main/java/com/zphhhhh/speech/SpeechRecognizerModule.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,6 @@ public String getName() {
5555
return "SpeechRecognizerModule";
5656
}
5757

58-
@Override
59-
public Map<String, Object> getConstants() {
60-
final Map<String, Object> constants = new HashMap<>();
61-
constants.put("PARAM", SpeechConstant.PARAMS);
62-
constants.put("ENGINE_TYPE", SpeechConstant.ENGINE_TYPE);
63-
constants.put("RESULT_TYPE", SpeechConstant.RESULT_TYPE);
64-
constants.put("LANGUAGE", SpeechConstant.LANGUAGE);
65-
constants.put("ACCENT", SpeechConstant.ACCENT);
66-
constants.put("VAD_BOS", SpeechConstant.VAD_BOS);
67-
constants.put("VAD_EOS", SpeechConstant.VAD_EOS);
68-
constants.put("ASR_PTT", SpeechConstant.ASR_PTT);
69-
constants.put("ASR_PTT", SpeechConstant.ASR_PTT);
70-
constants.put("AUDIO_FORMAT", SpeechConstant.AUDIO_FORMAT);
71-
constants.put("ASR_AUDIO_PATH", SpeechConstant.ASR_AUDIO_PATH);
72-
73-
return constants;
74-
}
75-
7658
@ReactMethod
7759
public void init(String AppId) {
7860
if (mIat != null) {
@@ -175,7 +157,7 @@ public void getParameter(String param, Promise promise) {
175157

176158
private static void setIatParam() {
177159
// 清空参数
178-
// mIat.setParameter(SpeechConstant.PARAMS, null);
160+
// mIat.setParameter(SpeechConstantModule.PARAMS, null);
179161

180162
// 设置听写引擎
181163
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
@@ -243,7 +225,13 @@ private void onIatResult(RecognizerResult results, boolean isLast) {
243225
}
244226

245227
private void onIatError(SpeechError error) {
246-
showTip(error.getPlainDescription(true));
228+
WritableMap params = Arguments.createMap();
229+
230+
params.putInt("errorCode", error.getErrorCode());
231+
params.putString("message", error.getErrorDescription());
232+
params.putString("plainDescription", error.getPlainDescription(true));
233+
234+
this.onJSEvent(getReactApplicationContext(),"onRecognizerError",params);
247235
}
248236

249237
private void showTip(final String str) {

android/src/main/java/com/zphhhhh/speech/SpeechSynthesizerModule.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,6 @@ public String getName() {
5252
return "SpeechSynthesizerModule";
5353
}
5454

55-
@Nullable
56-
@Override
57-
public Map<String, Object> getConstants() {
58-
final Map<String, Object> constants = new HashMap<>();
59-
constants.put("PARAM", SpeechConstant.PARAMS);
60-
constants.put("ENGINE_TYPE", SpeechConstant.ENGINE_TYPE);
61-
constants.put("RESULT_TYPE", SpeechConstant.RESULT_TYPE);
62-
constants.put("LANGUAGE", SpeechConstant.LANGUAGE);
63-
constants.put("ACCENT", SpeechConstant.ACCENT);
64-
constants.put("VAD_BOS", SpeechConstant.VAD_BOS);
65-
constants.put("VAD_EOS", SpeechConstant.VAD_EOS);
66-
constants.put("ASR_PTT", SpeechConstant.ASR_PTT);
67-
constants.put("ASR_PTT", SpeechConstant.ASR_PTT);
68-
constants.put("AUDIO_FORMAT", SpeechConstant.AUDIO_FORMAT);
69-
constants.put("ASR_AUDIO_PATH", SpeechConstant.ASR_AUDIO_PATH);
70-
constants.put("TTS_AUDIO_PATH", SpeechConstant.TTS_AUDIO_PATH);
71-
72-
return constants;
73-
}
74-
7555
@ReactMethod
7656
public void init(String AppId) {
7757
if (mTts != null) {
@@ -194,7 +174,7 @@ private void setTtsParam() {
194174

195175
mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
196176
// 设置在线合成发音人
197-
mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaofeng");
177+
mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");
198178
//设置合成语速
199179
mTts.setParameter(SpeechConstant.SPEED, "50");
200180
//设置合成音调

0 commit comments

Comments
 (0)