可以为Discord音乐机器人编写自动语音吗?

时间:2018-06-11 05:56:44

标签: python bots discord discord.py

所以,标题基本上以简短的形式解释了我对我的Discord机器人的问题。更具体地说,如果音乐曲目排在队列中并且它不遵循公会配置的指南,例如它是否包含亵渎性质,那么音频会通过僵尸网站由原始发布者提交给我们的批准版权侵权投诉,禁止收听对于音频或它是一个尖叫者,它会自动说出如下信息:

  

此时播放的当前音乐音量太大或超出音高的频率限制。跳到队列中的下一首音乐。

     

此时计划播放的当前音乐已被标记为包含亵渎性语言,并且不符合公会配置的指南。跳到队列中的下一首音乐。

     

此时计划播放的当前音乐有版权侵权投诉,表明原始发布者限制收听音频。跳到队列中的下一首音乐。

是否可以为Discord bot编程和自动语音?

提前致谢。

1 个答案:

答案 0 :(得分:3)

我会帮助您将用户Amadan的想法变为discord.py,首先您需要安装Google文本到语音python api:

pip install gtts

此答案将假设您使用discord.py的重写分支

import os
import discord
from gtts import gTTS

if not discord.opus.is_loaded():
    # or libopus.so on linux in the current directory
    # you should replace this with the location the
    # opus library is located in and with the proper filename.
    discord.opus.load_opus('opus')

if not os.path.exists('message1.mp3'):

    tts = gTTS("The current music scheduled to play at this time is too intense in volume or exceeds "
               "the frequency limits for pitch. Skipping to next music in queue.")
    with open('message1.mp3', 'wb') as f:
        tts.write_to_fp(f)

if not os.path.exists('message2.mp3'):
    tts = gTTS("The current music scheduled to play at this time has been marked for containing profane"
               " language and does not comply with the guild-configured guidelines. "
               "Skipping to next music in queue.")
    with open('message2.mp3', 'wb') as f:
        tts.write_to_fp(f)

if not os.path.exists('message3.mp3'):
    tts = gTTS("The current music scheduled to play at this time has a copyright infringement complaint "
               "which indicates that the original publisher restricts listening to the audio. "
               "Skipping to next music in queue.")
    with open('message3.mp3', 'wb') as f:
        tts.write_to_fp(f)

@bot.command(pass_context=True)
async def play(ctx, num):
    vc = ctx.author.voice.voice_channel

    voice = await bot.join_voice_channel(vc)

    player = voice.create_ffmpeg_player('message{}.mp3'.format(num))
    player.start()

现在处于不和中,当你在语音通道中并输入<prefix>play <num>时,前缀是机器人前缀,而num(1-3)是你想要播放的消息的索引,机器人会说消息。

相关问题