I'm currently having a problem with my computer, so I'm not able to check this, but this should work:
from pydub import generators
from pydub.playback import play
import subprocess, sys
play(generators.Sine(440).to_audio_segment(duration=1500))
if sys.platform in ('linux', 'osx'):
subprocess.call('clear', shell=True)
elif sys.platform in ('nt', 'dos', 'ce'):
subprocess.call('cls', shell=True)
else:
pass
This is kind-of a 'hack' in the code that just clears console every time an output is sent.
Something like this may work, but again, I haven't been able to test it:
import contextlib
import io
from pydub import generators
from pydub.playback import play
with contextlib.redirect_stdout(io.StringIO()):
play(generators.Sine(440).to_audio_segment(duration=1500))