Programming — Discord Bot TTS
~tts hello there!
Environment: Python3.7 on Raspberry Pi 3b+
To get started you need to run the following commands:
sudo pip3 install gtts && sudo pip3 install mutagen && sudo pip3 install discord.py[voice]
The first step is to import the packages you just installed.
The first function of the code gets the length of the mp3 file that is saved once you run the ~tts command.
Next, we need to create a discord bot command. I called it “tts”. Anything following the ~tts command is stored in the variable “text”. I also reference the gTTs that we will need to use in order to convert text to speech.
The next step was to get the text and save it to the current directory.
After we got that, we need to join the voice channel the user is currently in and play the file.
The last step is to leave the voice chat once the audio is don playing. We do that by calling the audio_len() function and pass it the path to the file. We get back the length, and wait to disconnect until the audio is done playing.
After that, you have yourself a fully functioning text to speech discord bot!