Skip to content
Open
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
2 changes: 1 addition & 1 deletion android-buildsystem
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ private void closeMediaPlayer() {
}

@Override
public void checkStatus(SynthesizerListener.OnStatusChecked listener) {
public void checkStatus(Activity activity, SynthesizerListener.OnStatusChecked listener) {
logger.i(TAG, "check AmazonSpeech status");
prepare(synthesizerStatus -> {
final DescribeVoicesResult voicesResult = mAmazonSpeechClient.describeVoices(new DescribeVoicesRequest()
.withLanguageCode(mLanguageCode));
Expand All @@ -196,6 +197,10 @@ public void checkStatus(SynthesizerListener.OnStatusChecked listener) {
});
}

@Override
public void testStatus(SynthesizerListener.OnStatusChecked listener) {
}

@Override public void loadInstallation(Activity activity, SynthesizerListener.OnStatusChecked listener) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,22 @@ public AndroidSpeechSynthesizer(Application application,
}

@Override
public void checkStatus(SynthesizerListener.OnStatusChecked listener) {
public void checkStatus(Activity activity, SynthesizerListener.OnStatusChecked listener) {
logger.i(TAG, "check TTS status");

Intent checkData = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

boolean checkDataExists = checkData.resolveActivityInfo(activity.getPackageManager(), 0) != null;

if (checkDataExists) {
activity.startActivityForResult(checkData, CHECK_TTS_REQUEST_CODE);
} else {
listener.execute(NOT_AVAILABLE_ERROR);
}
}

@Override
public void testStatus(SynthesizerListener.OnStatusChecked listener) {
try {
prepare(status -> checkTTS(listener));
} catch (Exception e) {
Expand Down Expand Up @@ -111,9 +125,12 @@ public void loadInstallation(Activity activity, SynthesizerListener.OnStatusChec
final Locale speechLanguage = getConfiguration().getSpeechLanguage();
final TextToSpeech[] _tts = { null };
TextToSpeech.OnInitListener ttsListener = status -> {
int result = _tts[0].isLanguageAvailable(speechLanguage);
_tts[0].shutdown();
_tts[0] = null;
TextToSpeech _currentTts = _tts[0];
if (_currentTts == null) {
_currentTts = new TextToSpeech(application, status1 -> {});
}
int result = _currentTts.isLanguageAvailable(speechLanguage);
_currentTts.shutdown();
if (ArraysKt.contains(new int[] {TextToSpeech.LANG_AVAILABLE,
TextToSpeech.LANG_COUNTRY_AVAILABLE,
TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE}, result)) {
Expand All @@ -133,14 +150,10 @@ public void onActivityResumed(Activity activity) {
_tts[0] = new TextToSpeech(application, ttsListener);
}
});
Intent checkData = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
boolean checkDataExists = checkData.resolveActivityInfo(activity.getPackageManager(), 0) != null;
if (checkDataExists)
activity.startActivity(checkData);
Intent installData = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
boolean installDataExists = installData.resolveActivityInfo(activity.getPackageManager(), 0) != null;
if (installDataExists)
activity.startActivity(checkData);
activity.startActivity(installData);
else {
shutdown();
logger.e(TAG, "NOT_AVAILABLE_ERROR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public GoogleSpeechSynthesizer(Application application,

@WorkerThread
@Override
public void checkStatus(SynthesizerListener.OnStatusChecked listener) {
logger.i(TAG, "checkStatus and check language");
public void checkStatus(Activity activity, SynthesizerListener.OnStatusChecked listener) {
logger.i(TAG, "check GoogleSpeech status and language");
// At this stage, we only want to check whether the api works and the language is available
try (TextToSpeechClient ttsClient = generateFromRawFile(
application, getConfiguration().getGoogleCredentialsResourceFile())) {
Expand All @@ -100,6 +100,10 @@ application, getConfiguration().getGoogleCredentialsResourceFile())) {
}
}

@Override
public void testStatus(SynthesizerListener.OnStatusChecked listener) {
}

@Override public void loadInstallation(Activity activity, SynthesizerListener.OnStatusChecked listener) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ abstract class BaseSpeechSynthesizer implements SpeechSynthesizer {
this.logger = logger;
}


abstract void executeOnEngineReady(String utteranceId, String text);

abstract void playSilence(String utteranceId, long durationInMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ConversationalFlow extends RequiredPermissions {
* @see SynthesizerListener.OnStatusChecked
* @see SynthesizerListener.Status
*/
void checkSpeechSynthesizerStatus(Context context, SynthesizerListener.OnStatusChecked listener);
void checkSpeechSynthesizerStatus(Activity activity, SynthesizerListener.OnStatusChecked listener);

/**
* Checks whether the Recognizer is available and returns a {@link RecognizerListener.Status}
Expand All @@ -45,7 +45,11 @@ public interface ConversationalFlow extends RequiredPermissions {
* @see RecognizerListener.OnStatusChecked
* @see RecognizerListener.Status
*/
void checkSpeechRecognizerStatus(Context context, RecognizerListener.OnStatusChecked listener);
void checkSpeechRecognizerStatus(Activity activity, RecognizerListener.OnStatusChecked listener);

boolean isCheckingSpeech(int requestCode);

void checkSpeech(int resultCode, SynthesizerListener.OnStatusChecked listener);

/**
* Reuses the already set {@link ComponentConfig} allowing you to update only specific parts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.app.Application;
import android.content.Context;
import android.media.AudioManager;
import android.speech.tts.TextToSpeech;

import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
Expand All @@ -14,6 +15,8 @@

import chattylabs.android.commons.internal.ILogger;

import static chattylabs.conversations.SynthesizerListener.Status.NOT_AVAILABLE_ERROR;

final class ConversationalFlowImpl implements ConversationalFlow {

static class Instance {
Expand Down Expand Up @@ -124,21 +127,33 @@ public void onIncomingCallRinging() {
}

@Override
public void checkSpeechSynthesizerStatus(Context context, SynthesizerListener.OnStatusChecked listener) {
final Application application = (Application) context.getApplicationContext();
public void checkSpeechSynthesizerStatus(Activity activity, SynthesizerListener.OnStatusChecked listener) {
final Application application = (Application) activity.getApplicationContext();
initDependencies(application);
createSpeechSynthesizerInstance(application);
speechSynthesizer.checkStatus(listener);
speechSynthesizer.checkStatus(activity, listener);
}

@Override
public void checkSpeechRecognizerStatus(Context context, RecognizerListener.OnStatusChecked listener) {
final Application application = (Application) context.getApplicationContext();
public void checkSpeechRecognizerStatus(Activity activity, RecognizerListener.OnStatusChecked listener) {
final Application application = (Application) activity.getApplicationContext();
initDependencies(application);
createSpeechRecognizerInstance(application);
speechRecognizer.checkStatus(listener);
}

@Override public boolean isCheckingSpeech(int requestCode) {
return requestCode == SpeechSynthesizer.CHECK_TTS_REQUEST_CODE;
}

@Override public void checkSpeech(int resultCode, SynthesizerListener.OnStatusChecked listener) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
speechSynthesizer.testStatus(listener);
} else {
listener.execute(NOT_AVAILABLE_ERROR);
}
}

private void createSpeechSynthesizerInstance(Context context) {
try {
if (speechSynthesizer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
public interface SpeechSynthesizer {

int CHECK_TTS_REQUEST_CODE = 775;

String EMPTY = "<EMPTY>";

String VOICE_MALE = "#male";
Expand All @@ -22,7 +24,9 @@ public interface SpeechSynthesizer {

void setDefaultVoice();

void checkStatus(SynthesizerListener.OnStatusChecked listener);
void checkStatus(Activity activity, SynthesizerListener.OnStatusChecked listener);

void testStatus(SynthesizerListener.OnStatusChecked listener);

void loadInstallation(Activity activity, SynthesizerListener.OnStatusChecked listener);

Expand Down