Shut down TTS when recording is stopped

This commit is contained in:
jannis 2020-01-05 16:56:31 +01:00
parent ce06613b28
commit 5e5203848d

View File

@ -31,6 +31,8 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -38,8 +40,6 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.speech.tts.TextToSpeech;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import org.mapsforge.core.graphics.Paint; import org.mapsforge.core.graphics.Paint;
@ -110,6 +110,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
tts = new TextToSpeech(this, (int status) -> { tts = new TextToSpeech(this, (int status) -> {
ttsReady = status == TextToSpeech.SUCCESS && tts.setLanguage(Locale.getDefault())>=0; ttsReady = status == TextToSpeech.SUCCESS && tts.setLanguage(Locale.getDefault())>=0;
Log.d("Recorder", "TTS-ready: " + ttsReady);
}); });
infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value)); infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value));
infoViews[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value)); infoViews[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value));
@ -214,6 +215,8 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
final String text = distanceCaption + ": " + distance + ". " final String text = distanceCaption + ": " + distance + ". "
+ avgSpeedCaption + ": " + avgSpeed; + avgSpeedCaption + ": " + avgSpeed;
Log.d("Recorder", "TTS speak: " + text);
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
lastSpokenUpdateTime = duration; lastSpokenUpdateTime = duration;
@ -335,9 +338,16 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
@Override @Override
protected void onDestroy() { protected void onDestroy() {
recorder.stop(); recorder.stop();
saveIfNotSaved(); // Important saveIfNotSaved(); // Important to save
// Clear map
mapView.destroyAll(); mapView.destroyAll();
AndroidGraphicFactory.clearResourceMemoryCache(); AndroidGraphicFactory.clearResourceMemoryCache();
// Shutdown TTS engine
ttsReady = false;
tts.shutdown();
super.onDestroy(); super.onDestroy();
if(wakeLock.isHeld()){ if(wakeLock.isHeld()){
wakeLock.release(); wakeLock.release();