Nanda Kishore
Created July 30, 2024

PolyglobeGaming: Multilingual Game Chat Integration

PolyglobeGaming: Boost your game experience with real-time multilingual chat and voice integration via Discord Bots

25
PolyglobeGaming: Multilingual Game Chat Integration

Things used in this project

Hardware components

USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

TensorFlow
TensorFlow
Assistant SDK
Google Assistant SDK

Story

Read more

Schematics

Flowchart

Code

Discord Bot Initialization

JavaScript
This code sets up the basic structure of a Discord bot, including bot token initialization and basic event handling.
// Import the discord.js module
const Discord = require('discord.js');

// Create a new Discord client
const client = new Discord.Client();

// When the bot is ready, run this code
client.once('ready', () => {
    console.log('Ready!');
});

// Log in to Discord with your app's token
client.login('YOUR_BOT_TOKEN');

Voice Recognition Setup

JavaScript
This code captures and processes live voice input from users in a Discord voice channel.
// Required modules
const { joinVoiceChannel, createAudioPlayer, AudioPlayerStatus } = require('@discordjs/voice');
const { VoiceReceiver } = require('@discordjs/voice');

// Function to join a voice channel and start listening
function joinChannel(channel) {
    const connection = joinVoiceChannel({
        channelId: channel.id,
        guildId: channel.guild.id,
        adapterCreator: channel.guild.voiceAdapterCreator,
    });

    const receiver = new VoiceReceiver(connection);
    receiver.speaking.on('start', (userId) => {
        // Handle voice input here
    });
}

Speech Recognition Integration

Python
This code integrates speech recognition to transcribe spoken words into text using Google's Speech-to-Text API.
# Required imports
import speech_recognition as sr

# Initialize recognizer
recognizer = sr.Recognizer()

# Function to recognize speech
def recognize_speech(audio_file):
    try:
        text = recognizer.recognize_google(audio_file)
        print(f"Recognized Text: {text}")
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print(f"Could not request results from Google Speech Recognition service; {e}")

Text Translation

Python
This code translates text into the desired language using the Google Translate API.
# Required imports
from googletrans import Translator

# Initialize the Translator
translator = Translator()

# Function to translate text
def translate_text(text, dest_language):
    translation = translator.translate(text, dest=dest_language)
    return translation.text

Bot Command Handling

JavaScript
This code handles user commands in Discord, triggering specific bot functions like translation.
client.on('messageCreate', async message => {
    if (message.content.startsWith('!translate')) {
        const args = message.content.split(' ').slice(1);
        const textToTranslate = args.join(' ');
        
        // Call your translation function here
        const translatedText = await translateText(textToTranslate, 'es');
        
        message.channel.send(`Translated Text: ${translatedText}`);
    }
});

Credits

Nanda Kishore
1 project • 0 followers

Comments