breezy-portugal-49042
03/26/2025, 7:16 AMtall-airline-16756
03/26/2025, 7:16 AMtall-airline-16756
03/26/2025, 7:16 AMSTTSegmentsForwarder
class, which provides an interface for delivering transcriptions in real-time. Here's a basic implementation:
async def _forward_transcription(
stt_stream: stt.SpeechStream,
stt_forwarder: transcription.STTSegmentsForwarder,
):
"""Forward the transcription and log the transcript in the console"""
async for ev in stt_stream:
stt_forwarder.update(ev)
if ev.type == stt.SpeechEventType.INTERIM_TRANSCRIPT:
print(ev.alternatives[0].text, end="")
elif ev.type == stt.SpeechEventType.FINAL_TRANSCRIPT:
print("\n")
print(" -> ", ev.alternatives[0].text)
This function takes a speech stream and a forwarder, then updates the forwarder with each speech event, which will send the data to the frontend. The data is sent in chunks, with each chunk assigned an index and sent sequentially with appropriate headers.
Sources: Transcriptions | LiveKit Docsbreezy-portugal-49042
03/26/2025, 8:26 AMtall-airline-16756
03/26/2025, 8:26 AMtranscription
not being defined may be due to a missing import. The STTSegmentsForwarder
class is part of the transcription
module in the LiveKit Agents package. You can import it using the following:
from livekit.agents import transcription
Additionally, ensure you also import the stt
module if needed:
from livekit.agents import stt, transcription
Once imported, you should be able to use the STTSegmentsForwarder
class to forward speech-to-text transcriptions to your frontend in real-time.
Sources: Transcriptions | LiveKit Docsbreezy-portugal-49042
03/26/2025, 8:28 AMtall-airline-16756
03/26/2025, 8:28 AM->
.
For example, if the speech stream contains the phrase "Hello world," it might print:
Hello
-> Hello world
This output depends on the events received from the speech stream.breezy-portugal-49042
03/26/2025, 8:29 AMtall-airline-16756
03/26/2025, 8:29 AMgroq_stt = stt.STT.with_groq(
model="whisper-large-v3-turbo",
detect_language=True
)
When detect_language
is set to True
, the system will automatically detect the language from the audio stream. Ensure that the model you are using supports language detection by checking the Groq documentation.
You can also update the language detection options during runtime using the update_options
method:
def update_options(
self,
*,
languages: LanguageCode | None = None,
detect_language: bool | None = None,
# other parameters...
)
This allows you to dynamically enable or adjust language detection as needed.
Sources: Groq integration guide | LiveKit Docs | livekit.plugins.openai API documentation | livekit.plugins.google API documentationbreezy-portugal-49042
03/26/2025, 8:30 AMbreezy-portugal-49042
03/26/2025, 8:30 AMtall-airline-16756
03/26/2025, 8:30 AMtall-airline-16756
03/26/2025, 8:30 AMbreezy-portugal-49042
03/26/2025, 8:32 AM