imayhaveborkedit / discord-ext-voice-recv

Voice receive extension package for discord.py
https://pypi.org/project/discord-ext-voice-recv/
MIT License
117 stars 18 forks source link

expected 'AudioSink' not 'NoneType' #18

Closed sayborduu closed 4 months ago

sayborduu commented 6 months ago

I've been getting this error for a while now, and idk how to fix it. idk if it's because I'm using py-cord, or bc of the latest discord.py GitHub release.

This is my code:

def process_wit(recognizer: sr.Recognizer, audio: sr.AudioData, user: Optional[str]) -> Optional[str]:
    text: Optional[str] = None

    try:
        func = getattr(recognizer, 'recognize_wit', recognizer.recognize_google)
        text = func(audio, key='(key)')
    except sr.UnknownValueError:
        print("Bad speech chunk")

    return text

vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
vc.listen(voice_recv.extras.SpeechRecognitionSink(process_cb=process_wit, default_recognizer="wit"))

...but I also tried this:

def process_wit(recognizer: sr.Recognizer, audio: sr.AudioData, user: Optional[str]) -> Optional[str]:
    text: Optional[str] = None

    try:
        func = getattr(recognizer, 'recognize_wit', recognizer.recognize_google)
        text = func(audio, key='(key)')
    except sr.UnknownValueError:
        print("Bad speech chunk")

    return text

vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
sink = voice_recv.extras.SpeechRecognitionSink(process_cb=process_wit, default_recognizer="wit")
vc.sink = sink
vc.listen(sink)

getting this error:

Console error

``` Ignoring exception in on_application_command_error Traceback (most recent call last): File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 131, in wrapped ret = await coro(arg) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 1013, in _invoke await self.callback(ctx, **kwargs) File "/home/container/discord_bot.py", line 1387, in ai_join vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient) File "/home/container/.local/lib/python3.10/site-packages/discord/abc.py", line 1970, in connect voice = cls(client, self) File "/home/container/.local/lib/python3.10/site-packages/discord/ext/voice_recv/voice_client.py", line 35, in __init__ super().__init__(client, channel) File "/home/container/.local/lib/python3.10/site-packages/discord/voice_client.py", line 264, in __init__ self.sink = None File "/home/container/.local/lib/python3.10/site-packages/discord/ext/voice_recv/voice_client.py", line 178, in sink raise TypeError('expected AudioSink not {0.__class__.__name__}.'.format(sink)) TypeError: expected AudioSink not NoneType. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/container/.local/lib/python3.10/site-packages/discord/client.py", line 400, in _run_event await coro(*args, **kwargs) File "/home/container/discord_bot.py", line 1548, in on_application_command_error raise error File "/home/container/.local/lib/python3.10/site-packages/discord/bot.py", line 1130, in invoke_application_command await ctx.command.invoke(ctx) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 376, in invoke await injected(ctx) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 131, in wrapped ret = await coro(arg) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 1370, in _invoke await command.invoke(ctx) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 376, in invoke await injected(ctx) File "/home/container/.local/lib/python3.10/site-packages/discord/commands/core.py", line 139, in wrapped raise ApplicationCommandInvokeError(exc) from exc discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: expected AudioSink not NoneType. ```

TyrantKingBen commented 4 months ago

FYI, it's because you're using Pycord. Pycord has it's own voice recording already and the sinks between these two packages are not interchangeable. Although, it doesn't look like it would be terribly hard to convert the SpeechRecognitionSink to a Pycord compatible sink.

sayborduu commented 4 months ago

FYI, it's because you're using Pycord. Pycord has it's own voice recording already and the sinks between these two packages are not interchangeable. Although, it doesn't look like it would be terribly hard to convert the SpeechRecognitionSink to a Pycord compatible sink.

okay, thanks! I was already planning to switch to discord.py, so I’ll use this package with discord.py. Thanks again!