better-sandwich-65834
11/24/2025, 9:48 AMtall-airline-16756
11/24/2025, 9:48 AMtall-airline-16756
11/24/2025, 9:49 AMlk.transcription / user_input_transcribed and saving session.history).
• Guidance on Auto Egress or Agent Observability if you’re on LiveKit Cloud.
Which options do you want to proceed with?
Sources: Text and transcriptions | LiveKit docs | Observability data hooks | LiveKit docs | Events and error handling | LiveKit docs | Auto egress | LiveKit docs | Agent insights in LiveKit Cloud | LiveKit docsbetter-sandwich-65834
11/24/2025, 9:49 AMtall-airline-16756
11/24/2025, 9:50 AMRoomCompositeEgressRequest with audio_only=True and an AzureBlobUpload file output.
• Example (Python async):
from livekit import api
import os
async def start_recording(room_name):
lkapi = api.LiveKitAPI(os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"))
req = api.RoomCompositeEgressRequest(
room_name=room_name,
audio_only=True,
file_outputs=[
api.EncodedFileOutput(
filepath=f"{room_name}/recording_{room_name}.ogg",
file_type=api.EncodedFileType.OGG,
azure=api.AzureBlobUpload(
account_name=os.getenv("AZURE_ACCOUNT_NAME"),
account_key=os.getenv("AZURE_ACCOUNT_KEY"),
container_name=os.getenv("AZURE_CONTAINER_NAME"),
),
)
],
)
info = await lkapi.egress.start_room_composite_egress(req)
await lkapi.aclose()
return info.egress_id
• Store the returned egress_id so you can stop it later if needed.
3) Persist transcripts on session close (always run on shutdown)
• Use session.history.to_dict() (session.history is populated via transcription/chat events) and upload to Azure Blob Storage during your session shutdown callback.
• Example using Azure Blob SDK:
import json
from datetime import datetime
import os
from azure.storage.blob import BlobClient
def upload_transcript_to_azure(transcript_dict, room_name):
ts = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
blob_name = f"{room_name}/transcript_{room_name}_{ts}.json"
connect_str = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
blob = BlobClient.from_connection_string(conn_str=connect_str,
container_name=os.getenv("AZURE_CONTAINER_NAME"),
blob_name=blob_name)
blob.upload_blob(json.dumps(transcript_dict, indent=2), overwrite=True)
# In your shutdown handler / session end callback:
async def on_session_end(ctx):
# ensure you capture session.history at shutdown
if session.history:
transcript = session.history.to_dict()
upload_transcript_to_azure(transcript, ctx.room.name)
# optional: stop egress if you started it manually
if hasattr(ctx, "egress_id"):
lkapi = api.LiveKitAPI(os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"))
await lkapi.egress.stop_egress(ctx.egress_id)
await lkapi.aclose()
4) Ensure coverage for all session-end cases
• Register your transcript upload code in the same shutdown/job lifecycle hook that always runs on session end (graceful close, error, participant disconnect). Use your platform’s shutdown/ job lifecycle event to guarantee execution.
5) Optional/fine points
• Filename paths include the room name and timestamp to avoid collisions.
• You can let LiveKit auto-stop egress when the room ends; otherwise call stop_egress(egress_id) in shutdown.
• If you prefer streaming transcripts as they arrive, subscribe to user_input_transcribed events and append to a buffer; still flush and upload on shutdown.
Would you like:
• the code adapted to another language (Node/TS), or
• a sample that stores transcripts incrementally during the session (for very long sessions)? Sources: Events and error handling | LiveKit docs | Observability data hooks | LiveKit docs | Job lifecycle | LiveKit docs | Egress examples | LiveKit docsbetter-sandwich-65834
11/24/2025, 9:58 AMtall-airline-16756
11/24/2025, 9:58 AMbetter-sandwich-65834
11/24/2025, 11:03 AM