What's a cross platform way to play a sound file in python?

前端 未结 5 864
庸人自扰
庸人自扰 2020-12-28 16:56

I tried playing a .wav file using pyaudio. It works great on windows, but doesn\'t work in Ubuntu when another device is using sound.

The error is \"I

5条回答
  •  礼貌的吻别
    2020-12-28 17:26

    You can try Simpleaudio:

    > pip install simpleaudio
    

    Then:

    import simpleaudio as sa
    
    wave_obj = sa.WaveObject.from_wave_file("path/to/file.wav")
    play_obj = wave_obj.play()
    play_obj.wait_done()
    

提交回复
热议问题