Python plays music using pygame.mixer
Frequency here is the frequency adjustment ...
To play audio from your network:
#!/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 ... ')
This thing is a big distortion.
Play a local 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 ... ')
The tone frequency, the reduction degree is good, can receive.
Python plays music using pygame.mixer