transcribe: remove the slow request notice
The notice could survive beside a finished transcript, leaving a take a moment message under a completed reply. The typing indicator covers the wait, so drop the separate notice and its cleanup task.
This commit is contained in:
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
from contextlib import asynccontextmanager, suppress
|
||||
from typing import Optional
|
||||
|
||||
import aiohttp
|
||||
@@ -41,11 +40,6 @@ MEDIA_EXTENSIONS = (
|
||||
# guessed language produces fluent nonsense, so we show the transcript instead.
|
||||
MIN_LANGUAGE_CONFIDENCE = 0.5
|
||||
|
||||
# Post a progress note when a request is still running after this many seconds.
|
||||
# Long voice messages and slow CPU inference both cross this line; short clips
|
||||
# finish before the notice is sent, so they never see it.
|
||||
SLOW_REQUEST_NOTICE_SECONDS = 3.0
|
||||
|
||||
# English language names -> ISO-639-1, so `[p]transcribe french` works.
|
||||
LANGUAGE_NAMES = {
|
||||
"afrikaans": "af", "albanian": "sq", "amharic": "am", "arabic": "ar",
|
||||
@@ -359,36 +353,6 @@ class Transcribe(commands.Cog):
|
||||
"zh-tw": "zho_Hant", "zh-hant": "zho_Hant",
|
||||
}.get(code, code)
|
||||
|
||||
@asynccontextmanager
|
||||
async def _slow_notice(self, ctx: commands.Context, delay: float = SLOW_REQUEST_NOTICE_SECONDS):
|
||||
"""Tell the channel that a long transcription is still running.
|
||||
|
||||
Waits `delay` seconds before posting, and removes the notice when the
|
||||
surrounding block exits, whether it succeeded, failed or returned early.
|
||||
"""
|
||||
holder: dict[str, Optional[discord.Message]] = {"message": None}
|
||||
|
||||
async def announce():
|
||||
await asyncio.sleep(delay)
|
||||
try:
|
||||
holder["message"] = await ctx.send(
|
||||
"Still transcribing. Longer recordings can take a moment."
|
||||
)
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
|
||||
task = asyncio.create_task(announce())
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
task.cancel()
|
||||
with suppress(asyncio.CancelledError):
|
||||
await task
|
||||
message = holder["message"]
|
||||
if message is not None:
|
||||
with suppress(discord.HTTPException):
|
||||
await message.delete()
|
||||
|
||||
# ----------------------------------------------------------------- commands
|
||||
@commands.command(name="transcribe", aliases=["stt"])
|
||||
@commands.guild_only()
|
||||
@@ -423,7 +387,7 @@ class Transcribe(commands.Cog):
|
||||
return
|
||||
origin = self._origin_note(origin_message, forwarded)
|
||||
|
||||
async with ctx.typing(), self._slow_notice(ctx):
|
||||
async with ctx.typing():
|
||||
try:
|
||||
data = await self._download(attachment)
|
||||
if not data:
|
||||
|
||||
Reference in New Issue
Block a user