Skip to content

Commit a58d498

Browse files
authored
Merge pull request #88 from sloganking/codex/add-cli-flag-for-push-to-talk-audio-ducking
Add push-to-talk audio ducking option
2 parents 4571c3f + 2daf0a4 commit a58d498

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_device_sink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl DefaultDeviceSink {
153153
let speed = inner.sink.speed();
154154
let paused = inner.sink.is_paused();
155155

156-
let (stream, mut new_sink, name) = Self::create_stream();
156+
let (stream, new_sink, name) = Self::create_stream();
157157
new_sink.set_volume(volume);
158158
new_sink.set_speed(speed);
159159

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ use uuid::Uuid;
5353
mod options;
5454
#[cfg(target_os = "windows")]
5555
mod windows_volume;
56+
use speakstream::ss::SpeakStream;
5657
use tracing::{debug, error, info, instrument, warn};
5758
use tracing_appender::rolling::{RollingFileAppender, Rotation};
5859

59-
use speakstream::ss::SpeakStream;
60-
6160
#[derive(Debug, Subcommand)]
6261
pub enum SubCommands {
6362
/// Displays keys as you press them so you can figure out what key to use for push to talk.
@@ -1072,6 +1071,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
10721071
// It then sends the path of the recorded audio file to the AI thread.
10731072
let thread_llm_should_stop_mutex = llm_should_stop_mutex.clone();
10741073
let thread_speak_stream_mutex = speak_stream_mutex.clone();
1074+
let duck_ptt = opt.duck_ptt;
10751075
thread::spawn(move || {
10761076
let mut recorder = rec::Recorder::new();
10771077
let mut recording_start = std::time::SystemTime::now();
@@ -1100,6 +1100,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
11001100
let mut thread_speak_stream =
11011101
thread_speak_stream_mutex.lock().unwrap();
11021102
thread_speak_stream.stop_speech();
1103+
if duck_ptt {
1104+
thread_speak_stream.start_audio_ducking();
1105+
}
11031106
drop(thread_speak_stream);
11041107
}
11051108

@@ -1149,6 +1152,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
11491152
}
11501153
}
11511154

1155+
if duck_ptt {
1156+
let mut thread_speak_stream =
1157+
thread_speak_stream_mutex.lock().unwrap();
1158+
thread_speak_stream.stop_audio_ducking();
1159+
drop(thread_speak_stream);
1160+
}
1161+
11521162
// continue if we failed to get elapsed time
11531163
let elapsed = match elapsed_option {
11541164
Some(elapsed) => elapsed,

src/options.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{SubCommands, VoiceEnum};
22
use clap::Parser;
3-
use easy_rdev_key::PTTKey;
43

54
#[derive(Parser, Debug)]
65
#[command(version)]
@@ -33,6 +32,10 @@ pub struct Opt {
3332
#[arg(long)]
3433
pub tick: bool,
3534

35+
/// Duck other application audio while the push-to-talk key is held down.
36+
#[arg(long)]
37+
pub duck_ptt: bool,
38+
3639
/// Start with the AI voice muted.
3740
#[arg(long)]
3841
pub mute: bool,

0 commit comments

Comments
 (0)