0
votes
import discord
from discord.ext import commands
import speech_recognition as sr
description = 'Tutorial Bot'
bot_prefix = '?'
client = commands.Bot(description=description, command_prefix=bot_prefix)
@client.event
async def on_message(message):
    if message.content.startswith("Alice"):
        msg = await client.send_message(message.channel, 'Hello')
@client.event
async def on_voice_state_update():
    with sr.Microphone() as source:
        r = sr.Recognizer()
        audio = r.listen(source)
        command = r.recognize_google(audio)
        msg = await client.send_message(message.channel, comman)
async def joinVoiceChannel():
    channel = client.get_channel("FILL")
    await client.join_voice_channel(channel)
@client.event
async def on_ready():
    print("Logged in")
    print("Name : {}".format(client.user.name))
    print("ID : {}".format(client.user.id))
    print(discord.__version__)
    await joinVoiceChannel()
client.run("FILL")

I'm trying to make a bot that can join the call, hear audio when a microphone is activated and use the speech recognition module to output the message in string form. However I am having difficulties in the bot joining the call, and I haven't found a way to take an audio input from discord.

Logged in
Name : BOOS MUSIC
ID : 284760930837987338
0.16.8
Ignoring exception in on_ready Traceback (most recent call last): File "C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py", line 28, in on_ready await joinVoiceChannel() File "C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py", line 21, in joinVoiceChannel await client.join_voice_channel(channel) File "C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 3190, in join_voice_channel raise e File "C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 3186, in join_voice_channel session_id_data = yield from asyncio.wait_for(session_id_future, timeout=10.0, loop=self.loop) File "C:\Users\LMEBA21\AppData\Local\Programs\Python\Python35-32\lib\asyncio\tasks.py", line 390, in wait_for raise futures.TimeoutError() concurrent.futures._base.TimeoutError

1
What was the problem? Include the error you got in your post.user7627726

1 Answers

0
votes

I would comment but can't because of low rep, the two biggest mistakes you're making are that you should save your Voice object with something like:

voice = await client.join_voice_channel(channel)

as you will undoubtedly need to reference it later, and secondly Discord does not currently support recording audio from other users, to do this you would probably need to write your own discord wrapper and somehow integrate recording (Which is a little creepy).