|
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.OperationCanceledException;
|
|
|
|
import android.os.OperationCanceledException;
|
|
|
|
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
import android.speech.tts.TextToSpeech;
|
|
|
|
import android.speech.tts.UtteranceProgressListener;
|
|
|
|
import android.speech.tts.UtteranceProgressListener;
|
|
|
|
|
|
|
|
|
|
|
@ -35,10 +36,13 @@ import java.util.Map;
|
|
|
|
public class TTSHelper {
|
|
|
|
public class TTSHelper {
|
|
|
|
private static Integer status = null;
|
|
|
|
private static Integer status = null;
|
|
|
|
private static TextToSpeech instance = null;
|
|
|
|
private static TextToSpeech instance = null;
|
|
|
|
|
|
|
|
private static PowerManager.WakeLock wl = null;
|
|
|
|
private static final List<Runnable> queue = new ArrayList<>();
|
|
|
|
private static final List<Runnable> queue = new ArrayList<>();
|
|
|
|
private static final Map<String, Runnable> listeners = new HashMap<>();
|
|
|
|
private static final Map<String, Runnable> listeners = new HashMap<>();
|
|
|
|
private static final Object lock = new Object();
|
|
|
|
private static final Object lock = new Object();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final long MAX_WAKELOCK_DURATION = 3 * 60 * 1000L; // milliseconds
|
|
|
|
|
|
|
|
|
|
|
|
// https://developer.android.com/reference/android/speech/tts/TextToSpeech
|
|
|
|
// https://developer.android.com/reference/android/speech/tts/TextToSpeech
|
|
|
|
// https://android-developers.googleblog.com/2009/09/introduction-to-text-to-speech-in.html
|
|
|
|
// https://android-developers.googleblog.com/2009/09/introduction-to-text-to-speech-in.html
|
|
|
|
|
|
|
|
|
|
|
@ -50,6 +54,11 @@ public class TTSHelper {
|
|
|
|
final boolean flush,
|
|
|
|
final boolean flush,
|
|
|
|
final Runnable listener) {
|
|
|
|
final Runnable listener) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (wl == null) {
|
|
|
|
|
|
|
|
PowerManager pm = Helper.getSystemService(context, PowerManager.class);
|
|
|
|
|
|
|
|
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":tts");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Locale locale = (language == null ? Locale.getDefault() : new Locale(language));
|
|
|
|
Locale locale = (language == null ? Locale.getDefault() : new Locale(language));
|
|
|
|
|
|
|
|
|
|
|
|
final Runnable speak = new Runnable() {
|
|
|
|
final Runnable speak = new Runnable() {
|
|
|
@ -103,6 +112,7 @@ public class TTSHelper {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
status = null;
|
|
|
|
status = null;
|
|
|
|
instance = null;
|
|
|
|
instance = null;
|
|
|
|
|
|
|
|
wl.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -133,6 +143,7 @@ public class TTSHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
wl.acquire(MAX_WAKELOCK_DURATION);
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
Log.e(ex);
|
|
|
|
status = TextToSpeech.ERROR;
|
|
|
|
status = TextToSpeech.ERROR;
|
|
|
|