readium / swift-toolkit

A toolkit for ebooks, audiobooks and comics written in Swift
https://readium.org/mobile/
BSD 3-Clause "New" or "Revised" License
256 stars 101 forks source link

TTS: Preference to force override the language set in the HTML resources #279

Open morismoris opened 1 year ago

morismoris commented 1 year ago

Bug Report

It looks like the system only gives the possibility to listen to the ebook in the language set in the file's LANG metatag: if I try to change the language, the ebook is still read in the language set by the LANG meta tag.

Unfortunately, we don't know which and how many ebooks in our catalog could have this problem, so we need to know how to work around the problem and provide an acceptable quality text-to-speech to our iOS readers.

What happened?

The text-to-speech allows me to listen to it only in English: if I set Italian, this change is not accepted.

Expected behavior

I'd like to set Italian.

How to reproduce?

I attach an epub, a classic of Italian literature in which the metatag is set on EN. Canne_al_vento test lingua.zip

Environment

I can't test with the TestApp ('main' or 'develop' branch), because the TestApp fails with the error: Missing file: "/META-INF/container.xml"

Development environment

macOS: 13.2.1 platform: x86_64 carthage: 0.38.0 Xcode 14.2 Build version 14C18

Testing device

Additional context

mickael-menu commented 1 year ago

The Readium TTS allows to override the publication language, except if it's explicitly set in the HTML document. Unfortunately this book is badly authored as the HTML documents have xml:lang="en" despite the content being in Italian:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html>
<html xml:lang="en">
<p>Di là andarono alla festa dello Spirito Santo. Il cieco sapeva bene il tempo d’ogni festa e l’itinerario da seguirsi ed era lui che guidava il compagno.

We plan to improve the TTS navigator by adding a preference to force override the content language, but I have no ETA for this change.

In the meantime, I think that if you switch the utterance.language and config.defaultLanguage precedence here it should work:

https://github.com/readium/swift-toolkit/blob/e1735017b7c46ac62599e63adde961367a987b6f/Sources/Navigator/TTS/PublicationSpeechSynthesizer.swift#L265-L269

Note that this means that multilingual books won't behave correctly if you set config.defaultLanguage, as the elements languages will be ignored.

morismoris commented 1 year ago

Ok, it's works... but how can I preselect the right Language in TTSSettings? It seems that it doesn't work anycase also in Epub with the right lang.

mickael-menu commented 1 year ago

I don't understand what you mean?

morismoris commented 1 year ago

I open the book IMG_0549

I start the TTS IMG_0550

I open the TTS Settings, no language is preselected IMG_0551