首页 > 编程语言 > 详细

Python使用Pygame.mixer播放音乐

时间:2015-04-10 17:40:59      阅读:780      评论:0      收藏:0      [点我收藏+]

Python使用Pygame.mixer播放音乐

frequency这里是调频率...

播放网络中的音频:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Author:Tea

import pygame
import urllib2

pygame.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:Tea

import pygame
pygame.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播放音乐

原文:http://www.cnblogs.com/TeaIng-Index/p/4415060.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!