標籤:
Python使用Pygame.mixer播放音樂
frequency這裡是調頻率...
播放網路中的音頻:
#!/usr/bin/env python# -*- coding: utf-8 -*-#Author:Teaimport pygameimport urllib2pygame.mixer.init(frequency=8000,size=-16,channels=4)URL = ("http://api.microsofttranslator.com/V2/Http.svc/Speak?language=zh-chs&appid=Tz49xk_OIwzAAeH91ExsdbHBruQdwsi5C2ssKhwhttRerOg__1cm_J-fxFJXAIME2&text=%e4%b8%ba%e4%bb%80%e4%b9%88%e8%bf%99%e6%a0%b7%e5%ad%90%ef%bc%8c%e4%bd%a0%e5%a5%bd%e5%a5%bd&format=audio/wav&options=MaxQuality")response = urllib2.urlopen(URL)waveFile = response.read()pygame.mixer.Sound(waveFile).play()while pygame.mixer.get_busy(): print (‘playing...‘)
這玩意失真很大
播放本地的WAV
#!/usr/bin/env python# -*- coding: utf-8 -*-#Author:Teaimport pygamepygame.mixer.init(frequency=15500,size=-16,channels=4)waveFile = ‘D:\C.wav‘pygame.mixer.Sound(waveFile).play()while pygame.mixer.get_busy(): print (‘playing...‘)
調調頻率,還原度不錯,能接收。。
Python使用Pygame.mixer播放音樂