Fix quote tts
This commit is contained in:
9
bot.py
9
bot.py
@@ -795,11 +795,12 @@ async def quote_random_slash(ctx: SlashContext, author: Optional[str] = None, tt
|
|||||||
if tts:
|
if tts:
|
||||||
voice: discord.VoiceState = ctx.author.voice
|
voice: discord.VoiceState = ctx.author.voice
|
||||||
if voice.channel is not None:
|
if voice.channel is not None:
|
||||||
async def after_play(e: discord.DiscordException, vp: discord.VoiceProtocol):
|
source, tts_destroyer = text_to_speech(author + " sagte: " + quote)
|
||||||
await vp.disconnect(force=True)
|
vp: discord.VoiceClient = await connect_and_play(voice.channel, source)
|
||||||
|
while vp.is_playing() and vp.channel == voice.channel:
|
||||||
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
source, tts_destroyer = text_to_speech(quote)
|
await vp.disconnect()
|
||||||
await connect_and_play(voice.channel, source, after_play=after_play)
|
|
||||||
tts_destroyer()
|
tts_destroyer()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ def text_to_speech(text: str, lang: str = "de") -> (discord.AudioSource, Callabl
|
|||||||
|
|
||||||
async def connect_and_play(
|
async def connect_and_play(
|
||||||
channel: discord.VoiceChannel, source: discord.AudioSource,
|
channel: discord.VoiceChannel, source: discord.AudioSource,
|
||||||
after_play: Optional[Callable[[discord.DiscordException, discord.VoiceProtocol], Coroutine[Any, Any, Any]]] = None
|
after_play: Optional[Callable[[discord.DiscordException, discord.VoiceProtocol], Any]] = None
|
||||||
) -> Optional[discord.VoiceProtocol]:
|
) -> Optional[discord.VoiceClient]:
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
client: discord.VoiceClient = await channel.connect()
|
client: discord.VoiceClient = await channel.connect()
|
||||||
after_callback: Optional[Callable[[discord.DiscordException], Any]]
|
after_callback: Optional[Callable[[discord.DiscordException], Any]]
|
||||||
@@ -62,8 +62,7 @@ async def connect_and_play(
|
|||||||
after_callback = None
|
after_callback = None
|
||||||
else:
|
else:
|
||||||
def callback(exc: discord.DiscordException) -> Any:
|
def callback(exc: discord.DiscordException) -> Any:
|
||||||
loop = asyncio.get_event_loop()
|
after_play(exc, client)
|
||||||
return loop.run_until_complete(after_play(exc, client))
|
|
||||||
|
|
||||||
after_callback = callback
|
after_callback = callback
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user