Sound Play Questions: Delay, Preloading, mp3 or wav? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Sound Play Questions: Delay, Preloading, mp3 or wav?

28 Apr 2023, 05:56

Hello. ✌😊

I am.using soundplay for mp3 files inside my scripts.

I discover several.times some issues in the sound plays.

Like delays, sometimes just reacting on second push or loading when another threat starts.

Is it possible to preload the files with "FileRead" somehow?

Is there any possibility that, recode em to .wav files is better in performance then using .mp3 ?

If I got errors and delays can I somehow put a command in front to ensure its usage ?

Like Critical "On" or something?

I read a lot about AHKv1 stuff but I cant transfer it into v2 language.

Please help!.😊
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

28 Apr 2023, 06:26

Hello,

In many cases, adding the Wait command parameter helps, though it will then wait as commanded.

You could try an ActiveX GUI control. viewtopic.php?p=345201#p345201

I think that WAV is unlikely to help, but running your script with WAV is the way to answer the question.

Heavy CPU usage could interfere with playback.
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

28 Apr 2023, 18:02

@mikeyww

FileRead A_ScriptDir ("\Data\Sounds\Say Hello.mp3" && "\Data\Sounds\Joker.mp3") got no effect
wav didnt tried yet
cant get the wait param into your code

Code: Select all

SoundPlay A_ScriptDir (on ? '\Say Hello.mp3' : '\Joker.mp3')
Note: as always i tried severall combinations wich seem logic for me
like
splitt the filereads, add a "and" or & or &&

wrote filename.mp3", 1
wrote filename.mp3", wait
wrote filename.mp3", wait := True & false

and more... sorry i still do not understand enough of this language

this is th part wich makes the error somehow since days

Code: Select all

XboxToggleFunction() {
     POV := GetKeyState("JoyPOV")
    if POV >= 4501 and POV <= 13500 { ; 45, 90 and 135 degrees: Right
     Static on := False
     Critical "On"
     SetTimer(XboxRapidFire, 15 * on := !on)
     SoundPlay A_ScriptDir (on ? '\Say Hello.mp3' : '\Joker.mp3')
    } else {     
     JoyZ := GetKeyState("JoyZ")
    if GetKeyState("JoyZ") < 40 {
     SetKeyDelay 15, 15
     Send "{Blind}{LButton Down}"
    while GetKeyState("JoyZ") < 40
           Sleep 10
     Send "{Blind}{LButton Up}"
}}}
explanation: it is "Rapidfire and normal fire for the xbox controller using left mouse button
if i push D-Pad to the right it should toggle the mode between the else (normal fire) and the Functtion SetTimer(XboxRapidFire, 15 * on := !on)

usually when we pushed D-Pad to the right it gave the sound Say Hello, and did Rapidfire, and if we used to play normal we pushed again and did get the Joker sound

somehow the sounds get delayed or interrupted or play after a second or 3 after we pushed the fire button 1-2 times
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

28 Apr 2023, 19:36

I do not have a way to debug your script. One simple strategy is to shorten the script until your playback works. You can then add one new line at a time, testing iteratively. You will then know exactly when the script breaks.
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

29 Apr 2023, 07:19

Would be a great idea but it went hella big in a short time 😅🙈
I need a help from you with the wait command you suggested.
The line "( on? Sound 1 : sound 2 )" was from you and I cant put any parameters into it without errors.
The docs tell me I shall do SoundPlay "sound1.mp3" , wait

But I cant add a wait a 1 or anything else without errors on that part of the code.
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

29 Apr 2023, 07:28

Code: Select all

#Requires AutoHotkey v2.0
soundDir := A_ScriptDir '\t'

F2:: {
 Static on := False
 on := !on
 SoundPlay soundDir (on ? '\test1.wav' : '\test2.mp3'), WAIT := True
}
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?

29 Apr 2023, 07:42

mikeyww wrote:
29 Apr 2023, 07:28

Code: Select all

#Requires AutoHotkey v2.0
soundDir := A_ScriptDir '\t'

F2:: {
 Static on := False
 on := !on
 SoundPlay soundDir (on ? '\test1.wav' : '\test2.mp3'), WAIT := True
}
THANKS A LOT again 😁🙏
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: Sound Play Questions: Delay, Preloading, mp3 or wav?  Topic is solved

30 Apr 2023, 09:46

So fileread soundfilename.mp3 did not make any difference. I'm.not even sure if I done it correctly...

Convert / (change) .mp3 into .wav made it slightly better.
Because it does not need a codec for wav so it seems to run better with wav files.

The wait solution interrupts the script while the music is playing BUT it makes the performance better and the issues are gone with the ``` ), wait := true ``` Command


So using a shorter sound might be an option now but it is acceptable to wait for the file to play if the command after it works now flawlessly 👍


🙏👍 mikeyww lead to a success as usuall 😁👍

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: docterry, Google [Bot] and 44 guests