mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
support any audio file
This commit is contained in:
parent
248d300c47
commit
32f512a5fa
1 changed files with 4 additions and 2 deletions
|
@ -2451,8 +2451,10 @@ class OtherCog(commands.Cog):
|
||||||
if not message.attachments:
|
if not message.attachments:
|
||||||
return await ctx.respond("No attachments found.")
|
return await ctx.respond("No attachments found.")
|
||||||
|
|
||||||
|
_ft = "wav"
|
||||||
for attachment in message.attachments:
|
for attachment in message.attachments:
|
||||||
if attachment.content_type == "audio/ogg":
|
if attachment.content_type == "audio/":
|
||||||
|
_ft = attachment.filename.split(".")[-1]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return await ctx.respond("No voice messages.")
|
return await ctx.respond("No voice messages.")
|
||||||
|
@ -2469,7 +2471,7 @@ class OtherCog(commands.Cog):
|
||||||
with tempfile.NamedTemporaryFile("wb+", suffix="-" + attachment.filename) as f2:
|
with tempfile.NamedTemporaryFile("wb+", suffix="-" + attachment.filename) as f2:
|
||||||
await attachment.save(f2.name)
|
await attachment.save(f2.name)
|
||||||
f2.seek(0)
|
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)
|
seg = seg.set_channels(1)
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
seg.export, f.name, format="mp4"
|
seg.export, f.name, format="mp4"
|
||||||
|
|
Loading…
Reference in a new issue