GithubHelp home page GithubHelp logo

rei-x / discord-speech-recognition Goto Github PK

View Code? Open in Web Editor NEW
57.0 57.0 22.0 556 KB

Speech to text extension for discord.js

Home Page: https://npmjs.com/package/discord-speech-recognition

License: MIT License

JavaScript 1.59% TypeScript 98.26% Shell 0.15%
discord discord-bot discord-js hacktoberfest speech-recognition speech-to-text

discord-speech-recognition's Introduction

hello jello 🧫

jello

discord-speech-recognition's People

Contributors

dependabot[bot] avatar rei-x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

discord-speech-recognition's Issues

How do I turn off profanity filter?

I see this option in resolveSpeechWithGoogleSpeechV2 but I have no idea on how to use it, addSpeechEvent options doesn't have such field.

UPDATE
Okay, simply putting as option profanityFilter:false seems to work.
But if I insert my API key for Google Speech-To-Text the speech recognition simply stops. If I don't set any key in options it works

Doesn't work when using other library for connecting to voice channel

Hi, I am attempting to make a speech recognition music bot with Discord.js v14 and discord-music-player.

I did notice you already made a bot using Discord.js v13.

My code to join the voice channel is the following:

const queue = interaction.client.player.createQueue(channel.guild.id);
queue.join(channel);

This code is the same as the one you are using in your bot (although I am using slash commands) and what is required.

The issue I am facing is if the bot joins the voice channel using queue.join from discord-music-player, the speech recognition does not work. However if the bot joins the voice channel using joinVoiceChannel from discord.js/voice, speech recognition does work.

joinVoiceChannel({
	channelId: channel.id,
	guildId: channel.guild.id,
	adapterCreator: channel.guild.voiceAdapterCreator,
	selfDeaf: false,
});

I am not sure if something has changed between discord.js v13 and v14 and the updates to discord.js/voice and discord-music-player, and was not sure if this is a bug with either of those.

Is it possible to be able get the voice connection from discord-music-player via queue.connection instead of discord.js/voice to start the speech recognition?

Thanks! Sorry if this isn't something you can fix I wasn't sure where to post this issue but considering you had done this before with your own bot I thought I'd ask.

Multi language Support

If possible it would be great for the speech recognition to be able to accept different languages at the same time

DiscordAPIError: Cannot send an empty message

Hi there, I was trying out the simpleBot example and the bot crashes when it doesn't recognize a familiar word. I see that it throws something on traceback but it still stops the whole bot from functioning. I would really like to understand the code more and possibly put a try catch method so it prevents it from crashing. Thanks!

Groupchats

It would be great for the bot to throw speech events filtered by the user who spoke

Change Language

Would there be a way to explain to a layman, how do I make the module accept another spoken language?

ApI Key

there is a google api key included. is this being used for default package implementation

Recognition stops somewhat randomly

Recognition will stop somewhat randomly for seemingly no reason. I have checked the connection after it stop detecting speech and it seems to still be in the voice channel and ready. It doesn't even fire the Client.on(speechEvent) function. Leaving and then rejoining fixes the issue for a short while.

activate speech with a special word

hi mate, first of all ty for creating this, it´s really usefull.
i have question for u, i want the bot to start the speech recognition when it hears a special word like "andrea" for example, because it stats the speech recogniton every time someone stops talking. my english id bad, if you dont understand something let me know

Random crashes?

node:events:505
throw er; // Unhandled 'error' event
^

TypeError: The compressed data passed is corrupted
at Decoder._decode (C:\Users\serap\Desktop\discordspeechbot\discord-speech-recognition\examples\simpleBot\node_modules\prism-media\src\opus\Opus.js:64:25)
at Decoder._transform (C:\Users\serap\Desktop\discordspeechbot\discord-speech-recognition\examples\simpleBot\node_modules\prism-media\src\opus\Opus.js:204:22)
at Decoder.Transform._write (node:internal/streams/transform:184:23)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Decoder.Writable.write (node:internal/streams/writable:334:10)
at AudioReceiveStream.ondata (node:internal/streams/readable:754:22)
at AudioReceiveStream.emit (node:events:527:28)
at AudioReceiveStream.Readable.read (node:internal/streams/readable:527:10)
at flow (node:internal/streams/readable:1011:34)
Emitted 'error' event on Decoder instance at:
at Decoder.onerror (node:internal/streams/readable:773:14)
at Decoder.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

