我如何使用python混合音频文件? [英] How do I mix audio files using python?

查看:753
本文介绍了我如何使用python混合音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿做基本的音频混合蟒蛇

I would like to do basic audio mixing in python.

要举个例子:我想需要两个mp3文件,并添加在一起,并返回的MP3文件。又如:我想举一个MP3文件的前十秒钟,它添加到另一个MP3文件的开头

To give an example: I would like to take two mp3 files and add them together and return one mp3 file. Another example: I would like to take the first ten seconds of one mp3 file and add it to the beginning of another mp3 file.

什么是完成这些任务的最佳方式?我想用建于​​像audioop Python函数,但找不到任何好的教程或样品code那里为使用内置的功能。

What is the best way to accomplish these tasks? I would like to use built in python functions like audioop but can not find any good tutorials or sample code out there for using the built in functions.

我经历的文档,但我pretty混乱,无法弄清楚如何做这样的事情。我甚至不能确定,像MP3的蟒蛇库。大部分我看过的东西似乎是指WAV文件。所以,如果是这样的话,我想跟进的问题是有没有一个简单的方法,以一个MP3转换为操纵WAV和回来?

I am going through the docs but I am pretty confused and cannot figure out how to do things like this. I am not even sure that the python libraries like mp3's. Most of the stuff I have looked at seem to refer to WAV files. So, if this is the case, I guess a follow up question would be is there an easy way to convert an mp3 to a WAV for manipulation and back again?

推荐答案

您可以轻松地做到这一点pretty使用 pydub

You can do this pretty easily using pydub:

from pydub import AudioSegment

sound1 = AudioSegment.from_mp3("/path/to/file1.mp3")
sound2 = AudioSegment.from_mp3("/path/to/file1.mp3")

# mix sound2 with sound1, starting at 5000ms into sound1)
output = sound1.overlay(sound2, position=5000)

# save the result
output.export("mixed_sounds.mp3", format="mp3")

这篇关于我如何使用python混合音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