A Twitch Chat AI that reads twitch chat and creates a text to speech response using Google Cloud API and OpenAI's GPT-3 text completion model.
Kyumnii is coded in Python.
I use TwitchIO, A fully asynchronous Python IRC, API, EventSub and PubSub library for Twitch to check for messages, pull the contents and feeds it to GPT-3 where it responds.
There is a profanity filter that uses the Jaro-Winkler distance algorithm thats used to detect whether a given message or response contains profanity. It checks the similarity of the given message or response to a list of profanity words stored.
The bot checks that the message contains English words, is not too long, and then concatenates the most recent messages to generate a prompt. The prompt is used to generate a response using the OpenAI GPT-3 API.
I use Google's Text-to-Speech API to generate an audio file of the response, which is then played using VLC. The bot also sends the response to the Twitch chat and logs it to a file.
This code is a fork of Kuebiko. Make sure to check it out!
Video instructions by adi-panda here (original video for Kuebiko but about the same steps)
To get a local copy up and running follow these simple example steps.
- VLC must be in installed on your computer!
In order to install the prerequisites you will need to do:
- pip
pip install -r requirements.txt
- Install VLC 64-bit from here
- Get a OpenAI API Key here
- Get a Twitch API Token here
- Create a Google Cloud Project with TTS Service enabled and download JSON credentials file.
- Clone the repo
git clone https://github.com/idkanymre/kyumnii.git
- Enter your Twitch Username in
main.py > initial_channels
super().__init__(token='cred.twi_token', prefix='?', initial_channels=[''])
- Add the Google Cloud JSON file into the project folder.
- Add the name of the Google Cloud JSON File into
main.py
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ''
- Add the OpenAI API and Twitch OAuth token into
cred.py
# get your twitch oauth token here: https://twitchapps.com/tmi/ twi_token="oauth:xxxxxxxxxxxxxxxxxx" # get your openai token here: https://beta.openai.com/account/api-keys openai_token="sk-xxxxxxxxxxxxxxxxxx"
- Download VTube Studio and use VBAudio Cable to route audio coming from the program to Vtube Studio using params.
- Add the following script to OBS
- Create a new text source for captions, and set it to read from a file, select the
output.txt
file in \your documents folder\kyumnii (may need to run the script first in order to see it.) - In the script options put the name of your text source.
- Set the script in transform options to scale to inner bounds, and adjust the size of the captions.
- In order to change the voice of your AI, you will need to change the following parameters in main.py Here is a list of supported voices
voice = texttospeech.VoiceSelectionParams(
language_code="en-US",
name= "en-US-Neural2-H",
ssml_gender=texttospeech.SsmlVoiceGender.FEMALE,
)
I made this code public due to discontinuing the "kyumnii" social media and thought to share what I made for others! If you want to continue kyumnii's social media please message me on twitter here for enquiries.
https://twitch.tv/kyumnii https://youtube.com/@kyumnii
made with ๐ by unslyu with idkanymore