-
-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add synchronization to start of audio recordings #1984
Conversation
for more information, see https://pre-commit.ci
I'll add an example for this too. For now, this is enough to test the merging of audio recordings- import asyncio
import io
from pydub import AudioSegment # pip install pydub
import discord
from discord.ext import commands
from discord.sinks import MP3Sink
class MyCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
async def finished_callback(
self,
sink: MP3Sink,
channel: discord.TextChannel,
):
mention_strs = []
audio_segs: list[AudioSegment] = []
files: list[discord.File] = []
longest = AudioSegment.empty()
for user_id, audio in sink.audio_data.items():
mention_strs.append(f"<@{user_id}>")
seg = AudioSegment.from_file(audio.file, format="mp3")
# Determine the longest audio segment
if len(seg) > len(longest):
audio_segs.append(longest)
longest = seg
else:
audio_segs.append(seg)
audio.file.seek(0)
files.append(discord.File(audio.file, filename=f"{user_id}.mp3"))
for seg in audio_segs:
longest = longest.overlay(seg)
with io.BytesIO() as f:
longest.export(f, format="mp3")
await channel.send(
f"Finished! Recorded audio for {', '.join(mention_strs)}.",
files=files + [discord.File(f, filename="recording.mp3")],
)
@commands.command()
async def join(self, ctx: commands.Context):
await ctx.author.voice.channel.connect()
@commands.command()
async def record(self, ctx: commands.Context):
vc: discord.VoiceClient = ctx.voice_client
await ctx.send("Recording...")
vc.start_recording(
discord.sinks.MP3Sink(),
self.finished_callback,
ctx.channel,
sync_start=True,
)
await asyncio.sleep(15) # edit to change recording duration
vc.stop_recording()
await ctx.send("Stopped recording.")
def setup(bot: commands.Bot):
bot.add_cog(MyCog(bot)) |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1984 +/- ##
==========================================
- Coverage 33.27% 33.25% -0.02%
==========================================
Files 97 97
Lines 19017 19027 +10
==========================================
Hits 6328 6328
- Misses 12689 12699 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
Signed-off-by: Om <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Signed-off-by: Om <[email protected]>
for more information, see https://pre-commit.ci
Signed-off-by: Om <[email protected]>
Sigh |
Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: Om <[email protected]>
@Lulalaby any updates? |
Check this message by Lala in the discord server |
Please fix merge conflicts |
i rly had a stroke rn lol |
@plun1331 ping pong |
Summary
When a Voice Channel is being recorded, users' recordings start when they start speaking, and not when the recording was actually started. This PR adds silence at the start of the recordings of users who weren't speaking when the recording started, but started speaking later.
This however relies on the receipt timestamp of the first packet, which can sometimes cause slightly inaccurate synchronisation, based on the network conditions.
This PR solves #1980.
Information
examples, ...).
Checklist
type: ignore
comments were used, a comment is also left explaining why.