Turned Telegram Into a Local AI Voice Studio
From the publisher’s feed, collected in the ZeroLabs newsroom.
Designed a Telegram assistant capable of voice generation, voice design, and multi-step voice cloning conversations using local inference.Source: Image by Cc0images on DreamstimeTable of ContentshIntroductionGet StartedHow It WorksGoing Live: Backend SetupResultsConclusionReferencesIntroductionHigh-quality Text-to-Speech (TTS) models usually require you to sit at a computer, load a heavy interface, and manage audio files manually. But what if you could design and clone voices directly from your phone?In this article, we will build a Telegram bot powered by FastAPI and the state-of-generation Qwen3-TTS model. This bot will understand your commands to generate speech from pre-trained characters, design completely new voices from text descriptions, and clone voices using short audio samples, all within a standard Telegram chat.Get StartedYou will need basic Python knowledge, a machine with a CUDA-enabled GPU (recommended for Qwen3-TTS), and Git. Before diving into the AI logic, we need to set up the Telegram bot and our local environment.1. Create your Bot with BotFatherOpen Telegram, search for @BotFather (verified checkmark), and send /newbot. It will ask for two names:Name: display name (e.g., Cuentts Bot)Username: unique handle ending in bot (e.g., cuentts_bot)Save the API Token it generates. Your Python code needs this to send audio files back to the user.2. Set up the ProjectI have prepared a repository that handles the FastAPI server, the PyTorch memory management, and the Telegram webhook integration.Open your terminal and run:git clone https://github.com/anmerino-pnd/cuentts.git cd cuentts3. Environment SetupWe use uv for ultra-fast dependency management. To ensure everything runs smoothly, create the virtual environment, install the package, and sync the dependencies:uv venv uv pip install -e . uv sync4. ConfigurationBefore running the code, we need to configure our credentials. Open your environment configuration file and add your Telegram token:TELEGRAM_BOT_TOKEN="123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ"How It WorksUnlike standard polling bots, this architecture relies on Webhooks and FastAPI for asynchronous, non-blocking execution, while PyTorch handles the heavy lifting of the TTS model.The Request Flow: When a user sends a message, Telegram makes a POST request to our FastAPI /webhook endpoint. The server parses the text, identifies the command (/generate, /design, or /clone), and extracts the arguments.The Qwen3-TTS Engine: The core processing happens in our TTS class. To prevent server crashes, the model is loaded in bfloat16 precision (if CUDA is available) and we enforce strict memory clearing (torch.cuda.empty_cache()) after every generation cycle.In-Memory File Transfer: Instead of saving WAV files to the hard drive, our engine converts the NumPy arrays generated by Qwen3-TTS directly into an io.BytesIO object. This allows us to pipe the audio straight to Telegram’s API, making the bot significantly faster and keeping our server storage clean.Going Live: Backend SetupWe need Telegram to reach our local server. A FastAPI webhook combined with an Ngrok tunnel makes this possible.Start the FastAPI server:uv run uvicorn main:app - reloadExpose it to the internet with Ngrok:ngrok http 8000Copy the Forwarding URL from Ngrok’s output (e.g., https://your-url.ngrok-free.app).Finally, tell Telegram where to send the messages by hitting the setWebhook endpoint in your browser. Replace the placeholders with your actual bot token and the Ngrok URL (make sure it ends in /webhook):https://api.telegram.org/bot/setWebhook?url=/webhookResultsThe bot exposes the three main capabilities of Qwen3-TTS through intuitive commands.Basic Generation ( /generate)You can use one of the model’s pre-trained voices by specifying the character, the text, and an optional instruction separated by a pipe character (|).VivianVoice Design (/design)If you need a specific type of voice that isn’t in the presets, you can design it from scratch using natural language.Older manVoice Cloning (/clone)This is a guided, state-based flow. Telegram does not allow sending audio and text in the same step easily, so the bot orchestrates a conversation:Me clonedConclusionBy integrating FastAPI, PyTorch, and Qwen3-TTS, we have created a powerful, accessible tool for voice synthesis. You no longer need to rely on complex web interfaces; you have a state-of-the-art voice generation and cloning studio right in your Telegram chats.ReferencesQwenLM/Qwen3-TTS: Qwen3-TTS is an open-source series of TTS models developed by the Qwen team at Alibaba Cloud, supporting stable, expressive, and streaming speech generation, free-form voice design, and vivid voice cloning. (2025). GitHub. https://github.com/QwenLM/Qwen3-TTS?spm=a2ty_o06.30285417.0.0.2994c9217vIfOY#environment-setupyoutube-tutorial-sources/Notebooks/TTS/Qwen3_TTS_Tutorial.ipynb at main · alarcon7a/youtube-tutorial-sources. (2025). GitHub. https://github.com/alarcon7a/youtube-tutorial-sources/blob/main/Notebooks/TTS/Qwen3_TTS_Tutorial.ipynbTurned Telegram Into a Local AI Voice Studio was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.