How to play streaming audio from internet radio on Python 3.5.3

后端 未结 1 1164
春和景丽
春和景丽 2020-12-14 05:22

I am using Python 3.5.3 on Windows 8.1 x64 and i need play audio from here

I have tried pyaudio, but it gives me only white noise and error occurred after a few runs

相关标签:
1条回答
  • 2020-12-14 05:55

    If you are open for external libraries, you can install vlc binding for python using pip install python-vlc

    And use player method to play audio file directly from URL as below.

    import vlc
    import time
    
    url = 'http://prem1.rockradio.com:80/bluesrock?9555ae7caa92404c73cade1d'
    
    #define VLC instance
    instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
    
    #Define VLC player
    player=instance.media_player_new()
    
    #Define VLC media
    media=instance.media_new(url)
    
    #Set player media
    player.set_media(media)
    
    #Play the media
    player.play()
    

    Advantage of vlc player is that you can play most media types directly from URL (not just mp3) and also perform player like options such as

    >>> play.pause()  #pause play back
    >>> player.play() #resume play back
    >>> player.stop() #stop play back
    
    0 讨论(0)
提交回复
热议问题