我无法使用python discord模块使bot加入不和谐的语音通道

时间:2017-07-23 20:09:44

标签: python speech-recognition bots discord

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")

我试图制作可以加入通话的机器人,在麦克风激活时听到音频并使用语音识别模块输出 字符串形式的消息。然而,我在机器人加入通话时遇到了困难,而且我还没有找到一种方法来从不和谐中获取音频输入。

已登录
名称:BOOS MUSIC
ID:284760930837987338
0.16.8
忽略on_ready中的异常 Traceback(最近一次调用最后一次):   文件" C:\ Users \ LMEBA21 \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ site-packages \ discord \ client.py",307行,在_run_event中     来自getattr的收益率(自我,事件)(* args,** kwargs)   文件" C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py",第28行,在on_ready     等待joinVoiceChannel()   文件" C:/Users/LMEBA21/AppData/Local/Programs/Python/Python35-32/ALPHA.py",第21行,在joinVoiceChannel中     等待client.join_voice_channel(频道)   文件" C:\ Users \ LMEBA21 \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ site-packages \ discord \ client.py",第3190行,在join_voice_channel中     提高e   文件" C:\ Users \ LMEBA21 \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ site-packages \ discord \ client.py",第3186行,在join_voice_channel中     session_id_data =来自asyncio.wait_for的yield(session_id_future,timeout = 10.0,loop = self.loop)   文件" C:\ Users \ LMEBA21 \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ asyncio \ tasks.py",第390行,在wait_for中     提出期货.TimeoutError() concurrent.futures._base.TimeoutError

1 个答案:

答案 0 :(得分:0)

我会评论,但不能因为低代表,你正在犯的两个最大的错误是你应该用以下内容保存你的Voice对象:

voice = await client.join_voice_channel(channel)

因为你无疑需要在以后引用它,其次Discord目前不支持录制来自其他用户的音频,为此你可能需要编写自己的discord包装器并以某种方式集成录音(这有点令人毛骨悚然)