Inspired by DougDoug's 'Twitch Plays D&D' and stumpster project, but modifiedy to fit Loretta's stream better
- Clone or download this library.
- Download and install python.
- Install the necessary python libraries (run
pip install -r requirements.txt
).
- Create a Twitch chat bot application at the Twitch Developers page.
- Set the OAuth Redirect URL to
http://localhost:17563
. - Make a copy of the
example_config.json
file and rename it toconfig.json
. - Copy and paste the
Client ID
andClient Secret
from the Twitch application management page into theconfig.json
file in theapp_id
andapp_secret
sections. - Add your Twitch channel to the
target_channel
.
- Go to Tools > WebSocket Server Settings.
- Generate a password and copy that into the
obs_settings password
inconfig.json
. - Set your
Scene
name inconfig.json
. - In order for dice rolling to work you will need to have an dice animation, static dice image, and a text field set up as sources inside OBS. By default, these OBS sources are expected to be named
Dice Animation
,Dice Background
, andDice Result
respectively. You can change these expected source names in theconfig.json
file if you would like. Edit theobs_dice_animation_length
to match your animation length and theobs_dice_result_length
for how long you would like the result to be displayed. - In the
characters
section ofconfig.json
you will need to give your characters a name and assign them a voice (voices are covered below in the AWS section). In order for the character to move an image while they are talking the OBS image source should be named<character> Image
. As an example, if I set up a character namedSteven
then the OBS image associated with that character should be namedSteven Image
. - In OBS your character image will also need to have a Color Correction filter assigned to it. By default, this is expected to be named
Opacity
but you can change this name in theconfig.json
file if you would like.
Note: Cloud computing can incur costs, make sure you understand the AWS Polly pricing before configuring.
- Create a new AWS account.
- Create an IAM user in AWS to access AWS Polly through by:
- In the AWS console search for the
IAM
component and click on it. - Click on
Users
and click onCreate User
. - Give this user a name (e.g.
Polly
) and clickNext
. - Click on
Attach policies directly
and search forAmazonPollyFullAccess
. Select it and clickNext
. - Click
Create User
- Back in the IAM Users page, click on the new user and click on
Security Credentials
. - Scroll down and in the
Access Keys
section click onCreate access key
. - Click on
Local code
, clickNext
, and then clickCreate access key
. - Copy the access key and secret access key to the
config.json
fields underaws_settings
.
- In the AWS console search for the
- Modify your
character
voices inconfig.json
according to the voices that you would like to use from the AWS Polly voicelist. By default, only voices that are available asStandard Voices
can be used since these have much more AWS free credits available.
Note: ElevenLabs is easier to set up and generally has better voices but offers much less free usage than AWS. The free tier of ElevenLabs only allows for 10000 characters instead of AWS which allows for millions.
- Create a new ElevenLabs account
- Click on your profile in the top right.
- Copy your API key to the
config.json
file in theeleven_labs_settings
section. - In the
config.json
mark theenabled
field in AWS tofalse
and theenabled
field for Eleven Labs totrue
. - Modify your
character
voices inconfig.json
according to the names of the voices in Eleven Labs.
The owner of the channel can send the following commands in their Twitch chat to facilitate running games:
- !roll
- This will roll the default dice that you have listed in the
config.json
file. By default, this is set in theexample_config.json
to be 1d20.
- This will roll the default dice that you have listed in the
- !roll
X
dY
- This will roll X dice of Y sides. As an example,
!roll 2d6
will roll 2 six-sided dice.
- This will roll X dice of Y sides. As an example,
- !swap
- This will remove all current users from characters and assign new ones from users who have been active in chat over the last five minutes
- !mute
- This will prevent new voice and text for the characters from being processed (the messages sent while muted will be lost)
- !unmute
- Undoes the !mute command
Note: Running a ChatGPT-led game will have some cost associated with it since using the OpenAI API has an associated (albeit low) cost. With the default GPT-3.5 the maximum cost per message and response should be limited to $0.014. This is enough for approximately ~45 minutes of streaming before any history is lost.
Follow steps above to set up Twitch, OBS, and AWS with the following changes:
- Instead of having specific characters set in OBS you will need to have generic image NPC fields
NPC0
toNPC3
and text fieldsNPC0 Chat
toNPC3 Chat
- Ignore the
character
fields in theconfig.json
as these will not be used, ChatGPT will make new characters and automatically assign voices to them as they are created. - Set up an additional field for
GM
andGM Chat
- Open an account over at OpenAI's platform page
- Add funds to the account
- Generate an API key from your API key page
- Add this field to the
chatgpt_settings
section of yourconfig.json
and setenabled
totrue
- If you'd like to modify the scenario that ChatGPT is DM'ing for, adjust the
self.systemmsg
in thechatgptdm.py
file. By default, ChatGPT is presented with the following scenario:You are a game master who is leading a party though a campaign of Dungeons and Dragons. The players are: a fighter named Roger, a cleric named Karrix, and a wizard named Sylvania. They are currently in a tavern.
- Find your auth cookie using the steps here to use Bing to generate images using DALLE-3.
- Add this auth cookie to the
config.json
file in thebing_settings
Note: This is the default to use since it's free, but a little bit slower than OpenAI.
The owner of the channel can send the following commands in their Twitch chat to facilitate running games:
- !roll
- This will roll the default dice that you have listed in the
config.json
file. By default, this is set in theexample_config.json
to be 1d20.
- This will roll the default dice that you have listed in the
- !roll
X
dY
- This will roll X dice of Y sides. As an example,
!roll 2d6
will roll 2 six-sided dice.
- This will roll X dice of Y sides. As an example,
Any chatters in the channel can submit these commands:
-
!submit
- This command will be used by chat to submit actions to the ChatGPT GM. This starts a poll to vote on the next action and will give a shortcut for other chat members to vote on that action using:
-
!
x
- A shortcut for a command will be given (e.g.
!1
,!2
, etc) and can be used by chat members to vote on the next action
- A shortcut for a command will be given (e.g.