Skip to content

Commit 8619995

Browse files
committed
docs: Update readme (#12)
[x] GIFs [x] customization
1 parent 417477b commit 8619995

File tree

7 files changed

+158
-28
lines changed

7 files changed

+158
-28
lines changed

README.md

Lines changed: 155 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,169 @@
1-
# InstantSearch Android Voice
1+
![Voice Overlay for Android](./docs/banner.png)
22

3-
**InstantSearch Android Voice** provides UI components and helpers for adding voice input to your apps.
3+
<p align="center">
4+
<img src="https://img.shields.io/badge/platform-Android-blue.svg?style=flat" alt="Platform Android" />
5+
<a href="./LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a>
6+
</p>
47

5-
# Getting started
8+
# Overview
69

7-
## Supported platforms
10+
**Voice overlay** helps you turn your user's **voice** into **text**, providing a **polished UX** while handling for you the **necessary permission**.
811

9-
**InstantSearch Insights Android** is supported on Android devices starting from SDK 14 (Ice Cream Sandwich) and is usable from both **Kotlin** and **Java** code.
12+
<p float="left">
13+
<img src="./docs/permission.jpg" width="200" />
14+
&nbsp;
15+
<img src="./docs/listen.gif" width="200" />
16+
&nbsp;
17+
<img src="./docs/speak.gif" width="200" />
18+
&nbsp;
19+
<img src="./docs/nopermission.jpg" width="200" />
20+
&nbsp;
21+
</p>
1022

11-
# Install
23+
# Demo
1224

13-
Add `jCenter` to your repositories in `build.gradle`
25+
You can clone this repo, then run the Demo project by doing `./gradlew app:installDebug` and launching the application:
1426

15-
```
16-
allprojects {
17-
repositories {
18-
// [...]
19-
jcenter()
20-
}
21-
}
22-
```
27+
<img src="./docs/demo.gif" width="250">
28+
29+
# Installation
2330

24-
Add the following dependency to your `Gradle` file
31+
The Voice overlay is available as a gradle dependency via [JCenter](https://bintray.com/bintray/jcenter). To install
32+
it, add the following line to your app's `build.gradle`:
2533

26-
```gradle
34+
```groovy
2735
dependencies {
2836
// [...]
2937
implementation 'com.algolia.instantsearch-android:voice:1.+'
3038
// [...]
3139
}
3240
```
3341

34-
## Quick Start
42+
43+
# Usage
44+
45+
## Basic usage
46+
1. In your Activity, check if you have the permission and show the appropriate `Dialog`:
47+
```kotlin
48+
if (!isRecordAudioPermissionGranted()) {
49+
VoicePermissionDialogFragment().show(supportFragmentManager, "DIALOG_PERMISSION")
50+
} else {
51+
VoiceInputDialogFragment().show(supportFragmentManager, "DIALOG_INPUT")
52+
}
53+
```
54+
_See [it implemented in the demo app](app/src/main/kotlin/com/algolia/instantsearch/voice/demo/MainActivity.kt#L26-L30)._
55+
56+
This will display the permission dialog if the `RECORD_AUDIO` permission was not yet granted, then the voice input dialog once the permission is granted.
57+
58+
Once the user speaks, you will get their input back by implementing `VoiceSpeechRecognizer.ResultsListener`:
59+
```kotlin
60+
override fun onResults(possibleTexts: Array<out String>) {
61+
// Do something with the results, for example:
62+
resultView.text = possibleTexts.firstOrNull()?.capitalize()
63+
}
64+
```
65+
_See [it implemented in the demo app](app/src/main/kotlin/com/algolia/instantsearch/voice/demo/MainActivity.kt#L41-L43)._
66+
67+
## When the permission is not granted
68+
69+
If the user didn't accept the permission, you [should explain](https://developer.android.com/training/permissions/requesting#explain) the permission's rationale. If they deny the permission, you need to guide them into manually enabling it if they want to use the voice-input feature.
70+
71+
Voice overlay makes it easy to handle all these cases:
72+
73+
```groovy
74+
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
75+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
76+
if (Voice.isRecordPermissionWithResults(requestCode, grantResults)) {
77+
when {
78+
Voice.isPermissionGranted(grantResults) -> showVoiceDialog()
79+
shouldExplainPermission() -> showPermissionRationale(getPermissionView())
80+
else -> Voice.showPermissionManualInstructions(getPermissionView())
81+
}
82+
}
83+
// [...] eventual handling of other permissions requested by your app
84+
}
85+
```
86+
_See [it implemented in the demo app](app/src/main/kotlin/com/algolia/instantsearch/voice/demo/MainActivity.kt#L42-L51)._
87+
88+
This will display the permission rationale when the user doesn't allow it, and the manual instructions in case they denied it.
89+
90+
## Customization
91+
You can customize your voice overlay in the following ways:
92+
93+
### Behavior
94+
Several options let you adapt the voice overlay\'s behavior to your needs.
95+
96+
#### Suggestions
97+
You can provide suggestions of what the user could say, to give them some examples.
98+
```kotlin
99+
voiceInputDialogFragment.setSuggestions(
100+
"64GB Smartphone",
101+
"Red running shoes",
102+
"Cheap TV screen"
103+
)
104+
```
105+
106+
#### AutoStart
107+
You can prevent the overlay from automatically listening to user input.
108+
```kotlin
109+
/// Requires the user to click the mic to start listening.
110+
voiceInputDialogFragment.autoStart = false
111+
// [...]
112+
// you can also start listening programmatically with
113+
voiceInputDialogFragment.start()
114+
```
115+
116+
117+
### Copy text
118+
119+
You can change any text displayed in the overlay by overriding its resource in your `strings.xml`:
120+
```xml
121+
<!-- VoiceInputDialogFragment -->
122+
<string name="input_title_listening">Listening…</string>
123+
<string name="input_subtitle_listening">Say something like:</string>
124+
<string name="input_title_error">Sorry, we didn\'t quite get that.</string>
125+
<string name="input_subtitle_error">Try repeating your request.</string>
126+
<string name="input_hint_error">Try again</string>
127+
128+
<!-- VoicePermissionDialogFragment -->
129+
<string name="permission_title">You can use voice search to find products.</string>
130+
<string name="permission_subtitle">May we access your device’s microphone to enable voice search?</string>
131+
<string name="permission_button_allow">Allow microphone access</string>
132+
<string name="permission_button_reject">No</string>
133+
134+
<!-- Rationale/Try Again -->
135+
<string name="permission_rationale">Voice search requires this permission.</string>
136+
<string name="permission_button_again">Request again?</string>
137+
138+
<!-- Manual Instructions -->
139+
<string name="permission_enable_rationale">Permission denied, allow it to use voice search.</string>
140+
<string name="permission_button_enable">Allow recording</string>
141+
<string name="permission_enable_instructions">On the next screen, tap Permissions then Microphone.</string>
142+
```
143+
### Layouts
144+
145+
You can replace the voice overlay's layouts by your own, as long as they respect the following structure:
146+
147+
#### Permission
148+
149+
Create a layout called `voice_input.xml` with
150+
- A `ViewGroup` container with id `@+id/voicePermission`
151+
- A `View` with id `@+id/close` for closing the overlay when clicked
152+
- A `TextView` with id `@+id/title`
153+
- A `TextView` with id `@+id/subtitle`
154+
155+
#### Input
156+
157+
Create a layout called `voice_permission.xml` with
158+
- A `ViewGroup` container with id `@+id/voiceInput`
159+
- A `VoiceMicrophone` with id `@+id/microphone` to handle the voice input
160+
- A `TextView` with id `@+id/suggestions` to display eventual suggestions
161+
- A `View` with id `@+id/close` for closing the overlay when clicked
162+
- A `TextView` with id `@+id/title`
163+
- A `TextView` with id `@+id/subtitle`
164+
- An eventual `TextView` with id `@+id/hint` to display a hint on error
165+
- An eventual `RippleView` with id `@+id/ripple` if you want to keep the animation
166+
35167
## Getting Help
36168

37169
- **Need help**? Ask a question to the [Algolia Community](https://discourse.algolia.com/) or on [Stack Overflow](http://stackoverflow.com/questions/tagged/algolia).
@@ -41,11 +173,10 @@ dependencies {
41173

42174
## Getting involved
43175

44-
* If you **want to contribute** please feel free to **[submit pull requests](https://github.com/algolia/voice-overlay-android/pull/new)**.
45-
* If you **have a feature request** please **[open an
46-
issue](https://github.com/algolia/voice-overlay-android/issues/new]**.
47-
* If you use **InstantSearch** in your app, we would love to hear about it! Drop us a line on [discourse](https://discourse.algolia.com/new-topic?title=InstantSearch%20Mobile%20App:&category_id=10&body=I%27m%20using%20InstantSearch%20for...) or [twitter](https://twitter.com/algolia).
176+
* If you **want to contribute** please feel free to [**submit pull requests**](https://github.com/algolia/voice-overlay-android/pull/new).
177+
* If you **have a feature request** please [**open an issue**](https://github.com/algolia/voice-overlay-android/issues/new).
178+
* If you use the **Voice Overlay** in your app, we would love to hear about it! Drop us a line on [discourse](https://discourse.algolia.com/) or [twitter](https://twitter.com/algolia).
48179

49-
# License
180+
## License
50181

51-
InstantSearch Android Voice is [MIT licensed](LICENSE.md).
182+
The VoiceOverlay is available under the MIT license. See the [LICENSE file](./LICENSE) for more info.

app/src/main/kotlin/com/algolia/instantsearch/voice/demo/MainActivity.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener
5656
private fun showVoiceDialog() {
5757
getPermissionDialog()?.dismiss()
5858
(getVoiceDialog() ?: VoiceInputDialogFragment()).let {
59-
it.setSuggestions("Hey, I just met you",
60-
"And this is crazy",
61-
"But here's my number",
62-
"So call me maybe"
59+
it.setSuggestions(
60+
"Phone case",
61+
"Running shoes"
6362
)
6463
it.show(supportFragmentManager, Tag.Voice.name)
6564
}

docs/demo.gif

25.1 MB
Loading

docs/listen.gif

1.57 MB
Loading

docs/nopermission.jpg

218 KB
Loading

docs/permission.jpg

184 KB
Loading

docs/speak.gif

11.8 MB
Loading

0 commit comments

Comments
 (0)