Skip to content

Commit

Permalink
Virtual Assistant Client - Support Keyword Barge-in, Correct Build Er…
Browse files Browse the repository at this point in the history
…ror, & Update Gradle (microsoft#3336)

* Fix strings xml file; update gradle

* Remove duplicate field declaration in configuration

* Support keyword barge-in during TTS playback w/ toggle
  • Loading branch information
olmidy authored May 12, 2020
1 parent bb343dc commit e24d14b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ There are two configuration files used to provide your environment settings.
"custom_commands_app_id": "", // Optional, if you are connecting to a Custom Commands application
"custom_voice_deployment_ids": "", // Optional, to point to custom voices
"custom_speech_recognition_endpoint_id": "", // Optional, to point to a customized speech recognition endpoint
"barge_in_supported": false, // Whether or not to listen to keyword while TTS is playing. If true, TTS playback stops once Keyword is verified.
"user_id": "android",
"user_name": "Android",
"locale": "en-us",
"keyword": "computer",
"enableKWS": false, // Keyword spotting
"linkedAccountEndpoint": "" // Optional if you enabled the Linked Accounts solution in the prerequisites
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class MainActivity extends BaseActivity
@BindView(R.id.kbd_image) ImageView kbdImage;
@BindView(R.id.animated_assistant) AppCompatImageView animatedAssistant;
@BindView(R.id.switch_enable_kws) SwitchCompat switchEnableKws;
@BindView(R.id.switch_enable_barge_in) SwitchCompat switchEnableBargeIn;
@BindView(R.id.nav_menu_set_as_default_assistant) TextView setDefaultAssistant;

// CONSTANTS
Expand All @@ -117,6 +118,7 @@ public class MainActivity extends BaseActivity
private boolean enableDarkMode;
private boolean keepScreenOn;
private boolean enableKws;
private boolean bargeInSupported;
private boolean isExpandedTextInput;
private boolean isCreated;// used to identify when onCreate() is complete, used with SwitchCompat

Expand All @@ -135,7 +137,9 @@ protected void onCreate(Bundle savedInstanceState) {
// Options hidden in the nav-drawer
Configuration speechConfig = configurationManager.getConfiguration();
enableKws = speechConfig.enableKWS;
bargeInSupported = speechConfig.bargeInSupported;
switchEnableKws.setChecked(enableKws);
switchEnableBargeIn.setChecked(bargeInSupported);

// NAV DRAWER
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
Expand Down Expand Up @@ -433,6 +437,17 @@ public void onCheckedChangedEnableKws(CompoundButton button, boolean checked){
}
}

@OnCheckedChanged(R.id.switch_enable_barge_in)
public void onCheckedChangedEnableBargeIn(CompoundButton button, boolean checked) {
if (isCreated) {
bargeInSupported = checked;

Configuration speechConfig = configurationManager.getConfiguration();
speechConfig.bargeInSupported = bargeInSupported;
configurationManager.setConfiguration(speechConfig);
}
}

public void setDarkMode(boolean enabled){
if (enableDarkMode != enabled) {
enableDarkMode = enabled;
Expand Down Expand Up @@ -514,6 +529,14 @@ public void onEventBotListening(BotListening event) {
// Note: the SpeechService will trigger the actual listening. Since the app needs to show a
// visual, the app needs to subscribe to this event and act on it.
showListeningAnimation();

if ((bargeInSupported)) {
try {
speechServiceBinder.stopAnyTTS();
} catch (RemoteException exception) {
Log.e(LOGTAG, exception.getMessage());
}
}
}

// EventBus: the user spoke and the app recognized intermediate speech
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@
android:paddingBottom="16dp"
android:text="@string/nav_menu_enable_kws"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_enable_barge_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="@string/nav_menu_enable_barge_in"/>

</LinearLayout>

</android.support.design.widget.NavigationView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@
android:paddingBottom="16dp"
android:text="@string/nav_menu_enable_kws"/>

<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_enable_barge_in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:text="@string/nav_menu_enable_barge_in"/>

</LinearLayout>

</android.support.design.widget.NavigationView>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@
<string name="nav_menu_enable_dark_mode" translatable="false">Enable dark mode</string>
-->
<string name="nav_menu_enable_kws" translatable="false">Enable KWS</string>
<string name="nav_menu_enable_barge_in" translatable="false">Enable Barge-In</string>

<!-- CONFIGURATION -->
<string name="configuration_service_key_hint">Speech Service Subscription Key</string>
<string name="configuration_service_region_hint">Speech Service Subscription Key Region</string>
<string name="configuration_custom_commands_hint">Custom Commands App ID</string>
<string name="configuration_voice_deployment_hint">Custom Voice Deployment IDs</string>
<<<<<<< HEAD
<string name="configuration_custom_sr_endpoint_hint">Custom Speech Recognition Endpoint ID</string>
=======
<string name="configuration_service_connection_hint">Speech Service Connection Endpoint</string>
>>>>>>> origin/master
<string name="configuration_bot_id_hint">Direct Line Speech Secret Key</string>
<string name="configuration_voice_name_hint">Voice Name</string>
<string name="configuration_user_id_hint">User From Id</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public Configuration getConfiguration(){
if (configuration.customSpeechRecognitionEndpointId == null) {
configuration.customSpeechRecognitionEndpointId = defaultConfiguration.customSpeechRecognitionEndpointId;
}
if (configuration.bargeInSupported == null) {
configuration.bargeInSupported = defaultConfiguration.bargeInSupported;
}
if (configuration.userId == null) {
configuration.userId = defaultConfiguration.userId;
}
Expand All @@ -78,7 +81,7 @@ public Configuration getConfiguration(){
configuration.keyword = defaultConfiguration.keyword;
}
if (configuration.enableKWS == null) {
configuration.enableKWS = false;
configuration.enableKWS = defaultConfiguration.enableKWS;
}
if (configuration.linkedAccountEndpoint == null) {
configuration.linkedAccountEndpoint = defaultConfiguration.linkedAccountEndpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

public class Configuration {

@SerializedName("custom_commands_app_id")
@Expose
public String customCommandsAppId;

@SerializedName("service_key")
@Expose
public String serviceKey;
Expand All @@ -33,6 +29,10 @@ public class Configuration {
@Expose
public String customSpeechRecognitionEndpointId;

@SerializedName("barge_in_supported")
@Expose
public Boolean bargeInSupported;

@SerializedName("locale")
@Expose
public String locale;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Aug 29 19:47:39 CST 2019
#Wed May 06 14:28:08 PDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 comments on commit e24d14b

Please sign in to comment.