mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
Spoken directions use a voice in Gearslip's language
The turns are worded in Gearslip's language, but the speech engine read them with its default voice, which may speak another one (#70).
This commit is contained in:
1 parent
d42bc0d00a
commit
97555396c0
1 file changed
+13
@@ -71,6 +71,9 @@ object DirectionsVoice {
|
||||
tts = TextToSpeech(appContext) { status ->
|
||||
ttsReady = status == TextToSpeech.SUCCESS
|
||||
if (!ttsReady) GearslipLog.w("guidance: text-to-speech didn't start (status $status)")
|
||||
// The turns are worded in Gearslip's language; the engine's default voice may be
|
||||
// another one, and read German words with an English voice (issue #70).
|
||||
else speakIn(appContext?.resources?.configuration?.locales?.get(0))
|
||||
}.apply {
|
||||
setOnUtteranceProgressListener(object : UtteranceProgressListener() {
|
||||
override fun onStart(utteranceId: String?) {}
|
||||
@@ -81,6 +84,16 @@ object DirectionsVoice {
|
||||
}
|
||||
}
|
||||
|
||||
/** Keeps the engine's own voice when it has none for [locale]. */
|
||||
private fun speakIn(locale: java.util.Locale?) {
|
||||
val engine = tts ?: return
|
||||
locale ?: return
|
||||
val result = engine.setLanguage(locale)
|
||||
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
|
||||
GearslipLog.w("guidance: the speech engine has no ${locale.displayLanguage} voice - using its default")
|
||||
}
|
||||
}
|
||||
|
||||
/** The car opened its directions sink: start following the map app's turns. */
|
||||
fun attach(link: AudioLink, musicIsOurs: () -> Boolean) {
|
||||
this.link = link
|
||||
|
||||
Reference in new issue
Block a user