Re: [問題] 新手問題 如何播放網路上的.wav檔?

看板Python作者 (飄)時間14年前 (2011/06/18 22:08), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串2/2 (看更多)
方法一: import pygame.mixer import urllib2 import time URL = ("http://billor.chsh.chc.edu.tw/sound/applaus.wav") response = urllib2.urlopen(URL) pygame.mixer.init() #Sound 是丟File object進去阿! 不用先read() pygame.mixer.Sound(response).play() while pygame.mixer.get_busy(): time.sleep(0.1) 方法二: import pygame.mixer import urllib2 import time import StringIO URL = ("http://billor.chsh.chc.edu.tw/sound/applaus.wav") response = urllib2.urlopen(URL) waveFile = response.read() # 要不然就是在把它變成File object waveFile = StringIO.StringIO(waveFile) pygame.mixer.init() pygame.mixer.Sound(waveFile).play() while pygame.mixer.get_busy(): time.sleep(0.1) -- 『人生中有無數的選擇,卻沒有絕對正確的選擇, 你只要在選擇後讓它變成正確的就好。』 柔澤紅香 じゅうざわ べにか -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.252.238

06/18 23:56, , 1F
多謝 我回去試試
06/18 23:56, 1F

06/20 08:45, , 2F
兩種方式確定都可行 非常感謝!
06/20 08:45, 2F

06/20 14:48, , 3F
cool !!!!
06/20 14:48, 3F
文章代碼(AID): #1D_B5bHW (Python)
文章代碼(AID): #1D_B5bHW (Python)