show me a sample stt code integrating google cloud...
# ask-ai
l
show me a sample stt code integrating google cloud stt
t
Thanks for reaching out, Computer. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Here is a sample code snippet for integrating Google Cloud Speech-to-Text (STT) with LiveKit to transcribe real-time audio from participants in a room:
Copy code
from livekit import rtc
from livekit.agents import JobContext, JobRequest, WorkerOptions, cli, stt
from livekit.plugins.google import STT

async def entrypoint(job: JobContext):
    # Initialize Google Cloud STT
    google_stt = STT(
        languages="en-US",
        model="latest_long",
        interim_results=True,
        punctuate=True
    )

    # Wait for the first participant to join
    participant = await job.wait_for_participant()

    # Find the first subscribed audio track (microphone)
    audio_track = None
    for track in participant.tracks.values():
        if track.source == rtc.TrackSource.SOURCE_MICROPHONE:
            pub = participant.get_track_publication(track.sid)
            if pub and pub.is_subscribed and isinstance(pub.track, rtc.RemoteAudioTrack):
                audio_track = pub.track
                break

    if not audio_track:
        print("No subscribed microphone track found")
        return

    # Create a stream reader to get raw audio frames
    track_stream = rtc.AudioStream(track=audio_track)

    # Start the STT streaming session
    stt_stream = google_stt.stream()

    # Forward audio frames from participant to STT
    async def input_task():
        async for frame in track_stream:
            stt_stream.push_frame(frame)
        stt_stream.end_input()

    # Process transcription output
    async def output_task():
        async for event in stt_stream:
            if event.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
                print("Final Transcript:", event.alternatives[0].text)
            elif event.type == stt.SpeechEventType.INTERIM_TRANSCRIPT:
                print("Interim Transcript:", event.alternatives[0].text)

    # Run transcription tasks concurrently
    await asyncio.gather(input_task(), output_task(), return_exceptions=True)

    await stt_stream.aclose()

async def request_handler(req: JobRequest):
    await req.accept(entrypoint)

if __name__ == "__main__":
    cli.run_app(WorkerOptions(request_handler=request_handler))
Just a quick reminder to make sure you have the
livekit-plugins-google
package installed and that the Google Cloud Speech-to-Text API is enabled in your project. You can easily customize how the transcription works by tweaking parameters like
languages
,
model
, and
punctuate
. If you have any questions or would like me to walk you through more examples, please don’t hesitate to ask—I’m here to help! Sources: livekit-plugins/livekit-plugins-google/README.md | Google Cloud STT plugin guide | LiveKit Docs | Google AI and LiveKit | LiveKit Docs
l
tts=google.beta.GeminiTTS( model="gemini-2.5-flash-preview-tts", voice_name="Zephyr", instructions="Speak in a friendly and engaging tone.", ), this is my tts code, how to add malayalm langugae to it?
t
Thanks for reaching out! Right now, the documentation doesn’t clearly confirm if Google Gemini TTS supports Malayalam (
ml-IN
). To help you find out, here are a couple of steps you can try: 1. Take a look at the official Gemini TTS documentation for the list of supported voices and languages: Gemini TTS Voices. 2. If you don’t see Malayalam listed there, you might want to explore Google Cloud TTS, which offers a wider range of languages including Malayalam. You can check out the details here: Google Cloud TTS Voices. If you’d like, I’m here to help you get started with Google Cloud TTS or clarify anything else. Just let me know! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/tts.py | plugins/google/src/beta/gemini_tts.test.ts | Gemini TTS plugin guide | LiveKit Docs | Google AI and LiveKit | LiveKit Docs | Google Cloud TTS integration guide | LiveKit Docs
l
well gemini tts doesnt provide malayalm but google cloud does ml-IN-Chirp3-HD-Laomedeia this is the voice name for it, now how to integrate this into my tts code?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
l
tts = google.beta.GeminiTTS( model="gemini-2.5-flash-preview-tts", voice_name="Kore", in this tts code, if i want the tts to be in malayalam what param should i add?? and i have checked the model Kore does support malayalm