I need solution for phone to phone conversation tr...
# ask-ai
c
I need solution for phone to phone conversation translation, any ideas how to built such using LiveKit? examples? preferably it should use gemini live native dialog model
t
Thanks for reaching out, Gediminas. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in building a phone-to-phone conversation translation solution with LiveKit! You can achieve this by combining telephony integration, real-time speech-to-text (STT), translation through large language models (LLMs), and text-to-speech (TTS). Let me walk you through the process: 1. Enable Telephony Integration: Connect phone calls to a LiveKit room using SIP trunks or providers like Twilio. This way, each caller joins as a participant in the room. 2. Deploy a LiveKit Agent: This agent will handle the audio streams by transcribing speech with STT, translating the text via an LLM, and then synthesizing the translated speech using TTS. The translated audio gets published back into the room for everyone to hear. 3. Speech-to-Text (STT): You can use services like Deepgram, Google Cloud STT, or OpenAI Whisper for real-time transcription. 4. Translation: Large language models such as OpenAI or Google Gemini are great options to translate the transcribed text. 5. Text-to-Speech (TTS): Convert the translated text into speech with tools like ElevenLabs, Google TTS, or similar providers. 6. Publish Translated Audio: The agent will publish the translated audio as a new track, so participants can listen in their preferred language. To see this in action, check out the multi-user-translator.py example. It supports N-way translation and can be adapted perfectly for phone-to-phone conversations. If you'd like, I’d be happy to guide you step-by-step on setting up SIP trunks, deploying agents, or configuring the STT, LLM, and TTS services. Just let me know how I can assist you best! Sources: LiveKit Docs | examples/warm-transfer/warm_transfer.py | Live Conversations with AI using ChatGPT and WebRTC | server/main.py | LiveKit Agents | LiveKit Docs
c
Ok ,but i need it to operate in different mode: caller 1 speaks language A, caller 2 speaks language B. LiveKit is a middle man here and translates A-to-B and B-to-A separately. Callers can hear only translated speech to their language.
t
I'm glad you're interested in setting up LiveKit for bidirectional translation where callers hear only the translated speech. Let's walk through the steps together to make this as smooth as possible: 1. Enable Real-Time Translation: Start by using the Gladia STT integration with LiveKit Agents. You'll want to configure it to enable translation and specify both the input and target languages. Here's an example to guide you:
Copy code
from livekit.plugins import gladia

stt = gladia.STT(
    translation_enabled=True,
    languages=["en", "es"],  # Original spoken languages
    translation_target_languages=["es", "en"]  # Target languages for translation
)
2. Integrate STT with Agent Session: Next, use the STT instance within the AgentSession to process audio, translate it, and generate the output audio in the target language. 3. Generate Translated Audio: For turning the translated text back into speech, you can use a Text-to-Speech (TTS) service like ElevenLabs or Google TTS. 4. Publish Translated Audio: The system will publish the translated audio as a new track named in the format
{input_track_id}-{target_language_code}
. This helps ensure that participants receive the correct audio stream. 5. Client-Side Handling: Make sure participants subscribe only to audio tracks that match their preferred language. This can be managed by filtering tracks based on their metadata. 6. Language Configuration: It's important to specify each participant's language in their access token attributes. The agent uses this information to know which translations to provide. 7. Bidirectional Translation Logic: The agent dynamically handles input tracks and creates translations for each language pair needed, so participants hear only the translated speech. To see this in action, you might find the multi-user-translator.py example really helpful. It demonstrates bidirectional real-time translation and can be adapted to fit your specific needs. If you'd like, I'm here to help you further with configuring the agent or setting up the telephony integration—just let me know! Sources: Gladia integration guide | LiveKit Docs | livekit-plugins/livekit-plugins-gladia/livekit/plugins/gladia/stt.py