Node.js + Express backend server for the Tongues real-time audio translation application.
- 🎤 Real-time Audio Processing - WebSocket-based audio streaming
- 🌍 Multi-language Support - 12+ languages for translation
- 🔄 Live Translation Pipeline - Ready for AI service integration
- 📡 Socket.IO Integration - Low-latency real-time communication
- 🚀 Express.js REST API - Clean, modular API endpoints
- 🔒 CORS Enabled - Secure frontend integration
- Node.js (v18 or higher)
- npm or yarn
# Install dependencies
npm install
# Start development server
npm run dev
# Start production server
npm start
The server will be available at http://localhost:3001
- Express.js for REST API endpoints
- Socket.IO for real-time WebSocket communication
- Web Audio Processing pipeline ready for AI integration
- Modular Design for easy service integration
- CORS Configuration for frontend connectivity
This backend connects to the Tongues frontend service via WebSocket. The frontend should be running on http://localhost:5173
for full functionality.
GET /api/health
- Server status and active connections
GET /api/languages
- List of supported languages
audioStream
- Send audio data for translationstopStreaming
- Stop audio processing
translation
- Receive translated texterror
- Error messagesconnect
- Connection establisheddisconnect
- Connection closed
The processAudioStream
function in server.js
is where you'll integrate with AI services:
- Google Speech-to-Text - High accuracy, supports 120+ languages
- OpenAI Whisper - Excellent quality, good for multiple languages
- Azure Speech Services - Enterprise-grade, good integration
- Amazon Transcribe - AWS ecosystem integration
- Google Translate API - 100+ languages, good accuracy
- DeepL API - High quality for European languages
- OpenAI GPT - Context-aware translations
- Microsoft Translator - Good enterprise integration
// Google Speech-to-Text + Google Translate
const speech = require('@google-cloud/speech');
const {Translate} = require('@google-cloud/translate').v2;
async function processAudioStream(audioData, sourceLanguage, targetLanguage) {
// 1. Convert audio data to proper format
const audioBuffer = Buffer.from(audioData);
// 2. Speech-to-Text
const speechClient = new speech.SpeechClient();
const [response] = await speechClient.recognize({
audio: { content: audioBuffer.toString('base64') },
config: {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: sourceLanguage,
},
});
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
// 3. Translation
const translate = new Translate();
const [translation] = await translate.translate(transcription, targetLanguage);
return translation;
}
# Development mode with auto-reload
npm run dev
# Production mode
npm start
# Check server health
curl http://localhost:3001/api/health
├── server.js # Main server with Socket.IO
├── package.json # Dependencies and scripts
└── README.md # This file
- 🇺🇸 English (en)
- 🇪🇸 Spanish (es)
- 🇫🇷 French (fr)
- 🇩🇪 German (de)
- 🇮🇹 Italian (it)
- 🇵🇹 Portuguese (pt)
- 🇷🇺 Russian (ru)
- 🇯🇵 Japanese (ja)
- 🇰🇷 Korean (ko)
- 🇨🇳 Chinese (zh)
- 🇸🇦 Arabic (ar)
- 🇮🇳 Hindi (hi)
Create a .env
file:
PORT=3001
NODE_ENV=development
# Add your AI service API keys here
GOOGLE_APPLICATION_CREDENTIALS=path/to/credentials.json
OPENAI_API_KEY=your_openai_key
- Set
NODE_ENV=production
- Use a process manager like PM2
- Set up reverse proxy (nginx/Apache)
- Configure SSL certificates
- Set up environment variables for API keys
- Implement rate limiting
- Add authentication for API endpoints
- Validate audio data size and format
- Use HTTPS in production
- Implement proper error handling
- Add logging and monitoring
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License.
Part of the Tongues Audio Translation Platform