ToshaMusic: checking Hi-Res music in Telegram
our own Telegram bot: true FLAC quality by spectrum, honest tags, files up to 2 GB
A Telegram bot for our own Hi-Res music library: it measures the real bit depth, sample rate and spectral cutoff of FLAC, catches transcodes and upsampled CD masters, writes the file name and tags only from what was measured, and sends files up to 2 GB. A task queue, an admin panel and a headless mode for embedding.
The task
Hi-Res is often promised but not always delivered. A release is labelled "24 bit / 192 kHz", yet inside is an ordinary CD master stretched to the right numbers. There is also "pseudo-lossless": a FLAC built from an MP3, with a cut-off spectrum. Ordinary programs trust the tags and put into the library something that is not Hi-Res either by ear or by spectrum.
We needed a bot that solves three problems. Not to be fooled: measure the bit depth, sample rate and spectral cutoff frequency, compare them with the claim and honestly report any mismatch in the chat. To bring order: the file name and tags only from what was measured. To handle the load: a queue with limited parallelism and transfer of files up to 2 GB.
The solution
ToshaMusic, our own asynchronous Telegram bot, version 1.1.2. What was done:
- Release card. Cover art, artist, title, album, number of tracks, duration, date, label, genre, claimed quality.
- Verification. ffprobe, mutagen and spectral analysis; the file name, tags and verification line come only from measurements.
- Queue. A worker pool with a limit on parallel tasks, an overall queue limit and a per-user limit; cancelling a task in the queue and while it runs; clear error messages.
- Sending. A local Bot API, files up to 2000 MB, a cover thumbnail, an uncompressed ZIP for long releases, retries on flood control.
- Admin panel. Statistics with the number of fakes caught and the breakdown by real quality, users with bans and history, broadcasts, settings,
/versionand/sysinfo. - Headless mode. The same engine as a separate service with an internal HTTP API for embedding into another bot.
How it works
ffprobe and mutagen: checking the bit depth
ffprobe (a utility from FFmpeg) reads the codec, sample rate, bit depth, bitrate, number of channels and duration. For FLAC, ffprobe often reports the container's 32 bits instead of the real 24, so the bit depth is refined by mutagen, an audio tag library. If 24/192 is claimed but the actual figure is 16/44.1, a warning goes to the chat.
The lossless cutoff spectrum: how a fake is caught
A fragment from the middle of the track is decoded to PCM (uncompressed audio samples), and an averaged FFT (fast Fourier transform, which splits a signal into frequencies) is used to find the frequency above which the spectrum is empty. A cutoff in the 14β20.6 kHz range marks the file as transcoded from lossy. Emptiness above 24 kHz with a claimed 96 or 192 kHz gives away an upsampled CD master. A 19β20.6 kHz cutoff also occurs in honest dark mastering, so that warning is worded softly, and a definite verdict is given only for a cutoff below 19.5 kHz. The analysis can be turned off in the settings.
Name and tags only from measurements
The file name is built from the actual parameters: Artist - Title [24bit-192kHz].flac. A verification line with the bit depth, sample rate, bitrate, cutoff frequency and the ToshaMusic version is written into the tags, along with a QUALITY_VERIFIED field. This way the library has no files whose numbers in the name differ from their content.
A queue with limited parallelism
A worker pool on top of asyncio.Queue keeps a limit on simultaneous tasks (2 by default), an overall queue limit and a per-user task limit. The status in the chat is updated by stage: preparation, verification, tags, sending. Each task has an isolated working directory, abandoned directories are cleaned up at startup, and tasks left hanging after a crash are marked as interrupted.
Local Bot API: files up to 2 GB
The cloud Bot API limits file sending to 50 MB. Next to the bot, a local telegram-bot-api runs in Docker in local mode: the file is passed as a path on disk without copying, with a 2000 MB limit. The data directory is mounted at the same path in both containers, otherwise the server would not see the file.
Headless mode for embedding
Since version 1.1.0 the project has two entry points. The regular one starts the aiogram bot. The second creates no bot at all: the same database, queue and engine work behind an internal HTTP API with routes for the card, tasks, cancellation and confirmation. Finished files are passed through a shared volume, and business errors are returned as typed responses. A crash of the engine does not affect the consuming bot: they run in different containers.
Results
- Hi-Res fakes are detected by spectrum, a mismatch with the claimed quality is visible in the chat, and the file name and tags match the content.
- Files up to 2 GB go to Telegram directly, with no limit error.
- Failures do not break the work: errors are explained in clear text.
- The engine can be embedded into another bot over HTTP.
Technologies and why
- Python 3.13 and aiogram 3: an asynchronous bot, FSM for admin scenarios, inline keyboards only.
- pydantic-settings: configuration with type checking.
- SQLAlchemy 2.0 async and Alembic: models for users, tasks, tracks, settings and broadcasts; migrations checked against the models.
- aiohttp: the HTTP server for headless mode.
- FFmpeg, ffprobe, mutagen, numpy: measuring parameters, decoding a fragment, FFT to find the cutoff frequency.
- loguru: logs with rotation, a separate error file.
- Local Bot API: sending files up to 2000 MB.
- Docker Compose: the bot and telegram-bot-api with a shared data directory, TZ=Europe/Moscow.
Status
Our own product, in production. The current version is 1.1.2 of 8 September 2026. Version 1.1.0 (3 September 2026) added headless mode, and 1.0.0 (19 August 2026) was the first working release.
Limitations: admin scenario states live in memory and are reset on restart. Planned: FSM storage in Redis, statistics export to CSV, conversion to ALAC/AAC, saving the spectrogram as evidence, pytest coverage.
Questions about this project
How do you check that a FLAC is true Hi-Res and not an MP3?
What is Hi-Res, and why can't the label be taken at its word?
How does the bot send files larger than 50 MB?
What happens if the claimed quality is not confirmed?
Can the check be embedded into another bot?
More in this area
Telegram media bot: video and audio from a link, right in the chat
our own bot: quality choice up to 4K, MP3 with cover art, files up to 2 GB
Telegram ticketing system for an IT department
for a museum complex in Moscow: tickets, asset tracking, knowledge base and analytics
Finance Assistant: PDF bank statements to a Telegram budget
our own product: a bot and web dashboard, four banks' statements, Gemini
Need something similar?
Tell us about the task β we'll show how we solved it and estimate the scope.