python rsa模块使用3.5如何使用MP3play模块?

Python写的MP3播放器 mp3play-红联Linux系统门户
您的位置:
&& 查看内容 - - -
Python写的MP3播放器 mp3play
empast发布于
&&字号: &&&&(网友评论&6&条)&
mp3play 是一个用 Python 开发的 MP3 播放器,界面非常简单,无需安装其他的模块。可以嵌入到应用程序中以至此MP3音乐播放。
项目主页:
下载地址:
来自:开源中国社区
作者: py菜鸟&发布日期:
good,话说我学python就是想写一个linux下的音乐播放器,不过至今在网络编程和界面那里卡着……
作者: spworks&发布日期:
作者: sxmchj&发布日期:
作者: 菜鸟不怕踩&发布日期:
作者: Number&发布日期:
作者: ustb_hxb&发布日期:
学习学习...
共有评论数 6/每页显示数 10
发表评论,与各位同人交流。回复请点击下方的我要评论按钮(游客可回复),要发表贴子请点击
Linux教程下载?“”(请点击),Linux教程免费下载。
求助Linux问题?论坛有39版块,覆盖所有Linux技术层面。前往“”
 |  |  |  |  |  |  |  |  |  |  |  | 
&2017 红联 Powered by SupSiteaudio - Read MP3 in Python 3 - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
What I want to do is simply
mp3 = read_mp3(mp3_filename)
audio_left = mp3.audio_channels[0]
where audio_left will contain raw PCM audio data.
I was looking at , but most of the suggested modules are not ported to Python 3 yet. If possible I'd like to avoid having to install a fully-fledged game dev library.
I'm a complete Python beginner, so I'd like to start off using Python 3.
1,67021729
To make it easier I'd convert with some tools mp3 to wav, either:
$ ffmpeg -i foo.mp3 -vn -acodec pcm_s16le -ac 1 -ar 44100 -f wav foo.wav
$ mpg123 -w foo.wav foo.mp3
Then read the WAV with . I'd recommend
because it works with most generated WAV correctly and installed without issue (as opposed to scikits.audiolab).
Note: Even though scipy.io.wavfile.read() gave me a "WavFileWarning: Unfamiliar format bytes" warning, it also loaded the file properly.
18.7k1491107
I am considering using FFmpeg as a subprocess. There is a Python wrapper called pyffmpeg, but I had difficulty installing it on my system (OS X 10.7.3).
You may also want to look at the code here for calling FFmpeg as a subprocess from Python:
I ended up using an mpg123 subprocess to convert the mp3 to wav, and then I use scipy.io.wavfile.read to read the wav file.
1,67021729
I believe that the best to do this and that is also compatible with Python 3.x is:
I highly recommend that you look at Darwin M. Bautista's
And here is an example from (as provided by him):
from mplayer import Player, CmdPrefix
# Set default prefix for all Player instances
Player.cmd_prefix = CmdPrefix.PAUSING_KEEP
# Since autospawn is True by default, no need to call player.spawn() manually
player = Player()
# Play a file
player.loadfile('mp3_filename')
# Pause playback
player.pause()
# Get title from metadata
metadata = player.metadata or {}
print metadata.get('Title', '')
# Print the filename
print player.filename
# Seek +5 seconds
player.time_pos += 5
# Set to fullscreen
player.fullscreen = True
# Terminate MPlayer
player.quit()
List of supported audio codecs:
MPEG layer 1, 2, and 3 (MP3) audio
AC3/A52, E-AC3, DTS (Dolby Digital) audio (software or SP/DIF)
AAC (MPEG-4 audio)
WMA (DivX Audio) v1, v2
WMA 9 (WMAv3), Voxware audio, ACELP.net etc (using x86 DLLs)
RealAudio: COOK, SIPRO, ATRAC3 (using Real libraries)
RealAudio: DNET and older codecs
QuickTime: Qclp, Q-Design QDMC/QDM2, MACE 3/6 (using QT libraries), ALAC
Ogg Vorbis audio
VIVO audio (g723, Vivo Siren) (using x86 DLL)
alaw/ulaw, (ms)gsm, pcm, *adpcm and other simple old audio formats
2,66441843
Can be done with pydub:
import array
from pydub import AudioSegment
from pydub.utils import get_array_type
sound = AudioSegment.from_file(file=path_to_file)
left = sound.split_to_mono()[0]
bit_depth = left.sample_width * 8
array_type = get_array_type(bit_depth)
numeric_array = array.array(array_type, left._data)
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledI know that on PyAudio it is possible to choose on what playback device to stream on but PyAudio doesnt support mp3 files. My script would work if one of the following problem was solved:
Play mp3 file on PyAudio
Convert from mp3 to wav without without any data loss and without PyDub (with
of converting, I found out that in a longer audio, the ends are missing)
Somehow play sound from a mp3 file to different playback device (the device is not a default one)
Personally I want to solve the first problem.
I would be grateful if I can play mp3 file on PyAudio without any data loss or quality loss.
EDIT: I found out that when I play my mp3 file (which is btw a file generated from Google Text To Speech) with PyMedia, the endings also gone missing for some strange reason so perhaps the converting method (point 2.) is working correctly but the problem is probably somewhere else.
解决方案 First of all, The
you mentioned in your answer is about pymedia and not pydub.
Next, I've converted many files from mp3 to wav using pydub without issues.
If you want to give it a try, here is an one liner code to covnert from mp3 to wav. You will be able to use rest of your code this way using option-2.
from pydub import AudioSegment
AudioSegment.from_file("audio.mp3", format="mp3").export("audio.wav", format="wav")
本文地址: &
我知道,PyAudio有可能什么播放设备到流上,但PyAudio犯规支持mp3文件进行选择。如果下列问题之一,解决了我的脚本将工作: 在PyAudio播放MP3文件
从MP3转换为WAV没有,没有任何数据丢失,且无需PyDub(与,我发现,在一个较长的音频,末端缺失)
不知何故从MP3文件到不同的播放设备播放声音(该设备不是默认的) 我个人要解决的第一个问题。 我将不胜感激,如果我能在PyAudio播放MP3文件,而无需任何数据丢失或质量损失。 编辑:我发现,当我打我的MP3文件(这是顺便说一句,从谷歌文本到语音生成的文件)PyMedia的结局也失踪了一些奇怪的原因所以也许转换方法(2点)工作正常,但问题可能是在其他地方。解决方案 首先,请查看你在你的答复中提到是关于 pymedia ,而不是 pydub 。 接下来,我从 MP3 使用 pydub 没有问题。 如果你想给它一个尝试,这里是一个单行code从 MP3 到 WAV 。您将能够使用您的code的其余部分使用选项-2这样的。
从pydub进口AudioSegmentAudioSegment.from_file(“audio.mp3”格式=“MP3”)。出口(“audio.wav”格式=“WAV”)
本文地址: &
扫一扫关注官方微信Python基于pygame模块播放MP3的方法示例
转载 & & 作者:Chan7
这篇文章主要介绍了Python基于pygame模块播放MP3的方法,结合实例形式简单分析了Python使用pygame模块播放MP3音频文件的实现方法以及相关函数的功能说明,需要的朋友可以参考下
本文实例讲述了Python基于pygame模块播放MP3的方法。分享给大家供大家参考,具体如下:
安装pygame(可参考:)
pip安装这个
装完就直接跑代码啦,很短的
import time
import pygame
file=r'C:\Users\chan\Desktop\Adele - All I Ask.mp3'
pygame.mixer.init()
print("播放音乐1")
track = pygame.mixer.music.load(file)
pygame.mixer.music.play()
time.sleep(10)
pygame.mixer.music.stop()
功能:播放音乐10秒后停止
pygame.init() 进行全部模块的初始化,
pygame.mixer.init() 或者只初始化音频部分
pygame.mixer.music.load('xx.mp3') 使用文件名作为参数载入音乐 ,音乐可以是ogg、mp3等格式。载入的音乐不会全部放到内容中,而是以流的形式播放的,即在播放的时候才会一点点从文件中读取。
pygame.mixer.music.play()播放载入的音乐。该函数立即返回,音乐播放在后台进行。
play方法还可以使用两个参数
pygame.mixer.music.play(loops=0, start=0.0) loops和start分别代表重复的次数和开始播放的位置。
pygame.mixer.music.stop() 停止播放,
pygame.mixer.music.pause() 暂停播放。
pygame.mixer.music.unpause() 取消暂停。
pygame.mixer.music.fadeout(time) 用来进行淡出,在time毫秒的时间内音量由初始值渐变为0,最后停止播放。
pygame.mixer.music.set_volume(value) 来设置播放的音量,音量value的范围为0.0到1.0。
pygame.mixer.music.get_busy() 判断是否在播放音乐,返回1为正在播放。
pygame.mixer.music.set_endevent(pygame.USEREVENT + 1) 在音乐播放完成时,用事件的方式通知用户程序,设置当音乐播放完成时发送pygame.USEREVENT+1事件给用户程序。
pygame.mixer.music.queue(filename) 使用指定下一个要播放的音乐文件,当前的音乐播放完成后自动开始播放指定的下一个。一次只能指定一个等待播放的音乐文件。
更多关于Python相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家Python程序设计有所帮助。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具python使用win32com库播放mp3文件的方法
python使用win32com库播放mp3文件的方法
发布于1年前
阅读1469次
本文实例讲述了python使用win32com库播放mp3文件的方法。分享给大家供大家参考。具体实现方法如下:
# Python supports COM, if you have the Win32 extensions
# check your Python folder eg. D:\Python23\Lib\site-packages\win32com
# also http://starship.python.net/crew/mhammond/win32/Downloads.html
# this program will play MP3, WMA, MID, WAV files via the WindowsMediaPlayer
from win32com.client import Dispatch
mp = Dispatch("WMPlayer.OCX")
# use an mp3 file you have ...
#tune = mp.newMedia("C:/Program Files/Common Files/HP/Memories Disc/2.0/audio/Swing.mp3")
# or copy one to the working folder ...
#tune = mp.newMedia("Bier1.mp3")
# you can also play wma files, this cool sound came with XP ...
tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")
mp.currentPlaylist.appendItem(tune)
mp.controls.play()
# to stop playing use
raw_input("Press Enter to stop playing")
mp.controls.stop()
后回复方可回复, 如果你还没有账号你可以
一个帐号。
被 人关注,获得了231个喜欢
持续不断地劳动是人生的铁律,也是艺术的铁律。 —— 巴尔扎克*
共有0 条点评,0人收藏
记住登录状态
还不是会员
快速登录:

我要回帖

更多关于 python os模块 的文章

 

随机推荐