首页 > 解决方案 > 机器人图标显示为播放声音,但没有声音播放

问题描述

...
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")

我确实喜欢这个,但机器人显示为播放声音,但没有声音出来。我怎样才能解决这个问题?我在脚本路径中有 ffmpeg.exe、ffplay.exe、ffprobe.exe。并且,音频保存在名称为(ctx.guild.id)的文件夹中。

标签: pythondiscord.pypycord

解决方案


推荐阅读