braden-w / whispering

https://whispering.bradenwong.com/
MIT License
314 stars 36 forks source link

[Feature Request] Auto-Lowering System Audio While Recording #355

Open Arche151 opened 4 weeks ago

Arche151 commented 4 weeks ago

Hey Braden,

Hope you’re doing well! Ever since I made the switch from Linux to Windows (partly because, unfortunately, there isn’t a working version of Whispering for Linux yet 😅), I’ve been relying on Whispering even more in my study sessions. It’s a fantastic tool, and your work on it has really been a game-changer—so thank you for that!

Feature Request:

I wanted to suggest a feature that could make things even smoother. Often, I’m listening to music while I study, and when I start recording with Whispering, I have to manually turn down the music volume, which interrupts my workflow. It would be amazing if Whispering could automatically lower the system audio volume while recording and then restore it to its original level once the recording stops.

Suggested Functionality:

  1. On Recording Start: Automatically reduce the system audio (e.g., music or any other background audio) to a predefined level or mute it.

  2. On Recording Stop: Return the system audio to the volume it was at before the recording began.

Ideal Setup:

Thanks for considering this! It would be a huge help, and I’m sure others would love it too. If you need a tester, you know I’m here! 😊

Best,

Noah

doxgt commented 4 weeks ago

Interesting that this should be a popular request. I try to tell my little one that she shouldn't be listening to music while doing work ... falling completely on deaf ears ...

Now that you are on Windows, the easiest thing to do is just to DIY with AutoHotKey (https://github.com/braden-w/whispering/discussions/307#discussioncomment-10591537) ... or AutoIt.

Arche151 commented 4 weeks ago

Interesting that this should be a popular request. I try to tell my little one that she shouldn't be listening to music while doing work ... falling completely on deaf ears ...

Now that you are on Windows, the easiest thing to do is just to DIY with AutoHotKey (#307 (reply in thread)) ... or AutoIt.

Eyy, using AutoHotKey did it, thanks a lot!

Here's my script, if anyone might find it useful as well (you need to change th hotkey, in case you have a different one)

#Requires AutoHotkey v2.0
#SingleInstance Force

; Initialize global variables
global isRecording := false
global originalVolume := 0

; Ctrl+Shift+R hotkey
^+r:: {
    global isRecording, originalVolume  ; Declare globals inside the function

    if (!isRecording) {
        ; Get current volume (0-100)
        currentVolume := SoundGetVolume()
        originalVolume := currentVolume

        ; Lower volume to 20% of current
        newVolume := currentVolume * 0.2
        SoundSetVolume(newVolume)

        isRecording := true
    }
    else {
        ; Restore original volume
        SoundSetVolume(originalVolume)
        isRecording := false
    }

    ; Pass the key combination through to other applications
    Send("^+r")
}
Arche151 commented 3 weeks ago

Update: Unfortunately, using AutoHotKey to achieve the volume reduction during recordings turned out to be quite buggy.

I often have to restart Whispering, disable the AutoHotKey script, re-set the shortcuts etc.

So @braden-w it would be really amazing, if you could implement the feature in Whispering! :)

doxgt commented 3 weeks ago

Two suggestions in the meantime:

  1. Consider using KeyWait to implement a PTT routine.

  2. I would personally probably shy away from using the exact same hotkey/shortcut in your AHK script directly as Whispering's own recording shortcut. In your above implementation, you could be sending Control ("^") twice, in addition to causing potential "hook conflict", as described here (https://www.autohotkey.com/boards/viewtopic.php?p=589416#p589416) - run into by @DavidGP, one of the regulars here.

FWIW, I myself might try something along the following lines:

#Requires AutoHotkey v2
#SingleInstance
SetCapsLockState "AlwaysOff"                ; Optional

SC03A::                         ; Scan code for CAPSLOCK
{
    global originalVolume
    currentVolume := SoundGetVolume()
    originalVolume := currentVolume
    SoundSetVolume(currentVolume * 0.01)
    Send "{Blind}{Control up}{Alt up}{Shift up}"
    Send "^+r"
    KeyWait "SC03A"
    Sleep 500                       ; Gives time to capture trailing voice input
    Send "{Blind}{Control up}{Alt up}{Shift up}"
    Send "^+r"
    Sleep 100
    SoundSetVolume(originalVolume)
}
Arche151 commented 3 weeks ago

Two suggestions in the meantime:

  1. Consider using KeyWait to implement a PTT routine.
  2. I would personally probably shy away from using the exact same hotkey/shortcut in your AHK script directly as Whispering's own recording shortcut. In your above implementation, you could be sending Control ("^") twice, in addition to causing potential "hook conflict", as described here (https://www.autohotkey.com/boards/viewtopic.php?p=589416#p589416) - run into by @DavidGP, one of the regulars here.

FWIW, I myself might try something along the following lines:

#Requires AutoHotkey v2
#SingleInstance
SetCapsLockState "AlwaysOff"              ; Optional

SC03A::                           ; Scan code for CAPSLOCK
{
    global originalVolume
    currentVolume := SoundGetVolume()
    originalVolume := currentVolume
    SoundSetVolume(currentVolume * 0.01)
    Send "{Blind}{Control up}{Alt up}{Shift up}"
    Send "^+r"
    KeyWait "SC03A"
    Sleep 500                     ; Gives time to capture trailing voice input
    Send "{Blind}{Control up}{Alt up}{Shift up}"
    Send "^+r"
    Sleep 100
    SoundSetVolume(originalVolume)
}

Will try out that approach, thx :)