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 asyncio
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from contextlib import asynccontextmanager, suppress
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@@ -41,11 +40,6 @@ MEDIA_EXTENSIONS = (
|
|||||||
# guessed language produces fluent nonsense, so we show the transcript instead.
|
# guessed language produces fluent nonsense, so we show the transcript instead.
|
||||||
MIN_LANGUAGE_CONFIDENCE = 0.5
|
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.
|
# English language names -> ISO-639-1, so `[p]transcribe french` works.
|
||||||
LANGUAGE_NAMES = {
|
LANGUAGE_NAMES = {
|
||||||
"afrikaans": "af", "albanian": "sq", "amharic": "am", "arabic": "ar",
|
"afrikaans": "af", "albanian": "sq", "amharic": "am", "arabic": "ar",
|
||||||
@@ -359,36 +353,6 @@ class Transcribe(commands.Cog):
|
|||||||
"zh-tw": "zho_Hant", "zh-hant": "zho_Hant",
|
"zh-tw": "zho_Hant", "zh-hant": "zho_Hant",
|
||||||
}.get(code, code)
|
}.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
|
||||||
@commands.command(name="transcribe", aliases=["stt"])
|
@commands.command(name="transcribe", aliases=["stt"])
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@@ -423,7 +387,7 @@ class Transcribe(commands.Cog):
|
|||||||
return
|
return
|
||||||
origin = self._origin_note(origin_message, forwarded)
|
origin = self._origin_note(origin_message, forwarded)
|
||||||
|
|
||||||
async with ctx.typing(), self._slow_notice(ctx):
|
async with ctx.typing():
|
||||||
try:
|
try:
|
||||||
data = await self._download(attachment)
|
data = await self._download(attachment)
|
||||||
if not data:
|
if not data:
|
||||||
|
|||||||
+2
-2
@@ -66,9 +66,9 @@ The result header names both languages in the form `Source to Target`. When the
|
|||||||
|
|
||||||
Replies are clipped near 1900 characters, with the note that the text was cut off.
|
Replies are clipped near 1900 characters, with the note that the text was cut off.
|
||||||
|
|
||||||
## Progress and errors
|
## Errors
|
||||||
|
|
||||||
The command holds a typing indicator for the whole operation. If a request is still running after three seconds, including the download and any translation, the bot posts a short notice that it is still transcribing. The notice is deleted when the request finishes, whether it succeeds or fails. Short clips complete before the delay and never show it.
|
The command holds a typing indicator for the whole operation.
|
||||||
|
|
||||||
Service errors are prefixed with a warning symbol and include the specific cause:
|
Service errors are prefixed with a warning symbol and include the specific cause:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user