首页 > 解决方案 > 使用 discord.py 将 mp3 播放到语音频道

问题描述

我正在尝试制作一个文本转语音机器人,供人们在无麦克风聊天中使用,以对语音频道讲话。我发现其他文章对此进行了解释,但其中大多数都显示了 windowsffmpeg版本,但我在 Mac 上。到目前为止,这是我的代码:

@bot.command()
async def speak(ctx, message):
    tts = gtts.gTTS(message, lang="en")
    tts.save("text.mp3")
    if ctx.guild.voice_client:
        vc = ctx.guild.voice_client
    else:
        voice_channel = get(ctx.guild.voice_channels, name="Voice Lounge")
        vc = await voice_channel.connect()
    vc.play(source='text.mp3')

这给了我错误: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: ffmpeg was not found.

有人说要指定 FFMPEG.exe 文件,但我没有看到。我从下载了 FFMPEG gitgit clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

但我仍然得到错误。其他文章说要指定可执行文件,但我找不到任何ffmpeg.exe我必须为其指定路径的文章。

提前致谢

标签: pythonffmpegdiscorddiscord.py

解决方案


推荐阅读