victorious-summer-64766
08/03/2025, 5:03 PMtall-airline-16756
08/03/2025, 5:03 PMtall-airline-16756
08/03/2025, 5:04 PMByteStreamReader class provided by the LiveKit RTC SDK. Here's a step-by-step guide:
1. Use ByteStreamReader to Read Chunks:
// Create a ByteStreamReader instance
const streamReader = new ByteStreamReader(info, readableStream);
// Use async iteration to process chunks
for await (const chunk of streamReader) {
processChunk(chunk);
}
// Alternatively, read all chunks at once
const allChunks = await streamReader.readAll();
2. Subscribe to Audio Tracks:
// Subscribe to audio tracks in a room
room.on(RoomEvent.TrackSubscribed, async (track, publication, participant) => {
if (track.kind === TrackKind.KIND_AUDIO) {
const stream = new AudioStream(track);
const reader = new ByteStreamReader(info, stream);
for await (const chunk of reader) {
processChunk(chunk);
}
}
});
3. Handle Different MIME Types:
// Check if the stream is Opus encoded
if (stream.info.mime_type && stream.info.mime_type.includes("opus")) {
const decoder = new AudioStreamDecoder(sampleRate, numChannels);
for await (const chunk of stream) {
decoder.push(chunk);
}
decoder.end_input();
for await (const frame of decoder) {
processFrame(frame);
}
} else {
for await (const chunk of stream) {
processChunk(chunk);
}
}
Let me know if you need further assistance with implementing these steps!
Sources: examples/receive-audio/index.tsvictorious-summer-64766
08/03/2025, 5:05 PMtall-airline-16756
08/03/2025, 5:05 PM.wav and .txt files on your computer, here’s a simple way to do it:
1. Save Audio to a .wav File
You can use the WavWriter class to save your audio streams like this:
// Example in Rust
let header = WavHeader {
sample_rate: 48000,
bit_depth: 16,
num_channels: 2,
};
let mut wav_writer = WavWriter::create("output.wav", header).await?;
// Write audio samples
wav_writer.write_sample(sample).await?;
// Finalize the file
wav_writer.finalize().await?;
This will create a nicely formatted WAV file with your audio data ready to go.
2. Save Conversation to a .txt File
To save your conversation transcripts, here’s a handy Python snippet:
import json
from datetime import datetime
def save_conversation_to_file(conversation_history):
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"conversation_{timestamp}.txt"
with open(filename, 'w') as f:
for message in conversation_history:
f.write(f"{message['timestamp']}: {message['speaker']}: {message['text']}\n")
print(f"Conversation saved to {filename}")
Just listen for events like conversation_item_added to catch the conversation as it happens and save the text on the fly.
3. Putting It All Together
• Use WavWriter to save your audio streams into a .wav file.
• Capture the conversation text and save it into a .txt file using event listeners.
If you want, I’m here to help you step-by-step with setting this up — just let me know!
Sources: examples/save_to_disk/src/main.rs | Recording agent sessions | LiveKit Docsvictorious-summer-64766
08/03/2025, 5:06 PMtall-airline-16756
08/03/2025, 5:08 PM