Skip to content

A Discord-Bot which unifies Facebooks witAi with (Anki) Flashcards and googleTTS (NLP)

License

Notifications You must be signed in to change notification settings

meda1028/VitAImine

Repository files navigation

VitAImine

Test Image 4

Anki & Anki-Connect

To connect Anki with the bot, download Anki from https://apps.ankiweb.net/ and install it. Register a free account on https://ankiweb.net/account/register if you dont have one already.

  1. Start Anki and Login (Sync).

  2. Navigate [Tools]->[Add-ons]->[Get Add-ons...] and enter Code: 2055492159 To download Anki-Connect https://ankiweb.net/shared/info/2055492159

    (I recommend installing 1133851639 too, which gives a better Presence for the Anki Player https://github.com/Monacraft/AnkiDiscord)

  3. Once Downloaded open [Tools]->[Add-ons]->[AnkiConnect] and replace with following configuration: a.)if your Discord server is on another machine you neet to input you external ip instead of localhost and Expose Port 8765 to make it accesible via internet

    b.) if you want to run Anki on the same Machine as your Discord Server e.g. with Docker

{
    "apiKey": null,
    "apiLogPath": null,
    "ignoreOriginList": [],
    "webBindAddress": "localhost",
    "webBindPort": 8765,
    "webCorsOriginList": [
        "http://localhost"
    ]
}
  1. Press [ok] and restart Anki

Docker

If you prefer using Docker instead of manually installing it.

Instead of a docker file you can also try to pull via docker pull meda1028\vitaimine

Copy the Dockerfile.sample and edit it. Near the bottom you have to provide API Credentials either using the settings.json file or setting the ENV variables.

If you want to use Anki on the same PC as Docker use: http://host.docker.internal:8765 for the ANKICONNECTIP, it will passthrough the api from localhost:8765. Refer to the settings section below for details on these.

Rename it to "Dockerfile" and save it. Once you've configured the Dockerfile you can build and run it:

  1. run docker build - < Dockerfile -t vitaimine this may take a minute or two.
  2. run docker images and doublecheck if theres a image called 'vitaimine'
  3. launch ANKI with ANKICONNECT on localhost:8765
  4. run docker run vitaimine
  5. Proceed to Usage section below.

Installation

You need nodeJS version 14+ with npm on your machine. Using shell or command prompt execute the following:

git clone https://github.com/meda1028/name.git
cd name
npm install

Settings

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) 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",
    "wit_ai_token": "your_token",
    "ankiconnect_api_ip": "http://host.docker.internal:8765"
}

If you are using Digitalocean Apps, Heroku, Docker or another service you can also use Environment Variables instead of a settings file. Configure these with the appropriate values:

DISCORD_TOK
WITAPIKEY
ANKICONNECT_IP

Running

Execute the following in your shell or prompt:

node index.js

or

npm start

Usage

By now you have a discord server, the VitAimine is running and is a part of your server. Make sure your server has a text and voice channel.

  1. Enter one of your voice channels.
  2. In one of your text channels type: *join, the bot will join the voice channel.
  3. Everything said within that channel will be transcribed into text (as long as the bot is within the voice channel).
  4. Type *leave to make the bot leave the voice channel.
  5. Type *help for a list of commands.

notes:

  • When the bot is inside a voice channel it listens to all speech and transcribes audio into text.
  • Each user is a separate audio channel, the bot hears everyone separately.
  • Only when your user picture turns green in the voice channel will the bot receive your audio.
  • A long pause interrupts the audio input.
  • (WitAI only) The duration of a single audio input is limited to 20 seconds, longer audio is not transcribed.
  • There's also a Bug if you didn't let googleTTS finish its sentence it won't continue
  • Sadly the only 2 TTS Options are normal, and slow

Language

WitAI supports over 120 languages (https://wit.ai/faq), however only one language can be used at a time. If you're not speaking German 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:

*language <code>

*language en     for English
*language es     for Spanish
*language 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

But keep in mind, each Wit.Ai token represents only 1 language.

Speech-To-Text

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:

  1. Open index.js, inside the function transcribe(file) make sure that transcribe_gspeech is being used and the other one(s) are disabled.
  2. You may want to adjust the languageCode value if you're speaking a non-English language.
  3. Enable Google Speech API here: https://console.cloud.google.com/apis/library/speech.googleapis.com
  4. Create a new Service Account (or use your existing one): https://console.cloud.google.com/apis/credentials
  5. Create a new Service Account Key (or use existing) and download the json file.
  6. Put the json file inside your bot directory and rename it to gspeech_key.json.

Resources

https://foosoft.net/projects/anki-connect/

Test Image 4