Your language learning app now uses Google Cloud Text-to-Speech for realistic-sounding Spanish voices instead of the browser's robotic SpeechSynthesisUtterance API.
- Go to Google Cloud Console
- Create a new project or select an existing one
- Note your project ID Project ID: language-learning-app-476110
- In the Google Cloud Console, go to "APIs & Services" > "Library"
- Search for "Text-to-Speech API"
- Click on it and press "Enable"
- Go to "IAM & Admin" > "Service Accounts"
- Click "Create Service Account"
- Give it a name like "tts-service" tts-service@language-learning-app-476110.iam.gserviceaccount.com
- Grant it the "Cloud Text-to-Speech API User" role
- Click "Create and Continue"
- Click "Done"
- Click on your newly created service account
- Go to the "Keys" tab
- Click "Add Key" > "Create new key"
- Choose "JSON" format
- Download the key file and save it securely
Create a .env file in your backend directory with:
# Option 1: Use service account key file
GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service-account-key.json
# Option 2: Use project ID (if using default credentials)
GOOGLE_CLOUD_PROJECT_ID=your-project-id- Start your backend:
cd backend && npm run dev - Start your frontend:
cd frontend && npm run dev - Go to the chat page and send a message
- You should hear a much more realistic Spanish voice!
- Realistic Spanish voices from Google Cloud TTS
- Automatic fallback to browser SpeechSynthesis if TTS API fails
- Error handling with proper logging
- Async audio playback that doesn't block the UI
- Emoji filtering (same as before)
- Configurable voice settings (rate, pitch, gender)
The TTS service supports these parameters:
languageCode: Language (default: 'es-ES')voiceName: Specific voice to usessmlGender: 'MALE', 'FEMALE', or 'NEUTRAL'speakingRate: Speech speed (0.25 to 4.0, default: 0.9)pitch: Voice pitch (-20.0 to 20.0, default: 0.0)
- Free tier: 1 million characters per month
- Paid: $4.00 per 1 million characters after free tier
- Perfect for language learning apps!
Converts text to speech and returns MP3 audio.
Request body:
{
"text": "Hola, ¿cómo estás?",
"languageCode": "es-ES",
"voiceName": "es-ES-Standard-A",
"ssmlGender": "FEMALE",
"speakingRate": 0.9,
"pitch": 0.0
}Returns available voices for a language.
Query parameters:
languageCode: Language code (default: 'es-ES')
- "TTS API error: 401" - Check your service account credentials
- "TTS API error: 403" - Make sure Text-to-Speech API is enabled
- "TTS API error: 429" - You've exceeded the free tier limit
- Audio not playing - Check browser console for errors
If the Google Cloud TTS API fails for any reason, the app automatically falls back to the browser's built-in SpeechSynthesisUtterance API, so your app will always have some form of text-to-speech.
- Test different Spanish voices by calling the
/tts/voicesendpoint - Consider adding voice selection UI for users
- Monitor usage to stay within free tier limits
- Add caching for frequently used phrases