python - 机器人图标显示为播放声音,但没有声音播放
问题描述
...
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)的文件夹中。
解决方案
推荐阅读
- python - 使用 Matplotlib 在图形上绘制 SQL 结果
- java - jsp 文件和 servlet 究竟是如何相互交互的?
- javascript - 输入选择文本,但仅在第一个焦点上(在移动设备上)
- javascript - 如何根据 iframe 大小调整引导模式的大小?
- c# - wix 为不同的目录重用 ComponentGroup
- elasticsearch - 如何在 kibana 仪表板 6.6.0 版中更改字体大小?
- typescript - VSCode 通过扩展修改文件资源管理器外观
- firebase - 我可以使用 Cloud Functions for Firebase 每天运行两次网络抓取工具吗?
- makefile - GNU Make:拆分文件(串行),然后处理部分(并行)
- sql - Oracle SQL - 从单行的列组合派生多行