Skip to content

Commit

Permalink
Fix #2922 (Check how accurate position of non-bible tts is saved when…
Browse files Browse the repository at this point in the history
… pausing)
  • Loading branch information
tuomas2 committed Oct 14, 2023
1 parent 4f304fa commit ae660d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class SpeakControl @Inject constructor(
private fun speakAny(bookRef: String, osisRef: String) {
val book = Books.installed().getBook(bookRef)
try {
if(book is SwordBook) {
if((book as? SwordBook)?.bookCategory == BookCategory.BIBLE) {
val verse = (book.getKey(osisRef) as RangedPassage).getVerseAt(0)
speakBible(book, verse)
} else {
Expand Down Expand Up @@ -406,7 +406,11 @@ class SpeakControl @Inject constructor(
if (!automated) {
prepareForSpeaking()
}
ttsServiceManager.continueAfterPause()
if(!ttsServiceManager.initialized) {
continueLastPosition()
} else {
ttsServiceManager.continueAfterPause()
}
}

fun stop(willContinueAfter: Boolean=false, force: Boolean=false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ class TextToSpeechServiceManager @Inject constructor(
}
}

var initialized = false

@Synchronized
fun continueAfterPause() {
try {
Expand Down Expand Up @@ -505,6 +507,7 @@ class TextToSpeechServiceManager @Inject constructor(
val am = application.getSystemService(Context.AUDIO_SERVICE) as AudioManager

private fun startSpeaking() {
initialized = true
Log.i(TAG, "about to send some text to TTS")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(audioFocusRequest == null) {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/net/bible/service/sword/BookAndKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package net.bible.service.sword
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import net.bible.android.control.page.OrdinalRange
import net.bible.android.control.versification.toVerseRange
import net.bible.android.view.activity.bookmark.LabelEditActivity
import net.bible.service.common.CommonUtils.json
import net.bible.service.common.ordinalRangeFor
Expand All @@ -29,6 +30,7 @@ import org.crosswire.jsword.book.Book
import org.crosswire.jsword.book.Books
import org.crosswire.jsword.passage.DefaultKeyList
import org.crosswire.jsword.passage.Key
import org.crosswire.jsword.passage.RangedPassage
import org.crosswire.jsword.passage.RestrictionType
import java.lang.UnsupportedOperationException
val BookAndKey.ordinalRange: IntRange? get() = document?.ordinalRangeFor(key)
Expand All @@ -42,7 +44,10 @@ class BookAndKeySerialized(
) {
val bookAndKey: BookAndKey get () {
val book = Books.installed().getBook(document)
val key = book.getKey(key)
var key = book.getKey(key)
if(key is RangedPassage) {
key = key.toVerseRange
}
return BookAndKey(key, book, ordinalRange, htmlId)
}

Expand Down

0 comments on commit ae660d2

Please sign in to comment.