Urgent.News

What's breaking now, across thousands of outlets.

Tech

Build a Real-Time Voice Translation App

Getting Started with a Real‑Time Voice Translation App Building a real‑time voice translation app feels like science‑fiction, but with today’s cloud APIs it’s a very achievable side‑project. In this article we’ll walk through the whole stack: capturing audio, transcribing it, translating the text, and finally turning the translated text back into speech. We’ll keep the example language‑agnostic…

Creating a real-time voice translation app may seem like a futuristic endeavor, but with today's cloud APIs, it is entirely feasible for a side project. This article outlines the entire process, from capturing audio to synthesizing speech in the target language. The example is language-agnostic, using Python for the backend and JavaScript for the frontend, and leveraging several reliable services.

ElevenLabs is the key player, offering top-notch text-to-speech (TTS) and voice-cloning features. You can test their free tier at https://try.elevenlabs.io/kr07zfuqn1bp.

Latency is crucial when building language-learning apps, travel chatbots, or customer support tools. Delays of 2 seconds are acceptable, while 5 seconds become noticeable. To achieve fast processing, we need: fast speech-to-text (STT) with a response time of around 1 second per sentence, quick translation within 200-400 milliseconds, and low-latency TTS that delivers the synthesized voice within 1 second.

This guide assumes you have API keys for an STT provider (Google Cloud Speech-to-Text, Azure Speech, or Whisper) and a translation service (Google Translate, DeepL, or Microsoft Translator). ElevenLabs will handle the TTS portion.

The high-level architecture comprises four components: the browser (JavaScript), a Node.js/Flask API, and ElevenLabs TTS. The browser captures microphone audio via the Web Audio API and streams it to the backend through a WebSocket. The backend forwards audio chunks to the STT service, then to the translation service, and finally to ElevenLabs for synthesis. ElevenLabs returns an MP3 or raw PCM stream that the browser plays back.

The front-end JavaScript snippet records microphone input and streams it to the server using WebSocket. It utilizes the MediaRecorder API for simplicity. The code sends audio chunks as binary data to the WebSocket, which then sends them to the backend. After the buffer reaches a threshold (250ms chunks in this example) or detects silence, the backend sends the audio to the STT API, proceeds with translation, and receives the synthesized speech from ElevenLabs.

The backend handles asynchronous tasks, such as connecting to the STT and translation APIs, using aiohttp for async HTTP requests. It also includes functions for transcribing audio, translating text, and sending the translated text to ElevenLabs for TTS.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Harvard's field data on coding agents: +30% code, +49% review time, flat output

A 78-page job market paper landed last week that puts field numbers on the argument everyone has been having from vibes. Fiona Chen and James Stratton at Harvard wrote it using a proprietary dataset…

  • AI coding assistants increased code lines by 30%
  • Review times rose by 49%, with more comments per pull request
  • Overall software output remained flat despite AI tool usage

Offline PDV: how a cash register keeps selling when the internet goes down

Internet caiu no meio do pico de vendas. Fila no caixa, cliente com o carrinho cheio e o sistema na nuvem fora do ar. Quem trabalha com varejo já viu isso acontecer.

  • Cash registers can sell offline using PDV system
  • Sales recorded directly on cash register during internet outage
  • Offline queue synchronized with server when internet restored

More from Saturday 17 October →