A speech-to-text bot for discord with music commands and more using NodeJS. Ideally for controlling your Discord server using voice commands, can also be useful for hearing-impaired people.
A speech-to-text bot for discord with music commands and more written in NodeJS.
Try the bot for yourself on our Discord server: https://discord.gg/ApdTMG9
You can follow the steps below to get this bot up and running.
Video Tutorial: https://www.youtube.com/watch?v=y9OOM-c6nik
If you don’t have a linux server/machine then you can use Heroku for hosting your bot 24/7 and it’s free.
Under “Resources” tab, use the “worker” deno type, and not the “web” one. You will need to configure the “Config Vars” under “Settings” tab, these are the environment variables from the settings section below.
Tutorial: https://dev.to/codr/discord-ears-bot-on-heroku-4606
If you prefer using Docker instead of manually installing it.
Copy the Dockerfile.sample
to Dockerfile
and edit it.
Near the bottom you have to provide API Credentials either using the settings.json
file or setting the ENV variables.
Refer to the settings section below for details on these.
Once you’ve configured the Dockerfile you can build and run it:
docker build -t discordspeechbot .
this may take a minute or two.docker run -it discordspeechbot
You need nodeJS version 12+ with npm on your machine.
Using shell or command prompt execute the following:
git clone https://github.com/healzer/DiscordSpeechBot.git
cd DiscordSpeechBot
npm install
Create a (free) discord bot and obtain the API credentials (Bot Token).
Here’s an easy tutorial: https://www.writebots.com/discord-bot-token/
Note: Give your bot enough permissions or simply grant it Administrator rights.
Create a (free) Spotify developers account to obtain the API credentials (Client Id and Client Secret): https://developer.spotify.com/dashboard/
Create a (free) WitAI account and obtain the API credentials (Server Access Token): https://wit.ai/
Rename the file settings-sample.json
to settings.json
and enter the obtained API credentials:
{
"discord_token": "your_token",
"spotify_token_id": "your_token_id",
"spotify_token_secret": "your_token_secret",
"wit_ai_token": "your_token"
}
If you are using Digitalocean Apps, Heroku or another service you can also use Environment Variables instead of a settings file. Configure these with the appropriate values:
DISCORD_TOK
WITAPIKEY
SPOTIFY_TOKEN_ID
SPOTIFY_TOKEN_SECRET
Execute the following in your shell or prompt:
node index.js
Use PM2 to keep the bot running 24/7, it will also restart the bot in case of a crash or on memory limits (2GB default):
pm2 start ecosystem.config.js
By now you have a discord server, the DiscordSpeechBot is running and is a part of your server.
Make sure your server has a text and voice channel.
!join
!help
for a list of commands.Examples:
!play https://www.youtube.com/watch?v=vK1YiArMDfg
!play red hot chili peppers californication
!list
!skip
When the bot is inside a voice channel it listens to all speech and tries to detect commands.
Try saying:
music play 'the chemical brothers'
music skip
music play random
music list
music clear list
A successful voice command looks like this:
<long pause> music play 'justin timberlake cry river' <long pause>
music
.Here are some examples which may not work (properly):
<talking> music skip
music skip <talking>
<talking> music skip <talking>
...
music play 'the chemical brothers' <talking>
music <long silence> play <long silence> 'the chemical brothers'
<long pause>
is usually between 1 and 2 seconds, long enough for discord to stop processing your audio input.Music lagging or stuttering? Try this
Using Mozilla DeepSpeech for speech recognition, tutorial.
WitAI supports over 120 languages (https://wit.ai/faq), however only one language can be used at a time.
If you’re not speaking English on Discord, then change your default language on WitAI under “settings” for your app.
You can also change the language using the following bot command:
!lang <code>
!lang en for English
!lang es for Spanish
!lang ru for Russian
...
The bot should reply with a success message.
<code> should be an ISO 639-1 language code (2 digits):
https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
By default WitAI’s free API is used for voice recognition / transcription. But you can easily integrate any other API into the bot. You can use Google’s Speech-to-Text API as follows:
index.js
, inside the function transcribe(file)
make sure that transcribe_gspeech
is being used and the other one(s) are disabled.languageCode
value if you’re speaking a non-English language.gspeech_key.json
.For enquiries or issues get in touch with me:
Name: Ilya Nevolin
Email: [email protected]
Discord: https://discord.gg/ApdTMG9