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

Posted

技术标签:

【中文标题】在 python 中使用 ffmpeg 将音频文件转换为 mp3【英文标题】:Convert audio files to mp3 using ffmpeg in python 【发布时间】:2022-01-06 15:50:58 【问题描述】:

我正在为 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')


【问题讨论】:

到目前为止你有什么tried? 这能回答你的问题吗? Convert audio files to mp3 using ffmpeg 【参考方案1】:

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

这会让事情变得更容易。

【讨论】:

以上是关于在 python 中使用 ffmpeg 将音频文件转换为 mp3的主要内容,如果未能解决你的问题,请参考以下文章

能够使用 ffmpeg 和 python 读取当前音频帧

如何使用Python来提取视频中的音频

如何通过传递文件对象(而不是磁盘上文件的位置)将 ffmpeg 与 Python 一起使用

ffmpeg+Python实现B站MP4格式音频与视频的合并

使用ffmpeg从视频文件中提取音频文件视频抽帧和切割视频

ffmpeg:如何将音频波文件循环到没有任何音频通道的视频中