johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
5.93k stars 273 forks source link

Flatpak TTS does not work #1126

Closed Nitrousoxide closed 9 months ago

Nitrousoxide commented 9 months ago

Describe the bug TTS does not work in the flatpak.

To Reproduce Steps to reproduce the behavior:

  1. Double click on some text to start TTS there
  2. Select "Speak from Here"
  3. Get error stating "Text-to-Speech Error: Make sure Speech Dispatcher is installed and working on your system"

Expected behavior TTS should start.

Screenshots image

Version:

Additional context I have speech dispatcher installed (via a distrobox container and exported to ~/.local/bin) on this host but the flatpak container does not pick it up. Though the flatpak should probably have that dependency installed in its own container if it's an actual dep.

❯ which speech-dispatcher
/home/Brian/.local/bin/speech-dispatcher

Documents/Repos/distrobox-assemble 
❯ speech-dispatcher test
[Tue Nov 14 11:02:21 2023 : 109042] speechd: Speech Dispatcher 0.11.5 starting
johnfactotum commented 9 months ago

It should work if speech-dispatcher is actively running on the host, but it does appear that it can't activate speech-dispatcher automatically if it isn't running.

fastrizwaan commented 9 months ago

Are there any good human like tts voices who can do tts with foliate?

fastrizwaan commented 9 months ago

Just found out https://github.com/rhasspy/piper

The voice samples, they are too good https://rhasspy.github.io/piper-samples/

if we could get it working as a flatpak, that'd be nice.

fastrizwaan commented 9 months ago

I've installed rpm-ostree install speech-dispatcher-utils and spd-say Hello! does output "hello" audio on fedora 39 silverblue.

but with flatpak foliate even with talkname and full system access, it is throwing error:

here's the error output:

rizvan@fedora:~$ flatpak run --talk-name=org.freedesktop.Flatpak --filesystem=host com.github.johnfactotum.Foliate 

(com.github.johnfactotum.Foliate:2): com.github.johnfactotum.Foliate-CRITICAL **: 02:01:41.528: Error: Error connecting to /run/user/1000/speech-dispatcher/speechd.sock: Gio.IOErrorEnum: Could not connect: Connection refused
connect@resource:///com/github/johnfactotum/Foliate/speech.js:28:19
init@resource:///com/github/johnfactotum/Foliate/speech.js:83:30
send@resource:///com/github/johnfactotum/Foliate/speech.js:114:20
stop@resource:///com/github/johnfactotum/Foliate/speech.js:146:21
#init@resource:///com/github/johnfactotum/Foliate/tts.js:64:21
speak@resource:///com/github/johnfactotum/Foliate/tts.js:79:19
#onSelection@resource:///com/github/johnfactotum/Foliate/book-viewer.js:879:34
selection@resource:///com/github/johnfactotum/Foliate/book-viewer.js:461:53
@resource:///com/github/johnfactotum/Foliate/book-viewer.js:215:23
registerHandler/<@resource:///com/github/johnfactotum/Foliate/webview.js:172:25
_init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34

^C
Nitrousoxide commented 9 months ago

I've installed rpm-ostree install speech-dispatcher-utils and spd-say Hello! does output "hello" audio on fedora 39 silverblue.

but with flatpak foliate even with talkname and full system access, it is throwing error:

Just to test this some more.
I gave spd-say a long bit of text to speak out and while it was still speaking started foliate's TTS.

 spd-say Hello, this is a test to see how well things are working.  Id like to see how long they will continue to talk

It did successfully speak. I've not added/removed any permissions for foliate's flatpak. I would note there are no controls for TTS though, so once you start it you can't stop it unless you back out of the book entirely.

I assume it is trying to tap into the speechd.sock which only temporarily exists while an ongoing speech command is running.

If you try to start tts in foliate without first starting spd-say in a terminal with some text line you get this (on fedora 39 workstation)

❯ flatpak run com.github.johnfactotum.Foliate

(com.github.johnfactotum.Foliate:2): com.github.johnfactotum.Foliate-WARNING **: 17:28:46.322: Gio.IOErrorEnum: Access to service is disallowed 'SERVICE'
getURIFromTracker@resource:///com/github/johnfactotum/Foliate/library.js:30:30
get@resource:///com/github/johnfactotum/Foliate/library.js:56:42
getBookFromIdentifier@resource:///com/github/johnfactotum/Foliate/library.js:105:36
getBook@resource:///com/github/johnfactotum/Foliate/library.js:101:21
activate@resource:///com/github/johnfactotum/Foliate/library.js:394:63
activate@resource:///com/github/johnfactotum/Foliate/library.js:322:18
_init/GLib.MainLoop.prototype.runAsync/</<@resource:///org/gnome/gjs/modules/core/overrides/GLib.js:266:34
johnfactotum commented 9 months ago

I gave spd-say a long bit of text to speak out

You can use spd-say -e to keep the server running without speaking.

I assume it is trying to tap into the speechd.sock which only temporarily exists while an ongoing speech command is running.

In older versions of speech-dispatcher, yes. But it supports socket activation starting from 0.11.4.

The Ubuntu package for speech-dispatcher installs a /usr/lib/systemd/user/speech-dispatcher.socket (see https://packages.ubuntu.com/mantic/amd64/speech-dispatcher/filelist). I just tried the Snap version on Ubuntu (which has strict confinement, so as with Flatpak it can't directly spawn speech-dispatcher), and TTS works.

But the packages for Debian (https://packages.debian.org/bookworm/amd64/speech-dispatcher/filelist) and Arch Linux (https://archlinux.org/packages/extra/x86_64/speech-dispatcher/files/) don't install this file. Presumably this is the case on Fedora as well.

If you try to start tts in foliate without first starting spd-say in a terminal with some text line you get this

No, that warning is about Tracker. I think it happens if you don't have tracker-miners installed. SERVICE here refers to dbus:org.freedesktop.Tracker3.Miner.Files.

johnfactotum commented 9 months ago

Just tried the Flatpak on Ubuntu, and it seems to be working.

johnfactotum commented 9 months ago

Added a section in troubleshooting with an explanation and a workaround for this issue: https://github.com/johnfactotum/foliate/blob/gtk4/docs/troubleshooting.md#text-to-speech-doesnt-work

fastrizwaan commented 9 months ago

Thank you, starting speech-dispatcher --timeout 0 in a terminal then asking foliate to play works.

I'm really thankful for such a wonderful ebook reader, and you've really done a great job with foliate.

Do you by any chance know how to change the speech-dispatcher to use "piper" voices which are really good. the robotic voice is not so cool you know.

johnfactotum commented 9 months ago

Do you by any chance know how to change the speech-dispatcher to use "piper" voices which are really good.

See https://github.com/brailcom/speechd/issues/866

qoijjj commented 5 months ago

Thank you, starting speech-dispatcher --timeout 0 in a terminal then asking foliate to play works.

I'm really thankful for such a wonderful ebook reader, and you've really done a great job with foliate.

Do you by any chance know how to change the speech-dispatcher to use "piper" voices which are really good. the robotic voice is not so cool you know.

Posting this here as well

https://github.com/Elleo/pied

fastrizwaan commented 5 months ago

@qoijjj thank you so much, I've installed voices using pied. they work.

in a terminal speech-dispatcher --timeout 0 start foliate and select text and choose 'Speak from Here'

@johnfactotum could you integrate or suggest users to use pied to get great voices.