Enable the sound's loop (https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1Sound.php#af23ab4f78f975bbabac031102321612b) and then play the sound once when the key is first pressed. It will loop continuously until you stop it. You can then stop it (again, once) when the key is released.
Vague idea:
sound.setLoop(true);
// window loop
if (spaceBarWasJustPressed)
sound.play();
else if (spaceBarWasJustReleased)
sound.stop();
Since you (now) want to do something whenever a key state is changed, it's easier to use events (sf::Event::KeyPressed and sf::Event::KeyReleased (https://www.sfml-dev.org/tutorials/2.4/window-events.php#the-keypressed-and-keyreleased-events))