defining velocity

The trouble I’m having is getting a footstep sound to play when my character moves. I currently have it constantly playing, and the only way i can think to fix this is to create a new variable called velocity, define it, and then add a line of code saying that if velocity equals zero then the sound stops. Does anybody have any ideas on how to do this?

something like this?

    float stepCycle = 0f;
    float nextStep = stepCycle/2f;
    float stepInterval;
    
    if (velocity.sqrMagnitude > 0 && (Input.x != 0 || Input.y != 0))
                {
                    stepCycle += (velocity.magnitude + (speed*(isWalking ? 1f : runstepLenght)))*
                                 Time.fixedDeltaTime;
                }
    
                if (!(stepCycle > nextStep))
                {
                    return;
                }
    
                nextStep = stepCycle + stepInterval;
    
                PlayFootStepAudio();
    }