feat: Add synchronization to start of audio recordings#1984
Merged
Lulalaby merged 34 commits intoPycord-Development:masterfrom May 1, 2023
Merged
feat: Add synchronization to start of audio recordings#1984Lulalaby merged 34 commits intoPycord-Development:masterfrom
Lulalaby merged 34 commits intoPycord-Development:masterfrom
Conversation
…to voice-recording
for more information, see https://pre-commit.ci
Contributor
Author
|
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 <92863779+Om1609@users.noreply.github.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
for more information, see https://pre-commit.ci
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
Member
|
Sigh |
VincentRPS
previously requested changes
Apr 2, 2023
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
JustaSqu1d
requested changes
Apr 18, 2023
Co-authored-by: JustaSqu1d <overenchanted.gaming@gmail.com> Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
Member
|
@Lulalaby any updates? |
Contributor
Author
Check this message by Lala in the discord server |
Contributor
|
Please fix merge conflicts |
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
Lulalaby
previously approved these changes
Apr 29, 2023
Member
|
i rly had a stroke rn lol |
Member
|
@plun1331 ping pong |
plun1331
approved these changes
May 1, 2023
Lulalaby
approved these changes
May 1, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: ignorecomments were used, a comment is also left explaining why.