Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stack overflow with TTS #482

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. Take a look

**Warning:** Features marked as *alpha* may change or be removed in a future release without notice. Use with caution.

<!-- ## [Unreleased] -->
## [Unreleased]

### Fixed

#### Navigator

* [#459](https://github.com/readium/swift-toolkit/issues/459) Fixed the stack overflow issue that occurred when running the text-to-speech on an EPUB file with many empty resources.


## [3.0.0-alpha.2]

Expand Down
15 changes: 7 additions & 8 deletions Sources/Navigator/TTS/PublicationSpeechSynthesizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,14 @@ public class PublicationSpeechSynthesizer: Loggable {
/// Loads the utterances for the next publication `ContentElement` item in the given `direction`.
private func loadNextUtterances(_ direction: Direction) async -> Bool {
do {
guard let content = try await publicationIterator?.next(direction) else {
return false
}

let nextUtterances = try tokenize(content)
.flatMap { utterances(for: $0) }
var nextUtterances: [Utterance] = []
while nextUtterances.isEmpty {
guard let content = try await publicationIterator?.next(direction) else {
return false
}

if nextUtterances.isEmpty {
return await loadNextUtterances(direction)
nextUtterances = try tokenize(content)
.flatMap { utterances(for: $0) }
}

utterances = CursorList(
Expand Down
Loading