Skip to content

Commit fb20957

Browse files
author
spoeck
committed
feat: ios support for UserEntities
1 parent 86e768a commit fb20957

1 file changed

Lines changed: 57 additions & 52 deletions

File tree

index.ios.js

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,89 @@ var SpeechToText = NativeModules.RNSpeechToTextIos;
77
class ApiAi {
88

99

10-
setConfiguration(clientAccessToken: String, languageTag: String) {
11-
this.language = languageTag;
12-
this.client = new ApiAiClient({accessToken: clientAccessToken, apiLang: languageTag});
13-
}
10+
setConfiguration(clientAccessToken: String, languageTag: String) {
11+
this.language = languageTag;
12+
this.client = new ApiAiClient({accessToken: clientAccessToken, apiLang: languageTag});
13+
}
1414

15-
onListeningStarted(callback: ()=>{}) {
15+
onListeningStarted(callback: ()=>{}) {
1616

17-
}
17+
}
1818

19-
onListeningCanceled(callback: ()=>{}) {
19+
onListeningCanceled(callback: ()=>{}) {
2020

21-
}
21+
}
2222

23-
onListeningFinished(callback: ()=>{}) {
23+
onListeningFinished(callback: ()=>{}) {
2424

25-
}
25+
}
2626

27-
startListening(onResult: ()=>{}, onError: ()=>{}) {
27+
startListening(onResult: ()=>{}, onError: ()=>{}) {
2828

29-
this.subscription = NativeAppEventEmitter.addListener(
30-
'SpeechToText',
31-
(result) => {
29+
this.subscription = NativeAppEventEmitter.addListener(
30+
'SpeechToText',
31+
(result) => {
3232

33-
console.log(result);
33+
console.log(result);
3434

35-
if (result.error) {
36-
onError(result.error);
37-
} else {
38-
if (result.isFinal) {
39-
this.requestQuery(result.bestTranscription.formattedString, onResult, onError);
40-
}
35+
if (result.error) {
36+
onError(result.error);
37+
} else {
38+
if (result.isFinal) {
39+
this.requestQuery(result.bestTranscription.formattedString, onResult, onError);
40+
}
4141

42-
}
42+
}
4343

44-
}
45-
);
44+
}
45+
);
4646

47-
SpeechToText.startRecognition(this.language);
48-
}
47+
SpeechToText.startRecognition(this.language);
48+
}
4949

50-
finishListening() {
51-
SpeechToText.finishRecognition();
52-
}
50+
finishListening() {
51+
SpeechToText.finishRecognition();
52+
}
5353

5454
setContexts(contexts) {
5555
this.contexts = contexts;
5656
}
5757

58+
setEntities(entities) {
59+
this.entities = entities;
60+
}
61+
5862
requestQuery(query: String, onResult: ()=>{}, onError: ()=>{}) {
59-
if (this.contexts) {
60-
this.client.textRequest(query, {contexts: this.contexts}).then(res=>onResult(res)).catch(err=>onError(err));
63+
if (this.contexts || this.entities) {
64+
this.client.textRequest(query, {contexts: this.contexts, entities: this.entities}).then(res=>onResult(res)).catch(err=>onError(err));
6165
this.contexts = null;
66+
this.entities = null;
6267
} else {
6368
this.client.textRequest(query).then(res=>onResult(res)).catch(err=>onError(err));
6469
}
6570
}
6671

67-
onAudioLevel(callback) {
68-
69-
}
70-
71-
LANG_CHINESE_CHINA = "zh-CN";
72-
LANG_CHINESE_HONGKONG = "zh-HK";
73-
LANG_CHINESE_TAIWAN = "zh-TW";
74-
LANG_DUTCH = "nl";
75-
LANG_ENGLISH = "en";
76-
LANG_ENGLISH_GB = "en-GB";
77-
LANG_ENGLISH_US = "en-US";
78-
LANG_FRENCH = "fr";
79-
LANG_GERMAN = "de";
80-
LANG_ITALIAN = "it";
81-
LANG_JAPANESE = "ja";
82-
LANG_KOREAN = "ko";
83-
LANG_PORTUGUESE = "pt";
84-
LANG_PORTUGUESE_BRAZIL = "pt-BR";
85-
LANG_RUSSIAN = "ru";
86-
LANG_SPANISH = "es";
87-
LANG_UKRAINIAN = "uk";
72+
onAudioLevel(callback) {
73+
74+
}
75+
76+
LANG_CHINESE_CHINA = "zh-CN";
77+
LANG_CHINESE_HONGKONG = "zh-HK";
78+
LANG_CHINESE_TAIWAN = "zh-TW";
79+
LANG_DUTCH = "nl";
80+
LANG_ENGLISH = "en";
81+
LANG_ENGLISH_GB = "en-GB";
82+
LANG_ENGLISH_US = "en-US";
83+
LANG_FRENCH = "fr";
84+
LANG_GERMAN = "de";
85+
LANG_ITALIAN = "it";
86+
LANG_JAPANESE = "ja";
87+
LANG_KOREAN = "ko";
88+
LANG_PORTUGUESE = "pt";
89+
LANG_PORTUGUESE_BRAZIL = "pt-BR";
90+
LANG_RUSSIAN = "ru";
91+
LANG_SPANISH = "es";
92+
LANG_UKRAINIAN = "uk";
8893
}
8994

9095
export default new ApiAi();

0 commit comments

Comments
 (0)