Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Speech Suppression] add in configurations to suppress speech for a time interval #33

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Speech Suppression] add in configurations to suppress speech for a g…
…iven time interval
  • Loading branch information
junjuew committed Apr 21, 2020
commit 39da7f41d16463e6b13cdb8a83ed16b691701caf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum DeviceModel {
public static final boolean LOAD_AUDIO = false;

public static boolean SHOW_SUBTITLES = false;
// The time interval in which duplicate TTS speeches are suppressed
public static int SPEECH_DEDUP_INTERVAL = 5;

// high level sensor control (on/off)
public static boolean SENSOR_VIDEO = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public class GabrielClientActivity extends Activity implements TextToSpeech.OnIn
private EngineInput engineInput;
final private Object engineInputLock = new Object();
private FrameSupplier frameSupplier;

// TTS
private String previousTts = "";
private long previousTtsTime = 0;

private boolean isRunning = false;
private boolean isFirstExperiment = true;
Expand Down Expand Up @@ -358,8 +361,10 @@ public void onClick(DialogInterface dialog, int which) {
dialog.show();
} else if (msg.what == NetworkProtocol.NETWORK_RET_SPEECH) {
String ttsMessage = (String) msg.obj;

if (tts != null && !ttsMessage.equals(previousTts)){
// suppress the duplicate message if they are adjacent and comes in a short interval
boolean isSuppressed = ttsMessage.equals(previousTts) && (
(System.currentTimeMillis()/1000 - previousTtsTime) < Const.SPEECH_DEDUP_INTERVAL);
if (tts != null && !isSuppressed){
Log.d(LOG_TAG, "tts to be played: " + ttsMessage);
tts.setSpeechRate(1.0f);
String[] splitMSGs = ttsMessage.split("\\.");
Expand All @@ -377,6 +382,7 @@ public void onClick(DialogInterface dialog, int which) {
tts.speak(splitMSGs[i].toString().trim(),TextToSpeech.QUEUE_ADD, null);
}
previousTts = ttsMessage;
previousTtsTime = System.currentTimeMillis() / 1000;
}
subtitleView = (TextView) findViewById(R.id.subtitleText);
subtitleView.setText(ttsMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import android.app.AlertDialog;
import android.content.SharedPreferences;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -54,6 +57,7 @@ public class ServerListActivity extends AppCompatActivity {
SeekBar seekBar = null;
TextView intervalLabel = null;
Switch subtitles = null;
EditText speechDedupInterval = null;
CameraManager camMan = null;
private SharedPreferences mSharedPreferences;
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 23;
Expand Down Expand Up @@ -105,12 +109,8 @@ protected void onCreate(Bundle savedInstanceState) {
mSharedPreferences=getSharedPreferences(getString(R.string.shared_preference_file_key),
MODE_PRIVATE);


// app options
subtitles = (Switch) findViewById(R.id.subtitles);




subtitles.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Const.SHOW_SUBTITLES = isChecked;
Expand All @@ -121,6 +121,34 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
});
subtitles.setChecked(mSharedPreferences.getBoolean("option:subtitles", false));

speechDedupInterval = (EditText) findViewById(R.id.speechDedupInterval);
speechDedupInterval.addTextChangedListener(
new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
try {
Const.SPEECH_DEDUP_INTERVAL = Integer.parseInt(s.toString());
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt("option:speechDedupInterval",
Const.SPEECH_DEDUP_INTERVAL);
editor.commit();
} catch (NumberFormatException e) {
Log.e(this.getClass().getName(), "Invalid int string (" +
s.toString() + ").. Failed to set SPEECH_DEDUP_INTERVAL");
}
}
}
);
Const.SPEECH_DEDUP_INTERVAL = mSharedPreferences.getInt("option:speechDedupInterval",
Const.SPEECH_DEDUP_INTERVAL);
speechDedupInterval.setText(String.valueOf(Const.SPEECH_DEDUP_INTERVAL));

camMan = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

initServerList();
Expand Down
21 changes: 21 additions & 0 deletions android-client/app/src/main/res/layout/activity_serverlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
android:layout_marginLeft="20dp"
android:text="@string/subtitles" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/speechDedup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textColor="@color/navigationBarColor"
android:text="@string/speech_dedup" />

<EditText
android:id="@+id/speechDedupInterval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:inputType="number"
android:maxLines="1" />
</LinearLayout>

<TextView
android:id="@+id/textServerList"
Expand Down
1 change: 1 addition & 0 deletions android-client/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<!-- activity_serverlist.xml -->
<string name="options_heading">Options</string>
<string name="subtitles">Show Subtitles for Audio Feedback</string>
<string name="speech_dedup">Period to Suppress Identical Speech (in Seconds)</string>
<string name="serverlist_heading">Server List</string>
<string name="name_subheading">Name</string>
<string name="address_subheading">Address</string>
Expand Down