This is periodically happening when I use SimpleBot. I don't really see how it's something I wrote, though I did modify it a bit. 

I have it joining a channel, and it doesn't leave it just continues functioning when you trigger it.

Why use axios and fetch

I just noticed that you use axios on this file
and node-fetch on wit.ai, is there a reason for that?

Also where did you find that key? You got inspirantion from this python implementation?
Anyways, this is awsome work!

Error

npm ERR! code 1
npm ERR! path /home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus
npm ERR! command failed
npm ERR! command sh -c node-pre-gyp install --fallback-to-build
npm ERR! Failed to execute '/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/bin/node /nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34/opus.node --module_name=opus --module_path=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
npm ERR! node-pre-gyp info it worked if it ends with ok
npm ERR! node-pre-gyp info using [email protected]
npm ERR! node-pre-gyp info using [email protected] | linux | x64
npm ERR! node-pre-gyp info check checked for "/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34/opus.node" (not found)
npm ERR! node-pre-gyp http GET https://github.com/discordjs/opus/releases/download/v0.8.0/opus-v0.8.0-node-v93-napi-v3-linux-x64-glibc-2.34.tar.gz
npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.8.0/opus-v0.8.0-node-v93-napi-v3-linux-x64-glibc-2.34.tar.gz
npm ERR! node-pre-gyp WARN Pre-built binaries not installable for @discordjs/[email protected] and [email protected] (node-v93 ABI, glibc) (falling back to source compile with node-gyp)
npm ERR! node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/discordjs/opus/releases/download/v0.8.0/opus-v0.8.0-node-v93-napi-v3-linux-x64-glibc-2.34.tar.gz
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info ok
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
npm ERR! gyp ERR! find Python checking if "python3" can be used
npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
npm ERR! gyp ERR! find Python checking if "python" can be used
npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python You need to install the latest version of Python.
npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
npm ERR! gyp ERR! find Python you can try one of the following options:
npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
npm ERR! gyp ERR! find Python (accepted by both node-gyp and npm)
npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
npm ERR! gyp ERR! find Python npm config set python "/path/to/pythonexecutable"
npm ERR! gyp ERR! find Python For more information consult the documentation at:
npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
npm ERR! gyp ERR! find Python **********************************************************
npm ERR! gyp ERR! find Python
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
npm ERR! gyp ERR! stack at PythonFinder.fail (/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
npm ERR! gyp ERR! stack at PythonFinder.runChecks (/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
npm ERR! gyp ERR! stack at PythonFinder. (/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
npm ERR! gyp ERR! stack at PythonFinder.execFileCallback (/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
npm ERR! gyp ERR! stack at exithandler (node:child_process:406:5)
npm ERR! gyp ERR! stack at ChildProcess.errorhandler (node:child_process:418:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
npm ERR! gyp ERR! stack at onErrorNT (node:internal/child_process:478:16)
npm ERR! gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR! gyp ERR! System Linux 5.15.0-1021-gcp
npm ERR! gyp ERR! command "/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/bin/node" "/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34/opus.node" "--module_name=opus" "--module_path=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
npm ERR! gyp ERR! cwd /home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus
npm ERR! gyp ERR! node -v v16.15.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok
npm ERR! node-pre-gyp ERR! build error
npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/bin/node /nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34/opus.node --module_name=opus --module_path=/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus/prebuild/node-v93-napi-v3-linux-x64-glibc-2.34 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
npm ERR! node-pre-gyp ERR! stack at ChildProcess. (/home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/node-pre-gyp/lib/util/compile.js:85:20)
npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1092:16)
npm ERR! node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! node-pre-gyp ERR! System Linux 5.15.0-1021-gcp
npm ERR! node-pre-gyp ERR! command "/nix/store/amm5j0ag985nh49n096a78q1dfs2xsfn-nodejs-16.15.0/bin/node" "/home/runner/LAST-TEST-I-SWEAR/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
npm ERR! node-pre-gyp ERR! cwd /home/runner/LAST-TEST-I-SWEAR/node_modules/@discordjs/opus
npm ERR! node-pre-gyp ERR! node -v v16.15.0
npm ERR! node-pre-gyp ERR! node-pre-gyp -v v0.4.5
npm ERR! node-pre-gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-11-04T00_06_26_657Z-debug-0.log

I keep getting this in visual studio code

ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run

npm ERR! A complete log of this run can be found in:

Opus Error hadn't been handle correctly

I found these errors on @discord/opus when speaking from a web browser which the error hasn't been handle correctly, so it will crash the whole app.

events.js:292
      throw er; // Unhandled 'error' event
      ^

TypeError: The compressed data passed is corrupted
    at Decoder._decode (C:\Users\ironp\Project\discord-speech-recognition-cont\node_modules\discord.js\node_modules\prism-media\src\opus\Opus.js:64:25)
    at Decoder._transform (C:\Users\ironp\Project\discord-speech-recognition-cont\node_modules\discord.js\node_modules\prism-media\src\opus\Opus.js:204:22)
    at Decoder.Transform._read (internal/streams/transform.js:205:10)
    at Decoder.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Decoder.Writable.write (internal/streams/writable.js:303:10)
    at Readable.ondata (internal/streams/readable.js:719:22)
    at Readable.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
Emitted 'error' event on Decoder instance at:
    at Decoder.onerror (internal/streams/readable.js:760:14)
    at Decoder.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

Recognition stops after a while

Hi, I used the code some time ago and everything worked fine, now the speech recognition works as if for a while after the bot joins the voice channel, after that it stops sending responses. After I disconnect the bot from the channel and rejoin it again it works again for a while

Speech-recognition libraries support

It would be awesome if there were other speech-recognition libraries supported, maybe even Vosk and Whisper. I know that Vosk supports real-time transcription, but the official Whisper library does not.

Listens when deafened

When selfDeaf is set to true, the bot can still hear the user's voice and transcribe it. This is an issue with Discord, not the speech recognition. It would be a nice feature if the bot didn't transcribe the voices when selfDeaf is set to true, for security.

await joinVoiceChannel({
    channelId: voiceChannel.id,
    guildId: voiceChannel.guild.id,
    adapterCreator: voiceChannel.guild.voiceAdapterCreator,
    selfDeaf: true,
});

I have an example bot that demonstrates the problem.

Doesn't work on M1

When someone actually makes a voice input, the program instantly crashes with
dyld[50404]: missing symbol called /var/folders/25/b6_q63592y7g21sc20h3jtx00000gn/T/start-cecd88d9.sh: line 1: 50404 Abort trap: 6 node index.js
Here is the relevant code:

client.on('interactionCreate', async (interaction) => {
	if (!interaction.isChatInputCommand()) return;

	const { commandName } = interaction;

	if (commandName === 'join') {
    const voiceChannel = interaction.member?.voice.channel;
    if (voiceChannel) {
      await joinVoiceChannel({
        channelId: voiceChannel.id,
        guildId: voiceChannel.guild.id,
        adapterCreator: voiceChannel.guild.voiceAdapterCreator,
        selfDeaf: false,
      });
      await interaction.reply("Joined channel \"" + voiceChannel.name + "\"");
    } else {
      await interaction.reply("Please join a voice channel before using this command!");
    }
  }
});

client.on("speech", (msg) => {
  // If bot didn't recognize speech, content will be empty
  console.log("tea");
});

Some googling makes me think this is an issue with M1 mac processors and the binaries, but not 100% sure.

Discord.js v13

I'm using discord.js v13 but a package doesn't work. Could any developer help me?

Error on trying to install the package.

npm i discord-speech-recognition
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @discordjs/[email protected]
npm ERR! node_modules/@discordjs/voice
npm ERR! @discordjs/voice@"^0.13.0" from the root project
npm ERR!
npm ERR! peer @discordjs/voice@"^0.11.x" from [email protected]
npm ERR! node_modules/discord-speech-recognition
npm ERR! discord-speech-recognition@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\GT-ACE\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\GT-ACE\AppData\Local\npm-cache_logs\2022-10-28T17_24_28_802Z-debug-0.log

Suggestion: Filter out sounds from other bots

Having a music/sound bot in the same channel can spam the speech recognition with useless requests. Would be nice to have a setting (or even by default) to ignore messages from bots.

Possible memory leak?

(node:19176) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [AudioReceiveStream]. Use emitter.setMaxListeners() to increase limit
    at __node_internal_genericNodeError (node:internal/errors:863:15)
    at _addListener (node:events:587:17)
    at AudioReceiveStream.addListener (node:events:605:10)
    at Readable.on (node:internal/streams/readable:887:35)
    at Readable.pipe (node:internal/streams/readable:763:7)
    at _SpeakingMap.handleSpeechEventOnConnectionReceiver (D:\projects\MusicBot\node_modules\discord-speech-recognition\src\bot\events\speech.ts:74:10)
    at _SpeakingMap.emit (node:events:513:28)
    at onPacket (D:\projects\MusicBot\node_modules\@discordjs\voice\src\receive\SpeakingMap.ts:48:9)        
    at onUdpMessage (D:\projects\MusicBot\node_modules\@discordjs\voice\src\receive\VoiceReceiver.ts:142:17)    at VoiceUDPSocket.emit (node:events:513:28)
const voiceHandler = (voice) => {
    if (!voice.content) {
        return; //if no speech detected, do nothing
    }   
    //console.log(`${voice.author.username} said ${voice.content}`);
    if (voice.content.toLowerCase().includes('music')){
        //console.log(voice);
        voice.content = `!${voice.content.toLowerCase().split('music')[1].trim()}`; //append '!' so everything else works
        console.log(`${voice.author.username} said '${voice.content}'`)
        command(voice);
    }
    //client.removeListener('speech', voiceHandler);
}
client.on(SpeechEvents.speech, voiceHandler);

Not sure what I can do to stop the warning, seems like it originates from the module itself. Any suggestions appreciated.

Callback firing multiple times for the same message when using Wit.ai

DiscordSR seems to be sending multiple requests when using wit.ai.

Code used for this test:

const { Client, Intents } = require('discord.js');
const { addSpeechEvent, resolveSpeechWithWitai } = require("discord-speech-recognition");
const { joinVoiceChannel } = require("@discordjs/voice");

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_VOICE_STATES,
        Intents.FLAGS.GUILD_MESSAGES,
    ],
});

addSpeechEvent(client, {
    speechRecognition: resolveSpeechWithWitai,
    lang: 'pt-BR',
    key: '<my-witai-key>',
    profanityFilter: false,
});


client.on('messageCreate', (msg) => {
    console.log("[M]", msg.member.displayName, msg.content);
    if (msg.content.startsWith('##join') && msg.member?.voice.channel) {
        joinVoiceChannel({
            channelId: msg.member.voice.channelId,
            guildId: msg.member.guild.id,
            adapterCreator: msg.member.guild.voiceAdapterCreator,
            selfDeaf: false,
            selfMute: true,
        });
    }
});

client.on('speech', (msg) => {
    console.log(`[S] ${msg.member.displayName}: ${msg.content}`);
});

client.on("ready", () => {
    console.log("BOT READY");
})

client.login('<my-bot-key>');

Resulting log:

BOT READY
[M] darkbreaker ##join
[S] darkbreaker: oi teste um dois três
[S] darkbreaker: oi teste um, dois, três

Both even show up on wit.ai dashboard:
image

When using just addSpeechEvent(client); with the default google SR it worked as intended:

BOT READY
[M] darkbreaker ##join
[S] darkbreaker: this is a test

use another package connection voice channel

Can I add another package option like discord-voip instead of @discordjs/voice... because I'm using discord-player and it works using discord-voip
I tried changing it all to discord-voip and it might work... Is there a way with one line of code to replace the whole thing

Events dosn't fire when imported as ES6 module

import { Client, ChannelType, GatewayIntentBits, Events, Collection, Partials } from 'discord.js'
import { joinVoiceChannel } from '@discordjs/voice'
import { addSpeechEvent, SpeechEvents } from 'discord-speech-recognition'
const client = new Client({
  intents: [
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.MessageContent],
  partials: [
    Partials.Channel,
    Partials.Message
  ]
})
addSpeechEvent(client, {
  lang: 'en-US'
})

in the messageCreate event i have this

      if (message.content === 'test-join') {
        const voiceChannel = message.member?.voice.channel
        if (voiceChannel) {
          return joinVoiceChannel({
            channelId: voiceChannel.id,
            guildId: voiceChannel.guild.id,
            adapterCreator: voiceChannel.guild.voiceAdapterCreator,
            selfDeaf: false
          })
        }
      }

And then

 client.on(SpeechEvents.voiceJoin, (out) => {console.log(out)})
  client.on(SpeechEvents.speech, (msg) => {
    console.log('speech')
    // If bot didn't recognize speech, content will be empty
    if (!msg.content) return
    console.log(msg.content)
    // msg.author.send(msg.content)
  })

but none of the events fire, neither the ´voiceJoin´ nor the ´speech´ event.
Am i missing something super obvious?

Recognizing voice input from DisTube's voice connection

I know someone has previously reported a problem with voice recognition when using another library for connecting to voice, however the solution presented in that thread (uninstalling the @discordjs/voice package), doesn't seem to work for the DisTube library, when using its distube.voices.join(voiceChannel) method and setting the deafened status to false. The bot does join the voice channel correctly, but the client.on('speech') event never gets emitted with that voice connection. Any help regarding this problem would be greatly appreciated!

I am not sure what my problems is. Here is the log when I run "npm install" .

$ npm install
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

[email protected] preinstall D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium
node install.js --preinstall

MS Version: 2015
Preinstall Mode
Download libsodium.lib
MS Version: 2015
Platform Tool is v140
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/x64/Release/v140/dynamic/libsodium.dll
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/x64/Release/v140/dynamic/libsodium.exp
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/x64/Release/v140/dynamic/libsodium.lib
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/x64/Release/v140/dynamic/libsodium.pdb
Libs for version v140 downloaded.
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/core.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_aead_aes256gcm.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_aead_chacha20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_aead_xchacha20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_auth.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_auth_hmacsha256.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_auth_hmacsha512.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_auth_hmacsha512256.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_box.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_box_curve25519xchacha20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_box_curve25519xsalsa20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_ed25519.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_hchacha20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_hsalsa20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_salsa20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_salsa2012.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_core_salsa208.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_generichash.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_generichash_blake2b.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_hash.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_hash_sha256.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_hash_sha512.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_kdf.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_kdf_blake2b.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_kx.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_onetimeauth.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_onetimeauth_poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_pwhash.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_pwhash_argon2i.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_pwhash_argon2id.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_pwhash_scryptsalsa208sha256.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_scalarmult.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_scalarmult_curve25519.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_scalarmult_ed25519.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_secretbox.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_secretbox_xchacha20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_secretbox_xsalsa20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_secretstream_xchacha20poly1305.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_shorthash.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_shorthash_siphash24.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_sign.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_sign_ed25519.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_sign_edwards25519sha512batch.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_chacha20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_salsa20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_salsa2012.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_salsa208.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_xchacha20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_stream_xsalsa20.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_verify_16.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_verify_32.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/crypto_verify_64.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/export.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/randombytes.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/randombytes_salsa20_random.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/randombytes_sysrandom.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/runtime.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/utils.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium/version.h
Download: https://raw.githubusercontent.com/paixaop/libsodium-bin/master/1.0.16/include/sodium.h
Include files downloaded.
Prebuild steps completed. Binary libsodium distribution installed in ./deps/build

@discordjs/[email protected] install D:\discord-speech-recognition\examples\simpleBot\node_modules@discordjs\opus
node-pre-gyp install --fallback-to-build

[@discordjs/opus] Success: "D:\discord-speech-recognition\examples\simpleBot\node_modules@discordjs\opus\prebuild\node-v83-napi-v3-win32-x64-unknown-unknown\opus.node" is installed via remote

[email protected] install D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium
node install.js --install

MS Version: 2015
Install Mode

D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find VS
gyp ERR! find VS msvs_version was set from command line or npm config
gyp ERR! find VS - looking for Visual Studio version 2015
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS valid versions for msvs_version:
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack at ChildProcess.exithandler (child_process.js:390:5)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at maybeClose (internal/child_process.js:1058:16)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium
gyp ERR! node -v v14.18.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium\install.js:293
throw new Error(cmdLine + ' exited with code ' + code);
^

Error: node-gyp rebuild exited with code 1
at ChildProcess. (D:\discord-speech-recognition\examples\simpleBot\node_modules\sodium\install.js:293:19)
at ChildProcess.emit (events.js:400:28)
at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node install.js --install
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ajhar\AppData\Roaming\npm-cache_logs\2021-10-18T12_16_47_010Z-debug.log

Detection sometimes repeated

Screenshot 2023-03-16 at 7 27 00 PM

Sometimes the detection is repeated sometimes, as shown above. Both result are the same and showing in the same time.

My original conversation:
Emma,
how do you feel right now,
are you feeling alright?

How to ignore all bots except one

I need my bot to ignore all bots except for one of mine. I could not find this functionality not in discord.js, not in this library

Audio BASE64 Output

Hello,

First of all, your module and project are very cool. I am using discord.js@v14 module and discord-speech-recognition latest version.

My problem is is there any way I can get "audio base64" data with speech client event?

client.on("speech", (msg) => {
  // If bot didn't recognize speech, content will be empty
  if (!msg.content) return;

  msg.author.send(msg.content);
});

Kind regards,
Pudochu.

Cannot find voiceChannel

  • question
    : I cannot access msg.member?.voice.channel

  • this is my codes

const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');
const { addSpeechEvent, SpeechEvents } = require('discord-speech-recognition');
const { joinVoiceChannel } = require('@discordjs/voice');

const fs = require('node:fs');
const path = require('node:path');
require('dotenv').config();

const token = process.env.DISCORD_TOKEN;

const client = new Client({
  intents: [
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.Guilds,
    GatewayIntentBits.MessageContent,
  ],
});

addSpeechEvent(client);

client.on(Events.MessageCreate, (msg) => {
  console.log('msg2', msg);

  const voiceChannel = msg.member?.voice.channel;

  // if (voiceChannel) {
  // joinVoiceChannel({
  //   channelId: voiceChannel.id,
  //   guildId: voiceChannel.guild.id,
  //   adapterCreator: voiceChannel.guild.voiceAdapterCreator,
  //   selfDeaf: false,
  // });
  // }
});

client.on(SpeechEvents.speech, (msg) => {
  // If bot didn't recognize speech, content will be empty
  if (!msg.content) return;

  msg.author.send(msg.content);
});

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith('.js'));

for (const file of eventFiles) {
  const filePath = path.join(eventsPath, file);
  const event = require(filePath);
  if (event.once) {
    client.once(event.name, (...args) => event.execute(...args));
  } else {
    client.on(event.name, (...args) => event.execute(...args));
  }
}

client.login(token);
  • and this is what I got in console.log('msg2', msg);
스크린샷 2024-02-25 오후 10 12 14
  • this is dependencies in package.json
"dependencies": {
    "@discordjs/opus": "github:discordjs/opus",
    "discord-speech-recognition": "^3.4.1",
    "discord.js": "^14.14.1",
    "dotenv": "^16.4.5",
    "sodium": "^3.0.2"
  },

Option for changing base language?

I saw an earlier issue regarding language support, but more simply, is there a way to set the default language (or multiple languages) used for the speech recognition?

Change SpeechOptions after adding the speech event.

Hi @Rei-x,

Hope you're well. I'm creating this issue to kindly request an update on the feature to change the speechOptions after addSpeechEvent (from issue #57). Any timeline or progress made would be appreciated.

Thanks for your great work on this project!

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.