Python script that plays a random audio file based on input received from a livestream chat.
This script relies on the following:
- mpv to play audio files
- An IRC client: the script currently supports log files generated by Chatty but it can easily be adapted to handle logs from other clients such as HexChat
While the IRC client is logging messages from a channel, the script will continuously check the corresponding log file to see when someone has said something and then trigger an audio file thanks to mpv (cmd/cli) based on how the script was configured.
First, you will need to install Python, mpv and Chatty.
Python can be downloaded here. During the installation, if you're a Windows user, make sure you check the checkbox that says Add python.exe to PATH
.
mpv can be downloaded here. For Windows users, I suggest clicking the first link that takes you to SourceForge and then clicking the green button that says Download Latest Version
. You will get a .zip file which you can extract into an empty folder. Double click on the .bat file you just extracted and let it do its thing.
Chatty can be downloaded here. It requires Java so make sure you also install that if not already the case.
The installation itself is straightforward so I won't go into the details here but after launching it for the first time and logging into your Twitch account, you will need to go to Main
> Settings
> Log to file
and have the following configured:
- in the
Message Types
section, uncheck everything except for theChat Messages
checkbox, - in the
Other Settings
section, uncheck theLock files
checkbox, - hit the
Save
button to save and close the settings window.
- Download this repository and unzip it anywhere you want on your computer
- Add your audio files inside the
audio
folder - Assuming you have already joined a Twitch chat in Chatty, you can then run the script by either running the
python main.py
command or, for Windows users, by right-clicking themain.py
and selectOpen with
>Python
- A window will show up where you can:
- fill in the name of the channel you want to track (aka one that you joined in Chatty)
- select the way you want quotes to be played;
- percentage chance per message sent -> make sure the value specified is a number between 1 and 100
- command -> put any string you want and an audio file will play whenever someone's message contains that string
- Chaos mode is a mode that doesn't wait for the previous audio file to finish, so it leads to a chaotic mess where audio files overlap
- The script will automatically update the contents of the
quote.txt
file with the info on who triggered an audio file in case you want to capture that in OBS (Add
>Text
>Read from file
). There is also a large rectangle inside the window that contains the same info if you prefer capturing that.
One error I came across so far was when I tested it on Linux and the tk
module was missing. In my case I just had to install it with the following command (i use arch btw)
sudo pacman -S tk
For other distros it might be named differently, like python-tk
or something like that.