Skip to content

Commit f775327

Browse files
author
spoeck
committed
feat: support for android
1 parent 44638d4 commit f775327

3 files changed

Lines changed: 330 additions & 31 deletions

File tree

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
11
# react-native-api-ai
22
A React-Native Bridge for the Google API AI SDK
3+
4+
Currently we are supporting android only. The support for ios will be released the next days.
5+
6+
7+
## Install
8+
9+
Add react-native-api-ai and link it:
10+
```
11+
npm install --save react-native-api-ai
12+
13+
react-native link react-native-api-ai
14+
```
15+
16+
17+
## Usage
18+
Import ApiAi:
19+
```javascript
20+
import ApiAi from "react-native-api-ai";
21+
```
22+
23+
Set the `clientAccessToken` and the language in your contructor:
24+
```javascript
25+
constructor(props) {
26+
super(props);
27+
28+
ApiAi.setConfiguration(
29+
"4xxxxxxxe90xxxxxxxxc372", ApiAi.LANG_GERMAN
30+
);
31+
}
32+
33+
```
34+
35+
Start listening with integrated speech recognition:
36+
```javascript
37+
<Button onPress={() => {
38+
ApiAi.startListening(result=>{
39+
console.log(result);
40+
}, error=>{
41+
console.log(error);
42+
});
43+
}}
44+
/>
45+
```
46+
47+
Usage of `onListeningStarted`, `onListeningCanceled`, `onListeningFinished` and `onAudioLevel`:
48+
```javascript
49+
<Button onPress={() => {
50+
51+
ApiAi.onListeningStarted(()=>{
52+
console.log("listening started");
53+
});
54+
55+
ApiAi.onListeningCanceled(()=>{
56+
console.log("listening canceled");
57+
});
58+
59+
ApiAi.onListeningFinished(()=>{
60+
console.log("listening finished");
61+
});
62+
63+
ApiAi.onAudioLevel(level=>{
64+
console.log(level);
65+
});
66+
67+
68+
ApiAi.startListening(result=>{
69+
console.log(result);
70+
}, error=>{
71+
console.log(error);
72+
});
73+
}}
74+
/>
75+
```
76+
Note: Make sure you are setting the callbacks before startListening again every single time. Don't set in e.g. constructor or componentsDidMount if you are executing startListening more than one times.
77+
78+
Using your own speech recognition:
79+
```javascript
80+
<Button onPress={() => {
81+
ApiAi.requestQuery("Some text for your api-ai agent", result=>console.log(result), error=>console.log(error));
82+
}}
83+
/>
84+
```
85+
86+
## Supported Languages
87+
Set the language in your configuration:
88+
```javascript
89+
ApiAi.setConfiguration("4xxxxxxxe90xxxxxxxxc372", ApiAi.LANG_GERMAN);
90+
```
91+
* LANG_CHINESE_CHINA
92+
* LANG_CHINESE_HONGKONG
93+
* LANG_CHINESE_TAIWAN
94+
* LANG_DUTCH
95+
* LANG_ENGLISH
96+
* LANG_ENGLISH_GB
97+
* LANG_ENGLISH_US
98+
* LANG_FRENCH
99+
* LANG_GERMAN
100+
* LANG_ITALIAN
101+
* LANG_JAPANESE
102+
* LANG_KOREAN
103+
* LANG_PORTUGUESE
104+
* LANG_PORTUGUESE_BRAZIL
105+
* LANG_RUSSIAN
106+
* LANG_SPANISH
107+
* LANG_UKRAINIAN
108+
109+
## Methods
110+
| name | param1 | param2 | param3 |
111+
| --------------------- | --------- | --------- | --------- |
112+
| `setConfiguration` | clientAccessToken: String | languageTag: String | |
113+
| `startListening` | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} | |
114+
| `requestQuery` | query: String | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} |
115+
| `onListeningStarted` | callback: ()=>{} | | |
116+
| `onListeningCanceled` | callback: ()=>{} || |
117+
| `onListeningFinished` | callback: ()=>{} | | |
118+
| `onAudioLevel` | callback: (level: number)=>{} || |

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
package="de.innfactory.apiai">
33

44
<uses-permission android:name="android.permission.RECORD_AUDIO" />
5+
<uses-permission android:name="android.permission.INTERNET" />
56

67
</manifest>

0 commit comments

Comments
 (0)