python - 使用 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
我必须为其指定路径的文章。
提前致谢
解决方案
推荐阅读
- swift - 如何删除 tableView 单元格并从 firebase 中删除数据
- python - 如何对 Pandas 系列中的行求和?
- rust - 避免共享静态变量的“同步”
- java - 如何在 Junit 5 中使用 CsvFileSource 转义参数化测试中的双引号
- dataframe - 将 pyspark 数据帧值转换为可变字符串值
- java - 切换日/夜模式时如何为组件(工具栏、搜索栏、操作栏等)设置自定义颜色?
- nhibernate - 在字符串属性上搜索不等式
- reactjs - 如何使用 springboot 和 reactjs 正确配置 websocket?
- sql - SQL - 如何在一年中的每个日期按年龄和状态对项目进行分组/计数?
- android - 每次退出应用程序后,用户都会重复相同的通知