How to detect with AppleScript if something is playing?

Solution 1:

You forgot the end if command.

on mySay(p, myMessage)
    tell application "QuickTime Player" to set isQTplaying to (playing of documents contains true)
    tell application "Music" to set isMusicPlaying to (player state is playing)
    tell application "VLC" to set isVLCplaying to playing
    --tell application "Brave" to set isiBravePlaying to (player state is playing)
    --tell application "FireFox" to set isiFireFoxPlaying to (player state is playing)
    --tell application "Safari" to set isiSafariPlaying to (player state is playing)
    if isQTplaying or isMusicPlaying or isVLCplaying or isiBravePlaying or isiFireFoxPlaying or isiSafariPlaying then
    else
        set volume output volume p
        say myMessage
        set volume output volume myVolumeBefore
    end if
end mySay

I made some adjustments to your code and removed what I could not get to compile on my side.

Is this something more along the lines of what you are looking for?

on mySay(p, myMessage)
    tell application "QuickTime Player" to set isQTplaying to ¬
        ((documents whose playing is true) is not {}) as boolean
    tell application "Music" to set isMusicPlaying to (player state is playing)
    tell application "VLC" to set isVLCplaying to playing
    if isQTplaying or isMusicPlaying or isVLCplaying then
        set myVolumeBefore to output volume of (get volume settings)
        set volume output volume p
        say myMessage
        set volume output volume myVolumeBefore
    else
        return
    end if
end mySay