hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.59k stars 439 forks source link

Native Sound Playback Capabilities #1328

Open marioawad opened 4 years ago

marioawad commented 4 years ago

Playing sounds is really necessary to me and I still can't find a reliable and fast way to do so in CopyQ. I like to know when data is copied, when it's a duplicate or not, and when the clipboard is empty via sounds.

What I tried is to do so via PowerShell as you suggested -- https://github.com/hluk/CopyQ/issues/357 -- and also via a small command line utility -- https://www.elifulkerson.com/projects/commandline-wav-player.php -- but both have the same issue: they are very very slow to respond especially when the system is busy.

Since CopyQ is running all the time anyways I think it would be super fast if it can play sounds natively.

Can you please look into it? I'm a web developer myself so I lack the desktop development expertise required but if you can guide me in the right direction maybe I can write some code as well.

Thanks for all the hard work on CopyQ; it's really amazing; been using it daily for a long time.

hluk commented 4 years ago

I don't use audio and having native support for it would probably require adding some new library and I would expect related issues that would come with this.

That said, probably the main reason for the audio delay, especially on Windows, is due to some time required to start new processes -- for handling the new clipboard content and for the playback itself. But there could be also some delay accessing the clipboard itself.

marioawad commented 4 years ago

I was hoping the used QT libs supported audio out of the box... oh well...

Is there a way to send inter process messages for example?

https://docs.microsoft.com/en-us/windows/win32/learnwin32/window-messages https://www.autohotkey.com/docs/misc/SendMessageList.htm

Or maybe send a hotkey combination?

Both of which I can capture from AutoHotkey (which is always running in the background) and play the necessary sounds in a fast way.

Thanks again for all the help.

hluk commented 4 years ago

Is there a way to send inter process messages for example?

That would probably only work on Windows.

Or maybe send a hotkey combination?

Not sure what you mean here.

I thought you need to check the clipboard content before playing any sound. Currently, CopyQ would still need to wait on clipboard content change/fetch and execute at least one process.

marioawad commented 4 years ago

Ohhh ouch I see for process messages...

By sending a hotkey combination I meant that CopyQ sends ctrl+alt+x for example to the system and then I could write code in AutoHotkey to capture the hotkey and handle the audio playback there. Not sure if this is possible in QT but I though I'd ask you.

Yes of course in all cases I will need to check clipboard content in CopyQ which I did successfully (and you helped me with this previously here: https://github.com/hluk/CopyQ/issues/1121

But once that is done firing up PowerShell or Sounder.exe to play sounds is very slow and I was hoping for an alternative...

Columbus1000 commented 4 years ago

I have to add my voice here. The horrendous lag of copying to CopyQ before it responds with a beep.wav or whatever drives me bonkers.

I have CopyQ users who ask me "why is the copy notification WAV so slow to play? CLCL used to do it instantly."

I explain that it's not a priority of the author's, and that a small wait is worth it, because of all the other neat features CopyQ has. But this doesn't convince them. "Why is is so hard to do?" The PowerShell method takes MUCH TOO LONG to not be irritating, to be honest.

I appreciate this isn't a priority of yours, but it sure would make a lot of we windows users happy! Please reconsider adding a native WAV playing capability eventually. Keep up the great work!

From Fremantle, Western Australia

hluk commented 4 years ago

Support for audio handling in CopyQ probably won't happen. This would add a dependency on a multimedia library which I believe most users don't need.

That said, I'm trying to add a callback to the scripting API that would minimize the delay between clipboard change and the process call. Can you try this build and following command?

[Command]
Command="
    var onClipboardAboutToChange_ = onClipboardAboutToChange
    global.onClipboardAboutToChange = function() {
        execute(
            'powershell',
            '(New-Object Media.SoundPlayer \"E:\\\\\\\\Downloads\\\\\\\\sound7.wav\").PlaySync()'
        )
        onClipboardAboutToChange_()
    }"
Icon=\xf028
IsScript=true
Name=Play Sound on Clipboard Change

(The amount of escape sequences \\ in Windows paths is ridiculous! Maybe it would be possible to use forward slash instead E:/Downloads/sound7.wav. I haven't tested this on Windows.)

Columbus1000 commented 4 years ago

Thanks Lukas, I will give it a try at my earliest opportunity. I am rather busy just at the moment.

I take your point about many users perhaps not needing an audio feature like this ... or maybe more do than one might suspect?

I wonder if some kind of a poll on the issue mightn't be a good idea?

I admire your work on this program very much indeed.

Cheers.

On Thu, 7 May 2020, 1:10 a.m. Lukas Holecek, notifications@github.com wrote:

Support for audio handling in CopyQ probably won't happen. This would add a dependency on a multimedia library which I believe most users don't need.

That said, I'm trying to add a callback to the scripting API that would minimize the delay between clipboard change and the process call. Can you try this build https://ci.appveyor.com/project/hluk/copyq/builds/32692265/job/l5uns76u1ilu7fot/artifacts and following command?

[Command]Command=" var onClipboardAboutToChange = onClipboardAboutToChange global.onClipboardAboutToChange = function() { execute( 'powershell', '(New-Object Media.SoundPlayer \"E:\\\\Downloads\\\\sound7.wav\").PlaySync()' ) onClipboardAboutToChange() }"Icon=\xf028IsScript=trueName=Play Sound on Clipboard Change

(The amount of escape sequences \ in Windows paths is ridiculous! Maybe it would be possible to use forward slash instead E:/Downloads/sound7.wav. I haven't tested this on Windows.)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hluk/CopyQ/issues/1328#issuecomment-624774336, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOMD7LCMGOV4CACQI4MM5XTRQGKXVANCNFSM4LEOKTFA .

marioawad commented 4 years ago

Hello guys, glad to hear there's interest in this feature; I really hope we'd get a fix for the lag.

I tried the build mentioned above -- https://github.com/hluk/CopyQ/issues/1328#issuecomment-624774336 -- and unfortunately the lag is still there. The lag between the copy and the sound playback is still long even when my machine is kinda idle and when under a good load of processing the lag is around a few seconds... pretty huge...

What changed in that build by the way? (kinda felt the exact same lag to the original builds).

As for native sound support, I'm not sure if this means there's builtin functionality in QT but I just ran across this: https://doc.qt.io/qt-5/qsound.html -- Would it help? Hopefully please :-)

hluk commented 4 years ago

Did anyone have the chance to try the build with the command I mentioned above?

As for native sound support, I'm not sure if this means there's builtin functionality in QT but I just ran across this: https://doc.qt.io/qt-5/qsound.html -- Would it help?

This supports only wav files and I still would need to add a dependency on the Qt Multimedia library (and possibly some plugins).

For me, this feature is not that important to have it built in the application.

Columbus1000 commented 4 years ago

Not yet, but I hope to find time to do so soon. I appreciate your effort on this.

On Mon, 18 May 2020, 11:32 p.m. Lukas Holecek, notifications@github.com wrote:

Did anyone have the chance to try the build with the command I mentioned above?

As for native sound support, I'm not sure if this means there's builtin functionality in QT but I just ran across this: https://doc.qt.io/qt-5/qsound.html -- Would it help?

This supports only wav files and I still would need to add a dependency on the Qt Multimedia library (and possibly some plugins).

For me, this feature is not that important to have it built in the application.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hluk/CopyQ/issues/1328#issuecomment-630261085, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOMD7LAS2VAFUSCMKSFKSJDRSFIIHANCNFSM4LEOKTFA .

marioawad commented 4 years ago

Did anyone have the chance to try the build with the command I mentioned above?

I did try this and reported previously and unfortunately the lag is still there...

Sorry to keep nagging on this issue but I really like sound plays to be fast especially that I use CopyQ all the time :-)

Supporting wav files is perfect for me and for anyone I think as you can just convert any mp3 file to wav and be done.

Can you please look into adding this functionality? Just a simple function that we can call to natively play a sound file from CopyQ...

If not, can you please point me on how to add the dependency on the Qt Multimedia library and compile CopyQ myself under Windows 10?

Thank you.

hluk commented 4 years ago

Check out audio branch.

Here is the build: https://ci.appveyor.com/project/hluk/copyq/builds/35300505/job/lmc91cfpdg0im2hk/artifacts

But the installation "setup.exe" file probably doesn't contain some required audio plugins, so use the portable zip instead.

It may be possible to play mp3 and other formats but some external libraries could be required.

You can set audio file and volume with following commands (you can enter these in Action dialog - F5 shortcut):

copyq config clipboard_change_audio C:/path/to/audio.wav
copyq config clipboard_change_audio_volume 50

I'm still against merging this change - it adds dependencies that are unnecessary in most cases.

marioawad commented 4 years ago

Dude you're amazing thanks a lot!

I tested the build and it works perfectly and even performs well when the system is under heavy load. Love it!

I'm doing something a bit more advanced with audio. Is there a possibility for you to provide a version where I can play audio via scripting commands please? I need to play different audio files depending on different events. Check below please. Notice all the things I tried to play audio quickly but still couldn't make it happen :-)

If I can call something like nativePlayAudio('C:/path/to/audio.wav') instead of the heavy and slow execute() commands below it would be really amazing. Thanks again!

onClipboardUnchanged = function() {
    playIgnoreSound();
}

updateClipboardData = function() {
    if(isClipboard()) {
        updateTitle();
        showDataNotification();
        setClipboardData();
        if(hasData()) {
            playCaptureSound();
        }
        else {
            playEraseSound();
        }
    }
}

global.playCaptureSound = function() {
    //QSound::play("mysounds/bells.wav"); //Not working
    //QKeySequence(tr("Ctrl+P")); //Not working (Call AutoHotkey and play sound from there)
    //execute('PowerShell', '(New-Object Media.SoundPlayer C:\\Progz\\CopyQ\\sounds\\capture.wav') //Super slow
    execute('C:\\Progz\\Sounder\\Sounder.exe', 'C:\\Progz\\CopyQ\\sounds\\capture.wav') //Slow but works
}
global.playEraseSound = function() {
    execute('C:\\Progz\\Sounder\\Sounder.exe', 'C:\\Progz\\CopyQ\\sounds\\erase.wav')
}
global.playIgnoreSound = function() {
    execute('C:\\Progz\\Sounder\\Sounder.exe', 'C:\\Progz\\CopyQ\\sounds\\ignore.wav')
}
Gitoffthelawn commented 2 years ago

Thanks for pointing me to this issue report thread, Lukas. It was further down in the search results than I ventured.

I just want to add my name to the list of CopyQ users who think this will be a beneficial feature. It will help with daily use as well as for debugging/testing (see #1865).

Ideally, I would like this to work on Linux and Windows.

I certainly understand the hesitation to add another library, although there might be enough users who will benefit from this to make it worth it.

As a side note, auditory notifications often become more significant for people with vision limitations (which often happens with age). For example, glaucoma often significantly reduces peripheral vision, which is where visual notifications typically appear.