This guide explains how to set up and use the real-time translator on mobile devices.
- On your computer, run the LibreTranslate server:
- Windows: Run
start-translator.bat - macOS/Linux: Run
./start-translator.sh
- Windows: Run
- Wait for the server to finish downloading language models (first run only)
- Verify the server is running by opening http://localhost:5000 in your browser
-
On Windows:
- Open Command Prompt
- Type
ipconfigand press Enter - Look for "IPv4 Address" under your active network connection (e.g., 192.168.1.X)
-
On macOS:
- Open System Preferences > Network
- Select your active connection
- Your IP address will be displayed (e.g., 192.168.1.X)
-
On Linux:
- Open Terminal
- Type
hostname -Iand press Enter - The first address is usually your local IP (e.g., 192.168.1.X)
-
Open these two files:
Project-MWS-01/app/(tabs)/voice-translator.tsxProject-MWS-01/components/TranslatorFooter.tsx
-
In both files, update the
LIBRE_TRANSLATE_API_URLconstant:// Comment out the existing line // const LIBRE_TRANSLATE_API_URL = 'http://10.0.2.2:5000'; // For Android emulator // Uncomment and update this line with your IP address const LIBRE_TRANSLATE_API_URL = 'http://YOUR_COMPUTER_IP:5000'; // For physical devices
Replace
YOUR_COMPUTER_IPwith your actual IP address (e.g., 192.168.1.X)
- Connect your mobile device to the same Wi-Fi network as your computer
- Ensure your computer's firewall allows connections on port 5000
-
Start the App:
- Run your app on your mobile device
- You should see the blue "Translator" button at the bottom of the screen
- If the server is available, it will say "Translator"
- If the server is unavailable, it will say "Translator (Offline)"
-
Access the Translator:
- Tap the blue translator button to open the translator
- Select your source and target languages
- Use voice input or text input to translate
-
Voice Translation:
- Press and hold the microphone button
- Speak clearly in the source language
- Release the button when finished
- The app will translate your speech
-
Text Translation:
- Type your text in the input field
- Tap the send button
- The app will translate your text
If the translator shows "Offline Mode":
-
Check Server Status:
- Make sure the LibreTranslate server is running on your computer
- Verify you can access http://localhost:5000 on your computer
-
Check Network Connection:
- Ensure your mobile device is on the same Wi-Fi network as your computer
- Try pinging your computer from another device to verify connectivity
-
Check IP Address:
- Verify you're using the correct IP address in the code
- IP addresses can change, so check it each time you connect to a different network
-
Check Firewall Settings:
- Make sure your computer's firewall allows incoming connections on port 5000
- On Windows, you might need to add an exception in Windows Defender Firewall
- On macOS, check System Preferences > Security & Privacy > Firewall
If voice recognition isn't working:
-
Check Microphone Permissions:
- Make sure you've granted microphone permissions to the app
- On Android: Settings > Apps > Your App > Permissions
- On iOS: Settings > Your App > Microphone
-
Speak Clearly:
- Speak at a moderate pace and volume
- Minimize background noise
If you switch Wi-Fi networks:
-
Get Your New IP Address:
- Your computer's IP address will change on different networks
- Follow Step 2 above to find your new IP address
-
Update the Code:
- Update the
LIBRE_TRANSLATE_API_URLconstant with your new IP address - Rebuild and reinstall the app
- Update the
For a production app, consider:
-
Hosting LibreTranslate on a Public Server:
- Set up LibreTranslate on a cloud server with a fixed IP or domain
- Update the URL in your app to point to this server
-
Using a Public LibreTranslate API:
- Some public instances are available, but may have rate limits
- Example:
https://libretranslate.com
-
Implementing a Fallback Mechanism:
- The app already has offline mode with limited translations
- You could enhance this with a larger offline dictionary