Skip to content

Add example for local audio streaming#676

Merged
ladvoc merged 17 commits intomainfrom
dc/local_audio_example
Sep 3, 2025
Merged

Add example for local audio streaming#676
ladvoc merged 17 commits intomainfrom
dc/local_audio_example

Conversation

@chenosaurus
Copy link
Contributor

add a examples/local_audio project that demostrates streaming to LiveKit from local mic input and playing participant audio to local speakier.

@chenosaurus chenosaurus requested review from bcherry and ladvoc July 11, 2025 23:00
Copy link
Contributor

@ladvoc ladvoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came across a build issue and have a few minor suggestions, but overall, this works really well ✅.

let devices = host.output_devices()?;

for device in devices {
println!("Device: {:?}", device);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile for me; Device does not implement Debug.


RoomEvent::ParticipantDisconnected(participant) => {
let participant_identity = participant.identity().to_string();
info!("Participant disconnected: {}", participant_identity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParticipantIdentity implements Display, so this can be made a one liner:

info!("Participant disconnected: {}", participant.identity());

This also avoids an unnecessary clone.

livekit = { path = "../../livekit", features = ["rustls-tls-native-roots"]}
livekit-api = { path = "../../livekit-api", features = ["rustls-tls-native-roots"]}
log = "0.4"
cpal = "0.15"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can upgrade to cpal 0.16. I tested the example with it and it works just as well.

}

// Get LiveKit connection details from CLI arguments or environment variables
let url = args.url.or_else(|| env::var("LIVEKIT_URL").ok())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clap has a really nice feature that can do this automatically. Once you enable the "env" feature on the crate, you can have it accept the arg either from the CLI or env:

/// LiveKit server URL (can also be set via LIVEKIT_URL environment variable)
#[arg(long, env = "LIVEKIT_URL")]
url: Option<String>

@ladvoc
Copy link
Contributor

ladvoc commented Aug 28, 2025

@chenosaurus, is this ready to merge?

@ladvoc ladvoc merged commit 59eda4a into main Sep 3, 2025
8 checks passed
@ladvoc ladvoc deleted the dc/local_audio_example branch September 3, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants