在 python 中使用 ffmpeg 将音频文件转换为 mp3

Convert audio files to mp3 using ffmpeg in python

我正在为 Dyscord 从事 BOT 行业工作,我需要在动力学知识中播放语音片段我有一台 32 位计算机

import discord
from discord.ext import commands
import os
client = commands.Bot(command_prefix="!")
@client.command()
async def play(ctx, url : str):
    print('We have logged in as {0.user}'.format(client))
    voiceChannel = discord.utils.get(ctx.guild.voice_channels, name="Lounge")
    await voiceChannel.connect()
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)

    voice.play(discord.FFmpegPCMAudio("song.mp3"))

@client.command()
async def ext(ctx):
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    await voice.disconnect()

client.run('token')


嘿嘿!我建议查看此 GitHub 存储库:https://github.com/pariweshsubedi/python-ffmpeg-audio-converter

它会让事情变得更简单。