Skip to content

Commit baf78ba

Browse files
enable --no-audio in human.cpp to avoid echo playback
1 parent 098e1f4 commit baf78ba

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

bridge/examples/human.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
* The selection controls both video and audio simultaneously.
3131
*
3232
* Usage:
33-
* human <ws-url> <token>
34-
* LIVEKIT_URL=... LIVEKIT_TOKEN=... human
33+
* human [--no-audio] <ws-url> <token>
34+
* LIVEKIT_URL=... LIVEKIT_TOKEN=... human [--no-audio]
35+
*
36+
* --no-audio Subscribe to audio tracks but suppress local playback.
3537
*
3638
* The token must grant identity "human". Generate one with:
3739
* lk token create --api-key <key> --api-secret <secret> \
@@ -101,10 +103,20 @@ static std::atomic<uint64_t> g_video_frames{0};
101103

102104
int main(int argc, char *argv[]) {
103105
// ----- Parse args / env -----
106+
bool no_audio = false;
107+
std::vector<std::string> positional;
108+
for (int i = 1; i < argc; ++i) {
109+
if (std::string(argv[i]) == "--no-audio") {
110+
no_audio = true;
111+
} else {
112+
positional.push_back(argv[i]);
113+
}
114+
}
115+
104116
std::string url, token;
105-
if (argc >= 3) {
106-
url = argv[1];
107-
token = argv[2];
117+
if (positional.size() >= 2) {
118+
url = positional[0];
119+
token = positional[1];
108120
} else {
109121
const char *e = std::getenv("LIVEKIT_URL");
110122
if (e)
@@ -114,10 +126,14 @@ int main(int argc, char *argv[]) {
114126
token = e;
115127
}
116128
if (url.empty() || token.empty()) {
117-
std::cerr << "Usage: human <ws-url> <token>\n"
118-
<< " or: LIVEKIT_URL=... LIVEKIT_TOKEN=... human\n";
129+
std::cerr
130+
<< "Usage: human [--no-audio] <ws-url> <token>\n"
131+
<< " or: LIVEKIT_URL=... LIVEKIT_TOKEN=... human [--no-audio]\n";
119132
return 1;
120133
}
134+
if (no_audio) {
135+
std::cout << "[human] --no-audio: audio playback disabled.\n";
136+
}
121137

122138
std::signal(SIGINT, handleSignal);
123139

@@ -199,10 +215,10 @@ int main(int argc, char *argv[]) {
199215
// Real mic (SOURCE_MICROPHONE) -- plays only when 'w' is selected
200216
bridge.registerOnAudioFrame(
201217
"robot", livekit::TrackSource::SOURCE_MICROPHONE,
202-
[playAudio](const livekit::AudioFrame &frame) {
218+
[playAudio, no_audio](const livekit::AudioFrame &frame) {
203219
g_audio_frames.fetch_add(1, std::memory_order_relaxed);
204-
if (g_selected_source.load(std::memory_order_relaxed) ==
205-
static_cast<int>(VideoSource::Webcam)) {
220+
if (!no_audio && g_selected_source.load(std::memory_order_relaxed) ==
221+
static_cast<int>(VideoSource::Webcam)) {
206222
playAudio(frame);
207223
}
208224
});
@@ -211,10 +227,10 @@ int main(int argc, char *argv[]) {
211227
// selected
212228
bridge.registerOnAudioFrame(
213229
"robot", livekit::TrackSource::SOURCE_SCREENSHARE_AUDIO,
214-
[playAudio](const livekit::AudioFrame &frame) {
230+
[playAudio, no_audio](const livekit::AudioFrame &frame) {
215231
g_audio_frames.fetch_add(1, std::memory_order_relaxed);
216-
if (g_selected_source.load(std::memory_order_relaxed) ==
217-
static_cast<int>(VideoSource::SimFrame)) {
232+
if (!no_audio && g_selected_source.load(std::memory_order_relaxed) ==
233+
static_cast<int>(VideoSource::SimFrame)) {
218234
playAudio(frame);
219235
}
220236
});

0 commit comments

Comments
 (0)