Skip to content

Commit b563ee0

Browse files
author
spoeck
committed
2 parents cfa2279 + 49b5658 commit b563ee0

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![Version](https://img.shields.io/npm/v/react-native-api-ai.svg)](https://www.npmjs.com/package/react-native-api-ai)
55
[![Downloads](https://img.shields.io/npm/dt/react-native-api-ai.svg)](https://www.npmjs.com/package/react-native-api-ai)
66

7-
A React-Native Bridge for the Google API AI SDK
7+
A React-Native Bridge for the Google API AI SDK.
88

9-
Currently we are supporting android only. The support for ios will be released the next days.
9+
Support for iOS 10+ and Android!
1010

1111

1212
## Install
@@ -18,6 +18,19 @@ npm install --save react-native-api-ai
1818
react-native link react-native-api-ai
1919
```
2020

21+
### iOS: IMPORTANT xCode plist settings
22+
23+
Also, you need open the React Native xCode project and add two new keys into `Info.plist`
24+
Just right click on `Info.plist` -> `Open As` -> `Source Code` and paste these strings somewhere into root `<dict>` tag
25+
26+
```xml
27+
<key>NSSpeechRecognitionUsageDescription</key>
28+
<string>Your usage description here</string>
29+
<key>NSMicrophoneUsageDescription</key>
30+
<string>Your usage description here</string>
31+
```
32+
33+
Application will crash if you don't do this.
2134

2235
## Usage
2336
Import ApiAi:
@@ -48,8 +61,14 @@ Start listening with integrated speech recognition:
4861
}}
4962
/>
5063
```
64+
In iOS only you have to call `finishListening()`. Android detects the end of your speech automatically. That's the reason why we didn't implement the finish method in Android.
65+
```javascript
66+
// only for iOS
67+
ApiAi.finishListening();
68+
// after this call your callbacks from the startListening will be executed.
69+
```
5170

52-
Usage of `onListeningStarted`, `onListeningCanceled`, `onListeningFinished` and `onAudioLevel`:
71+
Only in Android we have four additional methods: `onListeningStarted`, `onListeningCanceled`, `onListeningFinished` and `onAudioLevel`. In iOS they will be never called:
5372
```javascript
5473
<Button onPress={() => {
5574

@@ -112,15 +131,16 @@ ApiAi.setConfiguration("4xxxxxxxe90xxxxxxxxc372", ApiAi.LANG_GERMAN);
112131
* LANG_UKRAINIAN
113132

114133
## Methods
115-
| name | param1 | param2 | param3 |
116-
| --------------------- | --------- | --------- | --------- |
117-
| `setConfiguration` | clientAccessToken: String | languageTag: String | |
118-
| `startListening` | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} | |
119-
| `requestQuery` | query: String | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} |
120-
| `onListeningStarted` | callback: ()=>{} | | |
121-
| `onListeningCanceled` | callback: ()=>{} || |
122-
| `onListeningFinished` | callback: ()=>{} | | |
123-
| `onAudioLevel` | callback: (level: number)=>{} || |
134+
| name | platform | param1 | param2 | param3 |
135+
| --------------------- | -------- | --------- | --------- | --------- |
136+
| `setConfiguration` | both | clientAccessToken: String | languageTag: String | |
137+
| `startListening` | both | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} | |
138+
| `finishListening` | ios | | | |
139+
| `requestQuery` | both | query: String | resultCallback: (result: object)=>{} | errorCallback: (error: object)=>{} |
140+
| `onListeningStarted` | android | callback: ()=>{} | | |
141+
| `onListeningCanceled` | android | callback: ()=>{} || |
142+
| `onListeningFinished` | android | callback: ()=>{} | | |
143+
| `onAudioLevel` | android | callback: (level: number)=>{} || |
124144

125145

126146
## Contributors

index.ios.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11

22
import { NativeModules, NativeAppEventEmitter } from 'react-native';
33
import {ApiAiClient} from 'api-ai-javascript';
4-
//var SpeechToText = require('react-native-speech-to-text-ios');
5-
var SpeechToText = NativeModules.RNSpeechToTextIos;
6-
/*
7-
let ApiAi = NativeModules.ApiAi;
8-
9-
ApiAi.setConfiguration = (clientAccessToken, languageToken) => {
10-
ApiAi.client = new ApiAiJS.ApiAiClient({accessToken: clientAccessToken});
11-
}
124

5+
var SpeechToText = NativeModules.RNSpeechToTextIos;
136

14-
console.log(NativeModules);
15-
16-
module.exports = ApiAi;
17-
*/
187
class ApiAi {
198

209

@@ -47,7 +36,7 @@ class ApiAi {
4736
onError(result.error);
4837
} else {
4938
if (result.isFinal) {
50-
this.requestQuery(result.bestTranscription.formattedString, this.onResult, this.onError);
39+
this.requestQuery(result.bestTranscription.formattedString, onResult, onError);
5140
}
5241

5342
}

0 commit comments

Comments
 (0)