Python plays music using pygame.mixer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.