forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_recording.py
64 lines (48 loc) · 1.59 KB
/
audio_recording.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from enum import Enum
import discord
bot = discord.Bot(debug_guilds=[...])
connections = {}
class Sinks(Enum):
mp3 = discord.sinks.MP3Sink()
wav = discord.sinks.WaveSink()
pcm = discord.sinks.PCMSink()
ogg = discord.sinks.OGGSink()
mka = discord.sinks.MKASink()
mkv = discord.sinks.MKVSink()
mp4 = discord.sinks.MP4Sink()
m4a = discord.sinks.M4ASink()
async def finished_callback(sink, channel: discord.TextChannel, *args):
recorded_users = [f"<@{user_id}>" for user_id, audio in sink.audio_data.items()]
await sink.vc.disconnect()
files = [
discord.File(audio.file, f"{user_id}.{sink.encoding}")
for user_id, audio in sink.audio_data.items()
]
await channel.send(
f"Finished! Recorded audio for {', '.join(recorded_users)}.", files=files
)
@bot.command()
async def start(ctx: discord.ApplicationContext, sink: Sinks):
"""Record your voice!"""
voice = ctx.author.voice
if not voice:
return await ctx.respond("You're not in a vc right now")
vc = await voice.channel.connect()
connections.update({ctx.guild.id: vc})
vc.start_recording(
sink.value,
finished_callback,
ctx.channel,
)
await ctx.respond("The recording has started!")
@bot.command()
async def stop(ctx: discord.ApplicationContext):
"""Stop recording."""
if ctx.guild.id in connections:
vc = connections[ctx.guild.id]
vc.stop_recording()
del connections[ctx.guild.id]
await ctx.delete()
else:
await ctx.respond("Not recording in this guild.")
bot.run("TOKEN")