Playing .mp3 files with PyAudio

前端 未结 4 1470
忘掉有多难
忘掉有多难 2020-12-17 05:58

Can pyaudio play .mp3 files? If yes, may I ask to write an example please. If no, what is the simplest way to convert .mp3 to .wav?

I have tried to use PyDub, could

4条回答
  •  忘掉有多难
    2020-12-17 06:53

    If you're using Windows with Windows Media Player installed here's a simple solution:

    wmp = Dispatch('WMPlayer.OCX')
    wmp.settings.autoStart = True
    wmp.settings.volume = 50
    wmp.URL = r"tts_cache\gtts.mp3" #auto-start
    while wmp.PlayState != 1: #wait until stopped
        pythoncom.PumpWaitingMessages()
        time.sleep(0.1)
    wmp.URL = ""
    

    Unfortunately when i try to replace mp3 file with a new one it sometimes cannot be written. I think WMP blocks it or something. So i decided to create a new file every time and call it "caching".)

提交回复
热议问题