1.获取一个线上可播放的音频链接
如:http://221.229.203.64/m10.music.126.net/20170409145925/1c92fa94f8e995ef657c75158e180811/ymusic/4ab4/ce06/cae4/6787fcdbbac1624c736e7f2c32dee95c.mp3
2.用wget将此音频下载到本地
import os song_url = 'http://221.229.203.64/m10.music.126.net/20170409145925/1c92fa94f8e995ef657c75158e180811/ymusic/4ab4/ce06/cae4/6787fcdbbac1624c736e7f2c32dee95c.mp3' filePath = '123.mp3' c = "wget "%s" -c -T 10 -t 10 -O "%s"" % (song_url, filePath) os.system(c.encode('utf-8'))
3.用ffprobe查看下载下来的音频信息
4.将此音频标签中添加歌手信息
from mutagen.mp3 import MP3 import mutagen.id3 from mutagen.easyid3 import EasyID3 m = MP3('123.mp3', ID3=EasyID3) m['artist']=u'李宇春' m.save()
5.再次用ffprobe查看下载下来的音频信息,歌手标签已存在
6.以上我们看到此音频为128kb/s的双声道音频,要想转成16kb/s的单声道,可以使用ffmpeg
import os localPath = '123.mp3' filePath_temp = '123_zhuan.mp3' c='./ffmpeg -y -i %s -b:a %s -ar %s -ac 1 -vn %s' %(localPath,16000,16000,filePath_temp) os.system(c.encode('utf-8'))
7.查看转成单声道16kb/s的123_zhuan.mp3音频信息