Note
Mochaspeech is not production-ready and is not meant to be used that way. This is just a fun alternative server. You can use it on your own laptop absolutely don't put it on someone else's laptop.
Mochaspeech is a speech server compatible with most speech-dispatcher clients. Basically clients tell it to speak and it speaks.
I made it purely for fun and enjoyment.
No. An SSIP implementation would implement the SSIP fully according to the spec. This is a custom server attempting to merely work with most SSIP clients, and it cuts corners in a ton of ways (no history, no proper pausing/resuming, no module/voice systems, tons of lying to clients, and so on) in ordere to achieve that goal.
Is this supposed to replace speechd?
No. Speechd's still better at being reliable. Read the note at the top.
I don't know. It seems to work with Firefox, spd-say, and Orca. But
because I don't implement the SSIP fully (read
Isn't this an SSIP implementation?), there's bound to be some
client that breaks under mochaspeech.
if I had to advertise it
- size: Mochaspeech is 792 lines of Python as of writing this. Now compare that to the ever so humble speechd, with 30k-40k lines of code as of writing
- lightness: It just executes a command at the end of the day
- configurablility: You can customize the exact commands it runs and the pitch/volume/rate ranges through good old Python and a crappy list template system that i made in 5 minutes
- matureness: Mochaspeech is young. Speechd is over 20 years old.
- reliability: Speechd may be large, but at least it's almost guaranteed to work. Mochaspeech hasn't been tested as much.
- jank: Mochaspeech is pretty janky.
For most people no. This is just a nichhe fun project.
Unsupported. This is for Linux and the BSDs. Go away
Git clone this repo to /opt/mochaspeech. You're done for the installation.
If you wanna quickly just start the server run python -m mochaspeech while you're in
/opt/mochaspeech.
Now to set it up to automatically run in the background, which is init-specific:
DO NOT INSTALL IT AS A SYSTEM SERVICE DO NOT PLEASE DONT NO
Create this file at ~/.config/systemd/user/mochaspeech.service for each user that needs it:
[Unit]
Description=mochaspeech speech server
PartOf=graphical-session.target
After=graphical-session.target
[Service]
Type=simple
WorkingDirectory=/opt/mochaspeech
ExecStart=python3 -m mochaspeech
Restart=on-failure
[Install]
WantedBy=graphical-session.target
Then systemctl --user daemon-reload and systemctl --user enable --now mochaspeech!
To verify it's running run in your terminal:
python3 -c '
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/run/user/'"$(id -u)"'/speech-dispatcher/speechd.sock")
s.sendall(b"MOCHASPEECH\r\n")
print(s.recv(4096).decode())
s.close()
'If it says 266- followed by a version number, mochaspeech is running correctly.
If it instead says 500 ERR INVALID COMMAND or
ConnectionRefusedError: [Errno 111] Connection refused, it isn't running and either you did
something wrong or I did something wrong.
I only have instructions for systemd, sorry! it's the only thing I used, you're probably smart enough if you use something else anyway.
You can definitely figure it out ❤️
Go to /opt/mochaspeech or wherever you cloned mochaspeech and git pull.
Try installing espeak-ng first. It uses that by default and is stupid and won't fallback if
it isn't there. Also make sure it's in your PATH.
Otherwise check the logs. Idk. If it looks like something I broke open a GitHub issue.
DO NOT MODIFY config_example.py ABSOLUTELY DO NOT DON'T DON'T PLEASE DONT NO DONT
MODIFY IT DONT PLEAES DONT PLEASE
Go to /opt/mochaspeech or wherever you cloned mochaspeech and create a file in the
mochaspeech directory called config.py. Copy the contents of config_example.py into it.
Note you'll need to know Python to configure this. If you don't know Python just use the default config don't trouble yourself with this.
Variables (all of these are required):
Literal string. Should ideally identify your config but can be whatever.
List of either strings or integers. These are command arguments for SPEAK mode (plain text multiple lines).
The command this runs should be blocking, should run the audio on its own, and should quit as soon as speech ends. If it plays in the background mochaspeech will break. If it outputs audio data instead of playing on its own mochaspeech will break. If it waits for more data after speaking mochaspeech will break.
The strings get passed down literally and the integers get replaced dynamically.
Meaning of the integers:
1: The text data (omit this if your command supports stdin text input, mochaspeech knows what to do)2: Pitch3: Rate/speed4: Volume/amplitude
Literal string. The encoding that should be used for stdin communication with the SPEAK mode process.
Should be an encoding name Python can recognize. Just leave this as utf-8 unless you know what
you're doing.
Function. Takes an integer from -100 to 100 and outputs an integer or float. Should transform the input value to a value the SPEAK mode command can understand.
Function. Same thing as speak_rate but for pitch.
Function. Same thing as speak_rate but for volume.
List of either strings or integers. These are commands arguments for CHAR mode (char-by-char, pronouncing punctuation).
See speak_template.
Literal string. Same thing as speak_encoding but for CHAR mode.
Functions. Same as speak_rate, speak_pitch, and
speak_volume (respectively) but for CHAR mode.
List of either strings or integers. These are commands arguments for SSML mode (speak SSML)
See speak_template.
Literal string. Same thing as speak_encoding but for SSML mode.
Functions. Same as speak_rate, speak_pitch, and
speak_volume (respectively) but for SSML mode.
4 days
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU Affero General Public License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version. See the LICENSE file for more info.