The simpler way to keep track of is_on_floor before and after move_and_slide.
For example:
var was_on_floor = is_on_floor()
move_and_slide(velocity, Vector2.UP)
if is_on_floor() and not was_on_floor:
$sound.play()
Whenever you call move_and_slide Godot updates the values you get from is_on_floor, is_on_wall and is_on_ceiling. To know what is wall, floor or ceiling, Godot uses the vector you pass as second parameter (if you pass Vector2.ZERO then everything is wall).
If you only care to check if it collided with something at all, you may use get_slide_count after move_and_slide. The function get_slide_count should give you 0 if there were no collisions:
if get_slide_count() > 0:
$sound.play()
Or you could check if the velocity that move_and_slide returns a different velocity that the one you passed. Meaning it did collide (or slide).
var old_velocity = velocity
velocity = move_and_slide(velocity, Vector2.UP)
if velocity != old_velocity:
$sound.play()
Alternatively you may use get_slide_collision, which gives you a KinematicCollision2D object:
for i in get_slide_count():
var collision = get_slide_collision(i)
print("Collided with: ", collision.collider.name)
Which will let you identify with what did the KinematicBody2D collide with, and then you could pick a sound accordingly.