Git Product home page Git Product logo

mallard's Introduction

Mallard - A Discord Bot

Setup

npm i -S discord node-opus @google-cloud/speech ytdl-core fluent-ffmpeg

Functionality

While connected to a Discord guild, Mallard will constantly watch for users' game status updates. If the game is in its gameAlerts object, Mallard will check if there are enough players to form a full queue in that game (i.e. 2 for Hearthstone, 5 for League of Legends, etc).

The bot will then ask if it should ping the players in-game. It takes a response "yes" or "no" through either text or voice.

Implementation details

The largest roadblock to getting the GCloud API to cooperate with the Discord API was the need to convert audio. I had originally been using Discord's createOpusStream to listen to voice, but instead I needed to use createPCMStream and convert it to ffmpeg like so:

if (speaking) {
    let stream = bot.receiver.createPCMStream(member.user);
    ffmpeg(stream)
        .inputFormat('s32le')
        .audioFrequency(16000)
        .audioChannels(1)
        .audioCodec('pcm_s16le')
        .format('s16le')
        .pipe(recognizeStream);

}

Once I did this, all I had to do was pipe the stream using Node to my GCloud output stream and voila!

mallard's People

Contributors

txie1993 avatar

Watchers

 avatar  avatar  avatar

Forkers

silvinator

mallard's Issues

Speech is not a function

Hey,
Every time I start my bot I get that error.

const speechClient = Speech({ projectId: projectId });
                     ^

TypeError: Speech is not a function
    at Object.<anonymous> (c:\Users\Markus\Desktop\AalBot\Voice\Bot.js:9:22)
    at Module._compile (internal/modules/cjs/loader.js:722:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:775:12)
    at startup (internal/bootstrap/node.js:300:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.