ai newsSo., 1. Nov.
EilmeldungA ChatGPT Share Link Could Run Code Through MathLive. MathLive 0.111.2 Now Checks Origins

How to Build a Pronunciation Guide App with AI Voice

Why a Pronunciation Guide App Matters When learning a new language, the first hurdle is usually the “I can’t pronounce this word” moment. Traditional apps give you a text definition, but they rarely let you hear the word in a natural, context‑rich way. That’s where an AI‑powered pronunciation guide

dev.toSamstag 23:18 · 31.10.6 Min. Lesezeit
Bild: dev.to

When learning a new language, the first hurdle is usually the “I can’t pronounce this word” moment. Traditional apps give you a text definition, but they rarely let you hear the word in a natural, context‑rich way. That’s where an AI‑powered pronunciation guide comes in: you type a word or phrase, and a realistic voice reads it aloud, optionally breaking it down into syllables, showing stress patterns, and even comparing it to a native speaker’s rendition.

If you’re a developer who’s already tinkering with voice APIs or just curious about how TTS (text‑to‑speech) and voice cloning can be combined into a learning tool, this article is your starting point. We’ll walk through the core components, show you how to wire them together with ElevenLabs, and give you a few code snippets to get you up and running.

+----------------+ +------------------+ +----------------+ | Frontend UI | <------> | API Gateway | <------> | TTS Service | | (React/Vue) | | (Node.js/Express)| | (ElevenLabs) | +----------------+ +------------------+ +----------------+ | | | | GET /pronounce?text=… | | | ----------------------------> | | | | POST /v1/text-to-speech | | | ----------------------> | | | <---------------------- | | | Audio Stream | | <---------------------------- | | | | | Enter fullscreen mode Exit fullscreen mode Frontend – a simple input box, a play button, and optional controls for speed or pitch. API Gateway – receives the request, passes the text to the TTS service, streams the audio back to the client. TTS Service – in this example, ElevenLabs’ API, which can do standard TTS and also clone a user’s voice for a more personalized experience.

The biggest win is that the heavy lifting (audio generation) is off‑loaded to ElevenLabs. Their API is fast, supports a wide array of voices, and even offers voice cloning with just a few dozen seconds of sample audio.

Sign up – head over to the affiliate link: https://try.elevenlabs.io/kr07zfuqn1bp This gives you a free tier with a generous number of characters per month and access to the voice cloning endpoint.

API Key – after signing up, you’ll find your key in the dashboard. Store it safely; we’ll reference it in our code.

Choose a Voice – ElevenLabs ships with dozens of high‑quality voices. For a pronunciation guide, a neutral, clear voice is usually best. You can list voices with:

curl -H "xi-api-key: YOUR_API_KEY" \ https://api.elevenlabs.io/v1/voices Enter fullscreen mode Exit fullscreen mode 3. Building the API Gateway We’ll use Node.js with Express because it’s lightweight and has great async support. Install the dependencies:

npm init -y npm install express axios dotenv Enter fullscreen mode Exit fullscreen mode Create a.env file to hold your API key:

ELEVENLABS_API_KEY = sk_XXXXXXXXXXXXXXXXXXXX Enter fullscreen mode Exit fullscreen mode Now the server ( index.js ):

require ( ' dotenv ' ). config (); const express = require ( ' express ' ); const axios = require ( ' axios ' ); const app = express (); const ELEVEN_API_URL = ' https://api.elevenlabs.io/v1/text-to-speech '; app. get ( ' /pronounce ', async ( req, res ) => { const text = req. query. text; if (! text ) return res. status ( 400 ). send ( ' Missing text parameter ' ); try { const response = await axios ({ method: ' post ', url: ELEVEN_API_URL + ' /YOUR_VOICE_ID ', // replace with your chosen voice headers: { ' xi-api-key ': process. env. ELEVENLABS_API_KEY, ' Content-Type ': ' application/json ', }, data: { text, voice_settings: { stability: 0.5, similarity_boost: 0.75, }, }, responseType: ' stream ', }); // Pipe the audio stream back to the client res. set ( ' Content-Type ', response. headers [ ' content-type ' ]); response. data. pipe ( res ); } catch ( err ) { console. error ( err ); res. status ( 500 ). send ( ' TTS request failed ' ); } }); app. listen ( 3000, () => console. log ( ' Pronunciation server running on port 3000 ' )); Enter fullscreen mode Exit fullscreen mode Tip: Replace YOUR_VOICE_ID with the ID of the voice you fetched earlier. If you want to experiment with multiple voices, expose an optional voice query param.

Here’s a tiny React component that talks to our API:

import React, { useState } from ' react '; export default function Pronounce () { const [ text, setText ] = useState ( '' ); const [ audioUrl, setAudioUrl ] = useState ( null ); const handleSpeak = async () => { const res = await fetch ( `/pronounce?text= ${ encodeURIComponent ( text )} ` ); const blob = await res. blob (); const url = URL. createObjectURL ( blob ); setAudioUrl ( url ); }; return ( < div > < h2 > Pronunciation Guide </ h2 > < input type = "text" value = { text } onChange = { e => setText ( e. target. value ) } placeholder = "Enter word or phrase" /> < button onClick = { handleSpeak } > Play </ button > { audioUrl && ( < div > < audio controls src = { audioUrl } /> </ div > ) } </ div > ); } Enter fullscreen mode Exit fullscreen mode Serve this with a simple create-react-app or any static server. Point the fetch URL to your Express endpoint (adjust the CORS settings if needed).

If you want your app to sound like the user (or a celebrity you have rights to), ElevenLabs offers a voice cloning endpoint. The flow is:

curl -X POST "https://api.elevenlabs.io/v1/voice-clone" \ -H "xi-api-key: YOUR_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F "audio=@/path/to/sample.wav" \ -F "model=voice-clone-2024-01" \ -F "name=MyCustomVoice" Enter fullscreen mode Exit fullscreen mode The response will include a voice_id. Plug that ID into the TTS request in place of YOUR_VOICE_ID. The result is a voice that sounds remarkably like the sample.

A pronunciation guide isn’t just about sounding right; it’s about breaking down the word. While TTS will give you a natural-sounding audio, you can overlay syllable markers or IPA transcriptions.

Option 1 – Use a library: pronouncing (Python) or natural (Node.js) can generate IPA and syllable boundaries.

const natural = require ( ' natural ' ); const tokenizer = new natural. SyllableTokenizer (); const syllables = tokenizer. tokenize ( ' pronunciation ' ); console. log ( syllables ); // ['pro-nun-ci-a-tion'] Enter fullscreen mode Exit fullscreen mode Option 2 – Leverage ElevenLabs’ “voice‑over” ElevenLabs can add emphasis to specific words or phrases by wrapping them in <emphasis> tags in SSML. For example:

{ "text": "The <emphasis>pronunciation</emphasis> of this word is key." } Enter fullscreen mode Exit fullscreen mode This will make the TTS engine give the word a subtle stress, mimicking native intonation.

Once deployed, users can type a word, hit “Play,” and hear an accurate, natural pronunciation. If you’re building an educational platform, this can be the backbone of a language learning feature that feels truly interactive.

Ready to build a pronunciation guide that actually sounds like a native speaker? Sign up with ElevenLabs today through this link: https://try.elevenlabs.io/kr07zfuqn1bp

Take advantage of the free tier, experiment with voice cloning, and watch your app’s language learning features jump to the next level. Happy coding!

Quelle: dev.to (dev.to). Original öffnen