1
votes

So, the title basically explains my question for my Discord bot in a brief form. More specifically, if a music track comes first in queue and it doesn't follow the guild-configured guidelines such as if it contains profanity, the audio has an approved copyright infringement complaint submitted to us through the bot's website by the original publisher prohibiting listening to the audio or it's a screamer, it will automatically say a message such as the following:

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.

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.

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.

Would it be possible to program and automatic voice for a Discord bot?

Thanks in advance.

1
It is trivial to send an audio file, and you don't seem to need dynamic speech generation; just prerecord the message and dump it into Discord as needed? If you do need text-to-speech, there's google-tts-api.Amadan
Ok, I'll try it.Brandon

1 Answers

3
votes

I'll help you implement user Amadan's idea into discord.py, first you'll need to install the google text to speech python api:

pip install gtts

This answer will assume that you're not using the rewrite branch of 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()

Now in discord, when you are in a voice channel and type <prefix>play <num>, where prefix is the bot prefix and num (1-3) is the index of the message you want to play, the bot will say the message.