Skip to content

Commit 9a12021

Browse files
committed
Refactored Conversation node names.
1 parent 6e7e1bf commit 9a12021

File tree

21 files changed

+261
-259
lines changed

21 files changed

+261
-259
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Part of the [Voice User Interaction SDK]().
1111

1212
The library wraps and combines single platform resources and builds
13-
a **Software Component** capable of create a communication flow with ease.
13+
a _Software Component_ capable of create a communication flow between a devices and a user with ease.
1414

1515
Besides, it also lets you choose between the following providers:
1616
like Android, Google Cloud,
@@ -27,6 +27,10 @@ like Android, Google Cloud,
2727

2828
## Why choosing this library?
2929

30+
The **Conversational Flow Component** is based on [Directed Graph](https://en.wikipedia.org/wiki/Directed_graph)
31+
which also allows [Directed Cycles](https://en.wikipedia.org/wiki/Cycle_(graph_theory))
32+
to create connected nodes that build a consistent flow.
33+
3034
Some devices don't have configured the resources you need to run a conversation in your app,
3135
a developer needs to learn and test quite a lot before even to start coding for voice capabilities, noise is impacting
3236
considerably the communication, android components force you to create a lot of boilerplate, some countries don't
@@ -82,7 +86,7 @@ or update some changes on the current one at anytime.
8286

8387
```java
8488
// Optional
85-
conversationalFlowComponent.updateVoiceConfig(
89+
conversationalFlowComponent.updateConfiguration(
8690
builder -> builder.setBluetoothScoRequired(() -> preferences.connectToBluetoothSco()).build());
8791
```
8892

@@ -94,10 +98,7 @@ to user preferences.
9498

9599
### Create a Conversation
96100

97-
The **Conversational Flow Component** is based on a [Directed Graph](https://en.wikipedia.org/wiki/Directed_graph)
98-
which also allows [Directed Cycles](https://en.wikipedia.org/wiki/Cycle_(graph_theory))
99-
to create connected nodes that build a consistent flow.
100-
<br/>You can use the `ConversationalFlowComponent` at any context level, both in an Activity and a Service.
101+
You can use the `ConversationalFlowComponent` at any context level, both in an Activity and a Service.
101102

102103
To create a conversation between the user and your app, you will create a set of `VoiceNode` objects and build a flow with them.
103104

@@ -115,7 +116,7 @@ VoiceMessage question = VoiceMessage.newBuilder().setText("Do you need help?").b
115116

116117
// We define the expected replies from the user.
117118
String[] expected = new String[]{ "Yes", "I think so", "Sure" };
118-
VoiceAction answers = VoiceAction.newBuilder().setExpectedResults(expected)
119+
VoiceMatch answers = VoiceMatch.newBuilder().setExpectedResults(expected)
119120
.setOnMatch(results -> conversation::next)
120121
.build();
121122
```

app/src/main/java/com/chattylabs/demo/voice/MainActivity.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.chattylabs.sdk.android.voice.GoogleSpeechSynthesizer;
3535
import com.chattylabs.sdk.android.voice.Peripheral;
3636
import com.chattylabs.sdk.android.voice.TextFilterForUrl;
37-
import com.chattylabs.sdk.android.voice.VoiceConfig;
37+
import com.chattylabs.sdk.android.voice.ComponentConfig;
3838

3939
import javax.inject.Inject;
4040

@@ -130,17 +130,17 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
130130
if (PermissionsHelper.isPermissionGranted(grantResults)) {
131131
serialThread.addTask(() -> {
132132
//component = ConversationalFlowModule.provideComponent();
133-
component.updateVoiceConfig(builder ->
133+
component.updateConfiguration(builder ->
134134
builder .setGoogleCredentialsResourceFile(() -> R.raw.credential)
135135
.setRecognizerServiceType(() ->
136136
ADDON_TYPE == R.id.addon_android ?
137-
VoiceConfig.RECOGNIZER_SERVICE_ANDROID_BUILTIN :
138-
VoiceConfig.RECOGNIZER_SERVICE_ANDROID_BUILTIN
137+
ComponentConfig.RECOGNIZER_SERVICE_ANDROID_BUILTIN :
138+
ComponentConfig.RECOGNIZER_SERVICE_ANDROID_BUILTIN
139139
)
140140
.setSynthesizerServiceType(() ->
141141
ADDON_TYPE == R.id.addon_android ?
142-
VoiceConfig.SYNTHESIZER_SERVICE_ANDROID_BUILTIN :
143-
VoiceConfig.SYNTHESIZER_SERVICE_GOOGLE_BUILTIN)
142+
ComponentConfig.SYNTHESIZER_SERVICE_ANDROID_BUILTIN :
143+
ComponentConfig.SYNTHESIZER_SERVICE_GOOGLE_BUILTIN)
144144
.build());
145145
component.setup(this, status -> {
146146
if (status.isAvailable()) {
@@ -331,7 +331,7 @@ private void initViews() {
331331
Toast.makeText(this, "Not connected to a Bluetooth device", Toast.LENGTH_LONG).show();
332332
return;
333333
}
334-
component.updateVoiceConfig(
334+
component.updateConfiguration(
335335
builder -> {
336336
builder.setBluetoothScoRequired(() ->
337337
peripheral.get(Peripheral.Type.BLUETOOTH).isConnected() && isChecked);

sdk-addon-android-speech/src/main/java/com/chattylabs/sdk/android/voice/AndroidSpeechRecognizer.java

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@
2020
import java.util.concurrent.Executors;
2121
import java.util.concurrent.locks.ReentrantLock;
2222

23-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.MIN_VOICE_RECOGNITION_TIME_LISTENING;
2423
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.OnRecognizerError;
2524
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.OnRecognizerMostConfidentResult;
2625
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.OnRecognizerPartialResults;
2726
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.OnRecognizerReady;
2827
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.OnRecognizerResults;
29-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_AFTER_PARTIALS_ERROR;
30-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_EMPTY_RESULTS_ERROR;
31-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_LOW_SOUND_ERROR;
32-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_NO_SOUND_ERROR;
33-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_RETRY_ERROR;
34-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_STOPPED_TOO_EARLY_ERROR;
35-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_UNAVAILABLE_ERROR;
36-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RECOGNIZER_UNKNOWN_ERROR;
37-
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RecognizerListenerContract;
28+
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.RecognizerListener;
3829
import static com.chattylabs.sdk.android.voice.ConversationalFlowComponent.selectMostConfidentResult;
3930

4031
public final class AndroidSpeechRecognizer implements ConversationalFlowComponent.SpeechRecognizer {
@@ -49,12 +40,12 @@ public final class AndroidSpeechRecognizer implements ConversationalFlowComponen
4940

5041
// Resources
5142
private final Application application;
52-
private final VoiceConfig config;
43+
private final ComponentConfig config;
5344
private final AndroidHandler mainHandler;
5445
private final AndroidAudioHandler audioHandler;
5546
private final BluetoothSco bluetoothSco;
5647
private final Intent speechRecognizerIntent;
57-
private final SpeechRecognizerCreator recognizerCreator;
48+
private final SpeechRecognizerCreator<android.speech.SpeechRecognizer> recognizerCreator;
5849
private final ExecutorService executorService;
5950
private SpeechRecognizer speechRecognizer;
6051

@@ -98,7 +89,7 @@ public void run() {
9889
});
9990
}
10091
};
101-
timeout.schedule(task, MIN_VOICE_RECOGNITION_TIME_LISTENING * 3);
92+
timeout.schedule(task, RecognizerListener.MIN_VOICE_RECOGNITION_TIME_LISTENING * 3);
10293
}
10394

10495
private void cleanup() {
@@ -134,7 +125,8 @@ public void onReadyForSpeech(Bundle params) {
134125
public void onError(int error) {
135126
logger.e(TAG, "ANDROID VOICE - error: " + getErrorType(error));
136127
// We consider 2 sec as timeout for non speech
137-
boolean stoppedTooEarly = (System.currentTimeMillis() - elapsedTime) < ConversationalFlowComponent.MIN_VOICE_RECOGNITION_TIME_LISTENING;
128+
boolean stoppedTooEarly = (System.currentTimeMillis() - elapsedTime) <
129+
ConversationalFlowComponent.RecognizerListener.MIN_VOICE_RECOGNITION_TIME_LISTENING;
138130
// Start checking for the error
139131
OnRecognizerError errorListener = getOnError();
140132
int soundLevel = getSoundLevel();
@@ -143,27 +135,27 @@ public void onError(int error) {
143135
cancel();
144136
if (errorListener != null) {
145137
if (needRetry(error)) {
146-
errorListener.execute(RECOGNIZER_UNAVAILABLE_ERROR, error);
138+
errorListener.execute(RecognizerListener.RECOGNIZER_UNAVAILABLE_ERROR, error);
147139
}
148140
else if (stoppedTooEarly) {
149-
errorListener.execute(RECOGNIZER_STOPPED_TOO_EARLY_ERROR, error);
141+
errorListener.execute(RecognizerListener.RECOGNIZER_STOPPED_TOO_EARLY_ERROR, error);
150142
}
151143
else if (soundLevel == NO_SOUND) {
152-
errorListener.execute(RECOGNIZER_NO_SOUND_ERROR, error);
144+
errorListener.execute(RecognizerListener.RECOGNIZER_NO_SOUND_ERROR, error);
153145
}
154146
else if (soundLevel == LOW_SOUND) {
155-
errorListener.execute(RECOGNIZER_LOW_SOUND_ERROR, error);
147+
errorListener.execute(RecognizerListener.RECOGNIZER_LOW_SOUND_ERROR, error);
156148
}
157149
else if (intents > 0) {
158-
errorListener.execute(RECOGNIZER_AFTER_PARTIALS_ERROR, error);
150+
errorListener.execute(RecognizerListener.RECOGNIZER_AFTER_PARTIALS_ERROR, error);
159151
}
160152
else if (isTryAgain()) {
161153
errorListener.execute(error == SpeechRecognizer.ERROR_NO_MATCH ?
162-
RECOGNIZER_UNKNOWN_ERROR :
163-
RECOGNIZER_RETRY_ERROR, error);
154+
RecognizerListener.RECOGNIZER_UNKNOWN_ERROR :
155+
RecognizerListener.RECOGNIZER_RETRY_ERROR, error);
164156
}
165157
else { // Restore ANDROID VOICE
166-
errorListener.execute(RECOGNIZER_UNKNOWN_ERROR, error);
158+
errorListener.execute(RecognizerListener.RECOGNIZER_UNKNOWN_ERROR, error);
167159
}
168160
}
169161
}
@@ -192,7 +184,7 @@ public void onResults(Bundle results) {
192184
logger.e(TAG, "ANDROID VOICE - NO results");
193185
OnRecognizerError listener = getOnError();
194186
reset();
195-
if (listener != null) listener.execute(RECOGNIZER_EMPTY_RESULTS_ERROR, -1);
187+
if (listener != null) listener.execute(RecognizerListener.RECOGNIZER_EMPTY_RESULTS_ERROR, -1);
196188
}
197189
}
198190

@@ -226,7 +218,7 @@ private boolean needRetry(int error) {
226218
// Log stuff
227219
private ILogger logger;
228220

229-
AndroidSpeechRecognizer(Application application, VoiceConfig configuration,
221+
AndroidSpeechRecognizer(Application application, ComponentConfig configuration,
230222
AndroidAudioHandler audioHandler, BluetoothSco bluetoothSco,
231223
SpeechRecognizerCreator recognizerCreator, ILogger logger) {
232224
this.application = application;
@@ -322,7 +314,7 @@ public void shutdown() {
322314
}
323315

324316
@Override
325-
public void listen(RecognizerListenerContract... listeners) {
317+
public void listen(RecognizerListener... listeners) {
326318
logger.i(TAG, "ANDROID VOICE - start listening");
327319
handleListeners(listeners);
328320
// Check whether Sco is connected or required
@@ -382,10 +374,10 @@ private void startListening() {
382374
});
383375
}
384376

385-
private void handleListeners(RecognizerListenerContract... listeners) {
377+
private void handleListeners(RecognizerListener... listeners) {
386378
recognitionListener.reset();
387379
if (listeners != null && listeners.length > 0) {
388-
for (RecognizerListenerContract item : listeners) {
380+
for (RecognizerListener item : listeners) {
389381
if (item instanceof OnRecognizerReady) {
390382
recognitionListener.setOnReady((OnRecognizerReady) item);
391383
}

sdk-addon-android-speech/src/main/java/com/chattylabs/sdk/android/voice/AndroidSpeechSynthesizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class AndroidSpeechSynthesizer extends BaseSpeechSynthesizer {
4444
private OnSynthesizerSetup onSynthesizerSetup;
4545

4646
AndroidSpeechSynthesizer(Application application,
47-
VoiceConfig configuration,
47+
ComponentConfig configuration,
4848
AndroidAudioHandler audioHandler,
4949
BluetoothSco bluetoothSco,
5050
ILogger logger) {

0 commit comments

Comments
 (0)