twitchtts/README.md

426 lines
16 KiB
Markdown
Raw Permalink Normal View History

2022-08-10 20:58:51 +02:00
# Twitch TextToSpeech Bot
2022-08-12 20:18:26 +02:00
![Latest Release](https://img.shields.io/gitlab/v/release/38486705) ![License](https://img.shields.io/gitlab/license/38486705) ![Maintenance](https://img.shields.io/maintenance/yes/2022)
2022-08-11 13:24:52 +02:00
A simple Twitch TTS bot (Web Speech API)
2022-08-10 20:58:51 +02:00
2022-08-12 03:57:36 +02:00
## Description
2022-08-10 20:58:51 +02:00
2022-08-23 19:29:30 +02:00
The goal of this project is to provide a simple to use Text to Speech IRC bot. It's mainly focused on Twitch, but might be easily adapt to other IRC chats as well. Anyway, right now some parts are Twitch specific (like `CAP REQ :twitch.tv/commands twitch.tv/tags`). There are some other projects providing TTS for IRC based chats, like [IRC Radio (TTS)](https://play.google.com/store/apps/details?id=com.earthflare.android.ircradio&hl=en&gl=US), but they often are missing moderation features like Black-/Whitelists or deletion of single messages, before they are read. Therefore I created my own TTS bot, providing those features. Another very important aspect was that you should use almost any device capable running an HTML5-webbrowser as output. Therefore the bot uses a client-server "architecture". You can run the bot - for example - on your IRL server, but use your phone as output device. A mobile only solution always have the disadvantage of loosing messages, e.g. when your mobile connection drops.
2022-08-10 20:58:51 +02:00
2022-08-12 03:57:36 +02:00
The project consits of a very simple IRC client, which monitors the incoming messages. If a valid`!tts` command is detected the message will send into a queue. Depending on your config it will wait there a few seconds for deletion by you/your moderators. If nobody deletes the message, it will send into another queue. This queue will get fetched by the HTML frontend, which will be delivered by an internal webserver (backend). The HTML frontend will use the [Web Speech API](https://wicg.github.io/speech-api/) included in any modern webbrowser to read the incoming TTS message. When this is done it will report back to the webserver and the message will be removed from the queue.
The server part is written in Python. The TTS part is written in Javascript.
By using Javascript for the actual TTS part it's not only very easy to access the Web Speech API and the underlying Speech features of your OS, it also makes it possible to use a wide range of devices to actually play the TTS output. You can start the backend on your PC/Server and open the frontend on your Android/iOS tablet or Mobile Phone. If you expose the backend to the internet (I would recommend to use a reverse proxy, rather than exposing the backend directly) you can also use the TTS bot on the go (e.g. your IRL setup).
(⃰sender is not on the blacklist, message is not too long, etc.)
## Getting Started
### Dependencies
* Browser with Web Speech API support
* Web Speech API Voices (usually already included in your OS and/or browser)
* If you use `tts.py` see `requirements.txt`. If you use `tts.exe` all dependencies are included.
### Installing
1. Clone the repo, or download and unzip the newest [Release](https://gitlab.com/gpvkt/twitchtts/-/releases)
2. Rename/copy `config-dist.yml` to `config.yml`
2022-08-19 03:10:38 +02:00
3. Adapt `config.yml` to your needs. See `Configuration` for details.
2022-08-12 03:57:36 +02:00
### Configuration
2022-08-10 20:58:51 +02:00
2022-08-19 03:10:38 +02:00
Please use `UTF-8` as encoding, when editing `config.yml`.
Example:
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
``` lang=yaml
2022-08-10 20:58:51 +02:00
irc:
channel: "#gpkvt"
username: "ttsbot"
oauth_token: "oauth:ohkoace0wooghue8she9xaN0nooSau"
server: "irc.chat.twitch.tv"
clearmsg_timeout: 10
http:
port: 80
bind: "localhost"
bot:
2022-08-12 18:54:40 +02:00
start_enabled: True
2022-08-10 20:58:51 +02:00
subonly: False
modonly: False
message_length: 200
2022-08-24 18:03:57 +02:00
language: de
2022-08-10 20:58:51 +02:00
2022-10-23 16:19:38 +02:00
features:
quote: True
pick: True
vote: True
wiki: True
wikitts: True
wikisentences: 3
random: True
version: True
ping: True
2022-08-10 20:58:51 +02:00
messages:
2022-08-12 10:36:46 +02:00
toff: "TTS is now inactive."
ton: "TTS is now active."
2022-10-23 16:56:30 +02:00
wikitoff: "Wiki TTS is now inactive."
wikiton: "Wiki TTS is now active."
2022-08-10 20:58:51 +02:00
too_long: "Sorry, your TTS message is too long."
disabled: "Sorry, TTS is disabled right now."
denied: "Sorry, you are not allowed to use TTS."
subonly: "Sorry, TTS is a sub-only feature."
whitelist: "Sorry, you are not allowed to use TTS."
ready: "TTS bot alpha ready!"
says: "says"
2022-08-12 18:54:40 +02:00
votestart: "Quickvote started. Send #yourchoice to participate."
voteend: "Quickvote ended. The results are:"
votenobody: "Nobody casted a vote. :("
2022-08-13 09:19:26 +02:00
voteresult: "Voting has ended. The result is:"
2022-08-12 18:54:40 +02:00
votes: "Votes"
2022-08-25 01:55:04 +02:00
pickstart: "Pick started. Send #pickme to participate."
pickresult: "Pick ended. The results are:"
picknone: "Nobody was picked. :("
2022-08-20 18:43:40 +02:00
quotenotfound: "Sorry, no quote found."
quoteaddedprefix: "Quote:"
quoteaddedsuffix: "added."
2022-08-24 18:03:57 +02:00
wiki_too_many: "Sorry, there are too many possible results. Try a more narrow search."
wiki_no_result: "Sorry, there was an error fetching the wikipedia answer."
2022-08-20 18:44:16 +02:00
2022-08-10 20:58:51 +02:00
log:
level: "INFO"
usermapping:
gpkvt: "gpk"
whitelist:
```
2022-08-12 03:59:34 +02:00
#### Explanation
2022-08-10 20:58:51 +02:00
2022-08-12 03:59:34 +02:00
##### irc
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
* `channel`: Channel you want to monitor (e.g. #gpkvt)
* `username`: The bots username (e.g. gpkvt)
* `oauth_token`: The bots OAUTH-Token (e.g. oauth:ohkoace0wooghue8she9xaN0nooSau)
* `server`: Twitch IRC server to be used (default should be fine)
* `clearmsg_timeout`: Time to wait for an moderator to delete a message, before it's added to the TTS queue
2022-08-10 20:58:51 +02:00
2022-08-12 21:10:05 +02:00
You can generate your `oauth_token` by leaving the value empty when starting `tts.exe/tts.py`. The integrated webserver will then provide an OAuth-Generator. Due to limitations to the `redirect_url` parameter used by twitch, this is only possible if you use Port `8080` or `80` as `http:bind`. If you use a different port, you will need to use another [Twitch OAuth Generator](https://html.duckduckgo.com/html/?q=twitch+oauth+token+generator). The bot will need `chat:edit` and `chat:read` permissions.
2022-08-12 18:54:40 +02:00
Please note that the `oauth_token` is valid for approximately 60 days. If it become invalid the bot will not connect anymore and you will have to renew the token.
2022-08-12 03:59:34 +02:00
##### http
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
* `port`: Internal Webserver Port to listen to (e.g. 8080)
* `bind`: Interface/IP to bind server to (e.g. localhost)
2022-08-10 20:58:51 +02:00
2022-08-12 03:59:34 +02:00
##### bot
2022-08-12 18:54:40 +02:00
2022-08-13 16:23:36 +02:00
* `start_enabled`: Enable the bot on start? If `False` you need to use `!ton` first to make TTS work.
* `subonly`: If `True` only Subs can use TTS
* `modonly`: If `True` only Mods can use TTS
* `message_length`: Maximum allowed message length for TTS
2022-08-24 18:03:57 +02:00
* `language`: Language for `!wiki` command
2022-08-10 20:58:51 +02:00
2022-10-23 16:19:38 +02:00
##### features
* `quote`: Enable/Disable `!quote` function
* `pick`: Enable/Disable `!pick` function
* `wiki`: Enable/Disable `!wiki` function
* `wikitts`: Enable/Disable audio output for `!wiki` function
* `wikisentences`: Number of sentences fetched by `!wiki` function
* `random`: Enable/Disable `!random` function
* `version`: Enable/Disable `!version` function
* `ping`: Enable/Disable `!ping` function
2022-10-23 16:56:30 +02:00
Please note, the text output from `!wiki` might been shorter that the TTS output. This is due to the Twitch chat message length restriction. Therefore the `wikisentences` option might not have any effects, when `wikitts` is set to `False`.
Please also note that every `.` in the wikipedia result is counted as a sentence. This might cause issues with certain date-formats, e.g. if `wikisentences` is set to `1` and `bot:language` is set to `de` the command `!wiki douglas adams` will only return:
```text
Douglas Noël Adams (* 11.
```
Therefore the recommended minimum value for `wikisentences` is `3`.
2022-08-12 03:59:34 +02:00
##### messages
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
* `toff`: The bots reply when `!toff` is used.
* `ton`: The bots reply when `!ton` is used.
2022-10-23 16:56:30 +02:00
* `wikitoff`: The bots reply when `!wikitoff` is used.
* `wikiton`: The bots reply when `!wikiton` is used.
2022-08-13 16:23:36 +02:00
* `too_long`: The bots reply if message exceeds `message_length`
* `disabled`: The bots reply if TTS is disabled
* `denied`: The bots reply if the user is not allowed to use TTS
* `subonly`: The bots reply if `subonly` is active and the user isn't one.
* `whitelist`: The bots reply if `whitelist` is set and user isn't on the list.
* `ready`: The bots init message
* `says`: Prefix to add between username and message
2022-08-25 01:55:04 +02:00
* `votestart`: Message when a quickvote was started.
* `voteend`: Message when a quickvote ends.
* `votenobody`: Message when quickvote ends, but nobody has voted.
2022-08-18 16:45:11 +02:00
* `voteresult`: Prefix for the result (will be read out).
2022-08-13 16:23:36 +02:00
* `votes`: Suffix to vote count.
2022-08-25 01:55:04 +02:00
* `pickstart`: Message when `!pick` was started.
* `pickresult`: Message when `!pick` ends.
* `picknone`: Message if nobody was picked.
2022-08-18 16:45:11 +02:00
* `quotenotfound`: Message if requests quote wasn't found.
* `quoteaddedprefix`: Prefix for `Quote <number> added` message.
* `quoteaddedsuffix`: Suffix for `Quote <number> added` message.
2022-08-24 18:03:57 +02:00
* `wiki_too_many`: Message if `!wiki` command has more than one result.
* `wiki_no_result`: Message if `!wiki` command hasn't a valid result.
2022-08-10 20:58:51 +02:00
2022-08-12 03:59:34 +02:00
##### log
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
* `level`: The loglevel, valid values are: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
2022-08-10 20:58:51 +02:00
2022-08-12 18:54:40 +02:00
Do not use `DEBUG` in a production environment.
2022-08-12 03:59:34 +02:00
##### usermapping
2022-08-10 20:58:51 +02:00
Use this section to define key:value pairs of usernames. The first value is the Twitch username, the second value is how the bot should pronouce the user, when reading the message. This is helpfull if you have regulars with numbers or strangs chars in the name. You can add new/change entries on the fly without restarting the bot (changes took up to 60 seconds).
2022-08-11 20:04:01 +02:00
Please note: The key (real username) MUST be lowercase.
2022-08-12 03:59:34 +02:00
##### whitelist
2022-08-10 20:58:51 +02:00
You can add a whitelist section to `config.yml`, a whitelist will override any other settings like `subonly` and `modonly`. Only users on the whitelist are allowed to use `!tts`. Broadcasters and mods can temporarily add users (including themselfs) to the whitelist by using the `!ptts` command, though.
A whitelist looks as follows:
2022-08-13 16:23:36 +02:00
``` lang=yaml
2022-08-10 20:58:51 +02:00
whitelist:
- gpkvt
- foo
- bar
```
2022-08-11 12:14:13 +02:00
To disable the whitelist, remove it from `config.yml` completely. If you just leave `whitelist:` without entries, everyone must be whitelisted using `!ptts` (even broadcaster and mods). The permit is temporary until the bot restarts or (whichever happens first) if the user is removed from the whitelist using `!dtts`.
2022-08-10 20:58:51 +02:00
2022-08-11 20:04:01 +02:00
Please note: Usernames MUST be lowercase.
2022-08-12 03:57:36 +02:00
### Executing program
2022-08-10 20:58:51 +02:00
2022-08-13 16:23:36 +02:00
Execute `tts.exe` (or `tts.py` if you have Python installed), open the TTS webpage in your browser (the URL depends on your `bind` and `port` configuration, usually it's just `http://localhost`). Click the `Init` button at the button of the TTS webpage (you should hear `Init complete`).
2022-08-10 20:58:51 +02:00
Connect to the configured Twitch channel and send a message starting with `!tts`. After a few seconds (depending on your `clearmsg_timeout` config), the message should be read.
2022-08-12 10:19:00 +02:00
### Additional Commands
2022-08-10 20:58:51 +02:00
Additional commands (broadcaster and mods only) are:
2022-08-13 16:23:36 +02:00
* `!ping`: Check if bot is alive (the bot should reply: `Pong!`)
2022-08-27 11:30:39 +02:00
* `!version`: Print the bot version
2022-08-13 16:23:36 +02:00
* `!toff`: Turn TTS off (will also empty the current TTS queue)
* `!ton`: Turn TTS back on
2022-10-23 16:56:30 +02:00
* `!wton`: Turn on TTS for `!wiki`
* `!wtoff`: Turn off TTS for `!wiki`
2022-08-13 16:23:36 +02:00
* `!dtts <username>`: Disable TTS for the given user
* `!ptts <username>`: Allow TTS for the given user
2022-08-23 14:13:58 +02:00
* `!usermap <username> <spoken name>`: Add an entry to the usermapping in `config.yml`
* `!delay <int>`: Adjust the `clearmsg_timeout` in `config.yml`
2022-08-11 12:14:13 +02:00
2022-08-12 18:54:40 +02:00
### Additional features
2022-08-27 11:30:39 +02:00
You can enable/disable any feature in your `config.yml`:
``` lang=yaml
features:
quote: False
pick: False
vote: False
wiki: False
2022-10-23 16:19:38 +02:00
wikitts: False
2022-08-27 11:30:39 +02:00
random: False
version: True
ping: True
```
The default is enabled.
2022-08-13 09:19:26 +02:00
#### !quickvote
2022-08-25 20:56:51 +02:00
A simple vote system.
**Usage:**
2022-08-25 21:04:57 +02:00
1. Broadcaster/Mods: `!quickvote <message>`
2. User: `#choice`
3. Broadcaster/Mods: `!quickvote`
2022-08-25 20:56:51 +02:00
**Example:**
``` lang=text
mod: !quickvote Is pizza hawaii any good? #yes/#no
chat: #no
mod: !quickvote
bot: The result is: #no
```
If a message is given by the Mods it will be repeated every 60 seconds, so everyone keeps in mind, that a vote is still active.
#### !pick
Randomly choose users from chat (who wants to participate).
**Usage:**
2022-08-25 21:04:57 +02:00
1. Broadcaster/Mods: `!pick <int>`
2. User: #pickme
3. Broadcaster/Mods: `!pick`
2022-08-25 20:56:51 +02:00
**Example:**
``` lang=text
mod: !pick 3
user1: #pickme
user2: #pickme
user3: #pickme
user4: #pickme
user5: #pickme
mod: !pick
bot: The picked users are: user5, user3, user1
```
2022-08-13 09:19:26 +02:00
#### !random
2022-08-25 20:56:51 +02:00
Picks a random line from a file.
2022-08-12 18:54:40 +02:00
2022-08-25 20:56:51 +02:00
**Usage:**
2022-08-18 16:45:11 +02:00
2022-08-25 21:04:57 +02:00
* Broadcaster/Mod: `!random <file>`
2022-08-18 16:45:11 +02:00
2022-08-25 20:56:51 +02:00
You can use multiple files, if you call `!random foo` the bot fetch the random line from a file called `random_foo.txt`, `!random bar` will use the file `random_bar.txt` and so on. If no `<file>` is given the command use the file `random.txt`.
**Example:**
2022-08-18 16:45:11 +02:00
``` lang=text
2022-08-25 20:56:51 +02:00
mod: !random
bot: This is a random message
2022-08-18 16:45:11 +02:00
```
#### !addquote
2022-08-25 20:56:51 +02:00
The `!addquote` command adds a new line to `quotes.txt`.
**Usage:**
2022-08-25 21:04:57 +02:00
* Chat: `!addquote <username> <quote>`
2022-08-25 20:56:51 +02:00
**Example:**
``` lang=text
chat: !addquote gpkvt This is a very funny quote.
bot: Quote #1 was added.
```
2022-08-25 21:30:28 +02:00
#### !smartquote / !sq
2022-08-25 20:56:51 +02:00
Picks a random/specific line from `quotes.txt`.
**Usage:**
2022-08-25 21:04:57 +02:00
* Chat: `!smartquote`
* Chat: `!smartquote <linenumber>`
* Chat: `!smartquote <searchstring>`
2022-08-25 21:30:28 +02:00
* Chat: `!sq`
* Chat: `!sq <linenumber>`
* Chat: `!sq <searchstring>`
2022-08-25 21:04:57 +02:00
2022-08-25 21:30:28 +02:00
(`!sq` is an alias for `!smartquote`)
2022-08-25 20:56:51 +02:00
**Example:**
``` lang=text
chat: !smartquote
bot: This is a random quote
chat: !smartquote 1000
bot: This is quote #1000
chat: !smartquote something stupid
bot: This is a quote containing something stupid (or similiar)
```
The format of `quotes.txt` looks as follows:
``` lang=text
#1: "the quote" -username/game (date)
```
2022-08-18 16:45:11 +02:00
2022-08-24 18:03:57 +02:00
#### !wiki
2022-08-25 20:56:51 +02:00
Search the Wikipedia.
2022-08-18 16:45:11 +02:00
2022-08-25 20:56:51 +02:00
**Usage:**
2022-08-25 21:04:57 +02:00
* Chat: `!wiki <searchstring>`
2022-08-25 20:56:51 +02:00
**Example:**
2022-08-25 01:55:04 +02:00
2022-08-25 20:56:51 +02:00
``` lang=text
2022-08-25 21:00:41 +02:00
chat: !wiki 42 answer
2022-08-25 20:56:51 +02:00
bot: 42 is the "Answer to the Ultimate Question of Life, the Universe, and Everything".
```
2022-08-25 01:55:04 +02:00
2022-08-12 03:57:36 +02:00
## Build
If you prefer to build your own `tts.exe` instead of using the shipped one, you can do as follows:
2022-08-13 16:23:36 +02:00
* Install Python 3
* Install pyinstaller: `pip install pyinstaller`
* Install the required dependencies: `pip install -r requirements.txt -v`
* Create the executeable: `pyinstaller --onefile tts.py`
2022-08-12 03:57:36 +02:00
## Voices
2022-08-11 12:14:13 +02:00
2022-08-12 03:57:36 +02:00
The voices available depend on your Operating System and/or browser. On some systems only a default voice is available and the `Select voice` dropdown might stay empty or will only show entries after you clicked the `Init` button. Some Android devices will show a huge list of voices, but sounds the same no matter which one you choose.
2022-08-11 12:14:13 +02:00
2022-08-11 23:13:48 +02:00
On Windows you can install additional voices via `Settings` > `Time & language` > `Speech` > `Add voices` or by simply run `Add speech voices`.
2022-08-11 12:14:13 +02:00
2022-08-23 19:26:23 +02:00
Do not use Online-Voices, as this will result in serious delays.
2022-08-11 13:20:56 +02:00
## Help
2022-08-11 12:14:13 +02:00
2022-08-12 04:32:47 +02:00
Feel free to use the [Issuetracker](https://gitlab.com/gpvkt/twitchtts/-/issues) or send an [E-Mail](mailto:contact-project+gpvkt-twitchtts-38486705-issue-@incoming.gitlab.com) if you experience any problems.
2022-08-11 13:20:56 +02:00
## Authors
2022-08-12 04:32:47 +02:00
[@gpkvt](mailto:contact-project+gpvkt-twitchtts-38486705-issue-@incoming.gitlab.com)
2022-08-11 13:20:56 +02:00
## Version History
2022-08-12 19:01:35 +02:00
See [CHANGELOG.md](https://gitlab.com/gpvkt/twitchtts/-/blob/main/CHANGELOG.md)
2022-08-11 13:20:56 +02:00
## License
2022-08-13 11:26:18 +02:00
This project is licensed under the GPLv3 License - see [LICENSE](https://gitlab.com/gpvkt/twitchtts/-/blob/main/LICENSE) for details.
2022-08-11 13:20:56 +02:00
## Acknowledgments
2022-08-12 04:11:31 +02:00
### Ideas and Testing
2022-08-13 16:23:36 +02:00
* [GERBrowny and community](https://www.twitch.tv/gerbrowny/) ![Emote](https://static-cdn.jtvnw.net/emoticons/v2/303172270/static/light/1.0)
* [DerZugger and community](https://www.twitch.tv/derzugger/) ![Emote](https://static-cdn.jtvnw.net/emoticons/v2/302400142/static/light/1.0)
* [Timmeh74 and community](https://www.twitch.tv/timmeh74/) ![Emote](https://static-cdn.jtvnw.net/emoticons/v2/300192675/static/light/1.0)
2022-08-12 04:11:31 +02:00
### Libraries
2022-08-23 14:13:58 +02:00
* [Python](https://www.python.org/)
* [jQuery](https://jquery.org/)
* [Bootstrap](https://getbootstrap.com/)
2022-08-11 13:20:56 +02:00
* [PyYAML](https://pyyaml.org/)
2022-08-20 18:42:31 +02:00
* [requests](https://requests.readthedocs.io/en/latest/)
* [fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy)
2022-08-24 20:55:54 +02:00
* [wikipedia](https://github.com/goldsmith/Wikipedia)
2022-08-11 13:20:56 +02:00
* [pyinstaller](https://pyinstaller.org/)
2022-08-11 13:32:23 +02:00
## Disclaimer
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Twitch Interactive, Inc.