discord-ext-voice-recv
discord-ext-voice-recv copied to clipboard
Help Needed to output to speakers
Im trying to output to defauld audio device the things being said in the discord channel. Could you please help me:
What i have to far just outputs ticking to the speakers:
import discord
from discord.ext import commands, voice_recv
import random
import pyaudio
description = '''An example bot to showcase the discord.ext.commands extension
module.
There are a number of utility commands being showcased here.'''
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(command_prefix='?', description=description, intents=intents)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32,
channels=1,
rate=44100,
output=True)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
print('------')
@bot.command()
async def add(ctx, left: int, right: int):
"""Adds two numbers together."""
await ctx.send(left + right)
@bot.command()
async def test(ctx):
def callback(user, data: voice_recv.VoiceData):
print(f"Got packet from {user}")
## voice power level, how loud the user is speaking
ext_data = data.packet.extension_data.get(voice_recv.ExtensionID.audio_power)
value = int.from_bytes(ext_data, 'big')
power = 127-(value & 127)
print('#' * int(power * (79/128)))
stream.write(data.packet.decrypted_data)
## instead of 79 you can use shutil.get_terminal_size().columns-1
vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
vc.listen(voice_recv.BasicSink(callback))
@bot.command()
async def stop(ctx):
await ctx.voice_client.disconnect()
@bot.command()
async def die(ctx):
ctx.voice_client.stop()
await ctx.bot.close()
bot.run("xxxx")