...
import atexit, shelve, asyncio, random, time, math, datetime, sys, os, pickle
from gtts import gTTS
from gtts.tts import tts_langs as tl
import discord
from discord.ext import commands
from discord_components import *
bot = commands.Bot(command_prefix="&")
@bot.command(aliases=["tp","ttsp"])
async def ttsplay(ctx, lang, *string):
global storage
if string:
if lang in tl():
t = gTTS(text=str(' '.join(string)), lang=lang)
if os.path.isdir(f"./storage/{ctx.guild.id}"):
t.save(f"./storage/{ctx.guild.id}/tts-result.mp3")
else:
os.mkdir(f"./storage/{ctx.guild.id}")
t.save(f"./storage/{ctx.guild.id}/tts-result.mp3")
if not ctx.voice_client:
vc = await ctx.author.voice.channel.connect()
elif ctx.author.voice.channel and ctx.author.voice.channel != ctx.voice_client.channel:
await bot.voice_cilent_in(ctx.message.server).disconnect()
vc = await ctx.author.voice.channel.connect()
else:
vc = ctx.guild.voice_client
vc.play(discord.FFmpegPCMAudio(f"./storage/{ctx.guild.id}/tts-result.mp3"), after=lambda e: print(e))
await ctx.send("done!")
else:
await ctx.send(embed = discord.Embed(
title = f":warning: 지원하지 않는 언어입니다.",
description = f"```지원 언어 목록 : {', '.join(list(tl().keys()))}```",
colour = discord.Colour.red()))
else:
await ctx.send(embed = discord.Embed(
title = ":warning: tts로 변환할 인자가 주어지지 않았습니다. ( &tts <언어> <문장> )",
color = discord.Colour.red()
))
bot.run("token")
I did like this, but the bot displays as playing sound, but not sound comes out. how can i fix this? i have ffmpeg.exe, ffplay.exe, ffprobe.exe in The script's path. and, the audio is saved in the folder with name(ctx.guild.id).
pip install pynacl
fixed it. Good luck. – Xephire