0%

如何将网络视频中的音频上传音乐播放器

1.通过网站获取相应音频文件MP3格式

https://www.hotbox.fun/profile

2. 对音频文件进行裁剪(根据需求)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pydub import AudioSegment

def crop_mp3(input_path, output_path, start_time, end_time):
# 加载MP3文件
audio = AudioSegment.from_mp3(input_path)

# 计算裁剪的开始和结束时间(以毫秒为单位)
start_ms = start_time * 1000
end_ms = end_time * 1000

# 裁剪音频
cropped_audio = audio[start_ms:end_ms]

# 保存裁剪后的音频文件
cropped_audio.export(output_path, format="mp3")

# 输入文件路径
input_file = "input.mp3"

# 输出文件路径
output_file = "output.mp3"

# 裁剪的开始时间和结束时间(以秒为单位)
start_time = 30 # 从第30秒开始
end_time = 60 # 到第60秒结束

# 执行裁剪操作
crop_mp3(input_file, output_file, start_time, end_time)

3. 给MP3文件打标签,增加歌手、专辑、封面图片等信息,并修改分贝值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import eyed3
from pydub import AudioSegment

def edit_mp3_tags(file_path, title, artist, album, year, genre, lyrics,image_file):
audiofile = eyed3.load(file_path)

# 设置标签信息
audiofile.tag.title = title
audiofile.tag.artist = artist
audiofile.tag.album = album
audiofile.tag.release_date = year
audiofile.tag.genre = genre

# 添加歌词
# audiofile.tag.lyrics.set(lyrics)

# 读取图片文件的二进制数据
with open(image_file, "rb") as image:
image_data = image.read()

# 设置封面
audiofile.tag.images.set(3, image_data, "image/jpeg", u"Description")

# 保存更改
audiofile.tag.save()

def adjust_audio_dB(audio, target_dB):
# 调整音频的分贝数
adjustment = target_dB - audio.dBFS
adjusted_audio = audio + adjustment
return adjusted_audio

def main():
song_name = "song_name"

#文件名
file_path = "...\\音频\\" + song_name + ".mp3"
image_file_path = "...\\图片\\" + song_name + ".jpg"

# 调整分贝数
# 读取音频文件
audio = AudioSegment.from_mp3(file_path)

# # 获取当前分贝数
# current_dB = get_audio_dB(audio)
# print(f"当前音频的分贝数: {current_dB} dB")

# 指定目标分贝数
target_dB = -16.7 # 例如,将目标分贝数设置为 -10 dB

# 调整音频的分贝数
adjusted_audio = adjust_audio_dB(audio, target_dB)

# 保存调整后的音频
adjusted_audio.export(file_path, format="mp3")


#标签
title = song_name
artist = "artist"
album = "live"
year = "2013"
genre = "Pop"
lyrics = "歌词"

#打标签
edit_mp3_tags(file_path, title, artist, album, year, genre, lyrics, image_file_path)


if __name__ == "__main__":
main()


4、通过网站生成歌词文件

https://lrcgenerator.com/

将生成的歌词文件和MP3文件放在同一个文件夹,同时保证除了后缀名不同,其他保持一致。

5.上传音乐播放器

以网易云为例:直接通过“我的音乐云盘”上传,不能通过“本地与下载”上传,会出现播放其他音源的错误。