pythonhidesilentpydub

How can I hide 'pydub' output information?


My Code

from pydub import generators
from pydub.playback import play

play(generators.Sine(440).to_audio_segment(duration=1500))

In the console output:

Input #0, wav, from '/var/folders/_7/0q83l2vn4zjd7zgqpy3v97840000gn/T/tmphlm6i9s_.wav':
Duration: 00:00:01.50, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s

Solution

  • I didn't find a solution yet, but I found besides "pydub" three alternatives. The last one is without output text. (Number-4)

    import time
    from gtts import gTTS
    tts = gTTS('Test', lang='en')
    tts.save('Test.mp3')
    
    #=================1
    print("1")
    from pygame import mixer
    mixer.init()
    mixer.music.load("Test.mp3") 
    mixer.music.play()
    time.sleep(1)
    
    #=================2
    print("2")
    from pydub import AudioSegment
    from pydub.playback import play
    path_to_file = r"Test.mp3"
    song = AudioSegment.from_mp3(path_to_file)
    play(song)
    time.sleep(1)
    
    #=================3
    print("3")
    import os
    os.system("mpg321 -q Test.mp3")
    time.sleep(1)
    
    #=================4
    print("4")
    from mpyg321.mpyg321 import MPyg321Player
    player = MPyg321Player()
    player.play_song("Test.mp3")
    time.sleep(1)