```@session.on("user_input_transcribed") def o...
# ask-ai
n
Copy code
@session.on("user_input_transcribed")
    def on_user_input_transcribed(event: UserInputTranscribedEvent):
        nonlocal last_activity_time, warned_user
        logger.info(f"User input transcribed: {event.transcript[:50]}...")
        last_activity_time = perf_counter()
        warned_user = False  # Reset warning when user speaks
This transcribes each word and logs it one by one. Is there a way to transcribe a sentence and not a word?
t
Thanks for reaching out, Nikhil. 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 exploring how to transcribe sentences instead of individual words! You can use the
SentenceTokenizer
from the LiveKit library, which is designed to break text into sentence-sized chunks. It works great in both synchronous and streaming modes. For streaming transcription, here's a friendly example using the
.stream()
method:
Copy code
from livekit.agents.tokenize.basic import SentenceTokenizer

sentence_tokenizer = SentenceTokenizer()
sentence_stream = sentence_tokenizer.stream()
sentence_stream.push_text("Hello")
sentence_stream.push_text(" world. ")
sentence_stream.push_text("How are you?")

async for sentence in sentence_stream:
    print(f"New sentence: {sentence}")
# Result: First iteration yields "Hello world.", second yields "How are you?"
sentence_stream.close()
If you're working with complete transcript segments, another helpful option is the
livekit-blingfire
plugin's
text_to_sentences
function:
Copy code
from livekit.blingfire import text_to_sentences

text = "Hello world. How are you? I'm fine, thanks."
segmented_text = text_to_sentences(text)
# Returns a string with sentences separated by newlines
Please feel free to reach out if you'd like any more help or have questions while implementing this—I’m here to support you! Sources: livekit-agents/livekit/agents/inference/stt.py | Text and transcriptions | LiveKit Docs
n
i am using this for voice agent
t
I’m glad you asked about how LiveKit handles voice agent transcriptions! By default, LiveKit transcribes full sentences rather than individual words. This happens thanks to end-of-speech detection methods like Voice Activity Detection (VAD) or STT provider endpointing, which wait for a pause in speech before finalizing and sending the complete sentence. To work with these sentence-level transcriptions in your voice agent, you can listen for the
user_input_transcribed
event. Here’s a simple example to get you started:
Copy code
@session.on("user_input_transcribed")
def on_transcript(event):
    if event.is_final:
        print(f"Sentence transcribed: {event.transcript}")
If you want to customize things further, there are helpful tools like the
livekit-blingfire
plugin that can assist with sentence segmentation. Feel free to reach out if you’d like some guidance on setting that up—I’m here to help! Sources: livekit-plugins/livekit-plugins-speechmatics/README.md | pipeline-llm/interrupt_user.py | Text and transcriptions | LiveKit Docs