From 32f512a5fa8bfe58cb35e2cb1badc57e636b0bc3 Mon Sep 17 00:00:00 2001 From: nex Date: Sun, 3 Dec 2023 22:52:41 +0000 Subject: [PATCH] support any audio file --- cogs/other.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 26f1581..4243615 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -2451,8 +2451,10 @@ class OtherCog(commands.Cog): if not message.attachments: return await ctx.respond("No attachments found.") + _ft = "wav" for attachment in message.attachments: - if attachment.content_type == "audio/ogg": + if attachment.content_type == "audio/": + _ft = attachment.filename.split(".")[-1] break else: return await ctx.respond("No voice messages.") @@ -2469,7 +2471,7 @@ class OtherCog(commands.Cog): with tempfile.NamedTemporaryFile("wb+", suffix="-" + attachment.filename) as f2: await attachment.save(f2.name) f2.seek(0) - seg: pydub.AudioSegment = await asyncio.to_thread(pydub.AudioSegment.from_ogg, file=f2) + seg: pydub.AudioSegment = await asyncio.to_thread(pydub.AudioSegment.from_file, file=f2, format=_ft) seg = seg.set_channels(1) await asyncio.to_thread( seg.export, f.name, format="mp4"