Last active
October 17, 2018 16:27
-
-
Save JellyWX/9b414eedfa497793405097a2fa64ea63 to your computer and use it in GitHub Desktop.
Code sample of a D.py function to perform TTS using pico2wave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ln -s /dev/stdout ./stdout.wav |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async def tts(self, message, stripped, server): | |
# command: espeak --stdout "hello world" | ffmpeg -i pipe:0 out.ogg | |
caller = message.author | |
guild = message.guild | |
if 'off' not in server.roles and not caller.guild_permissions.manage_guild: | |
for role in caller.roles: | |
if role.id in server.roles: | |
break | |
else: | |
await channel.send('You aren\'t allowed to do this. Please tell a moderator to do `{}roles` to set up permissions'.format(server.prefix)) | |
return | |
if caller.voice is None: | |
await channel.send('You aren\'t in a voice channel.') | |
elif not caller.voice.channel.permissions_for(guild.me).connect: | |
await channel.send('No permissions to connect to channel.') | |
else: | |
try: | |
voice = await caller.voice.channel.connect() | |
except discord.errors.ClientException: | |
voice = [v for v in self.voice_clients if v.channel.guild == guild][0] | |
if voice.channel != caller.voice.channel: | |
await voice.disconnect() | |
voice = await caller.voice.channel.connect() | |
if voice.is_playing(): | |
voice.stop() | |
s = subprocess.Popen(['pico2wave', '-w', 'stdout.wav', '"{}"'.format(stripped)], stdout=subprocess.PIPE) | |
s2 = subprocess.Popen(['ffmpeg', '-i', '-', '-f', 's16le', '-ar', '48000', '-ac', '2', '-loglevel', 'warning', 'pipe:1'], stdin=s.stdout, stdout=subprocess.PIPE) | |
voice.play(discord.PCMAudio(s2.stdout)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment