Python Discord.py:播放音频到语音频道的速度加快
我使用Discord.py制作了一个简单的Discord机器人,它可以播放本地文件中的短音频片段,并在播放结束后离开。机器人工作得很好,但现在所有的音频都在加速。我没有更改代码中的任何内容。有一些音频剪辑可以选择,有些明显加快了速度,而有些甚至有时不播放。提速也不一致 主代码Python Discord.py:播放音频到语音频道的速度加快,python,ffmpeg,discord,discord.py,Python,Ffmpeg,Discord,Discord.py,我使用Discord.py制作了一个简单的Discord机器人,它可以播放本地文件中的短音频片段,并在播放结束后离开。机器人工作得很好,但现在所有的音频都在加速。我没有更改代码中的任何内容。有一些音频剪辑可以选择,有些明显加快了速度,而有些甚至有时不播放。提速也不一致 主代码 @bot.event async def on_ready(): print('Logged in as {0.user}'.format(bot)) @bot.command() async def meme(
@bot.event
async def on_ready():
print('Logged in as {0.user}'.format(bot))
@bot.command()
async def meme(ctx, message):
server = ctx.message.guild.name
#check if user is in voice channel or if command is valid
if not ctx.author.voice:
return await ctx.send("Join a voice channel!")
else:
if message in audioPathsDict:
audioPath = audioPathsDict[message]
else:
return await ctx.send("Not a valid command!")
#voice_channel is channel of command author
voice_channel = ctx.message.author.voice.channel
try:
vc = await voice_channel.connect()
print(f"Played {audioPath} in Voice Channel: {voice_channel}, Server: {server}\n")
except:
print("Already Connected to a voice channel")
voice = discord.utils.get(bot.voice_clients,guild = ctx.guild)
vc.play(FFmpegPCMAudio(audioPath))
vc.source = discord.PCMVolumeTransformer(vc.source)
vc.source.volume = 0.1
while vc.is_playing():
await sleep(2)#while audio is playing wait 0.5 then disconnect
await vc.disconnect()