帮我写一个 python代码,音频去人声,留下伴奏,针对MP3的
时间: 2023-08-28 17:10:43 浏览: 113
用python批量去除mp3中的静音段
好的,以下是python代码:
```
import os
from pydub import AudioSegment
# Step 1: Load Audio File
audio_file = AudioSegment.from_file("input_file.mp3", format="mp3")
# Step 2: Split Audio into Channels (Stereo audio only)
left_channel = audio_file.split_to_mono()[0]
right_channel = audio_file.split_to_mono()[1]
# Step 3: Invert Phase of Left Channel
inverted_left_channel = left_channel.invert_phase()
# Step 4: Combine Inverted Left Channel with Right Channel
accompaniment_only = inverted_left_channel.overlay(right_channel)
# Step 5: Export Accompaniment Only Audio File
accompaniment_only.export("output_file.mp3", format="mp3")
```
这个代码将会读取 "input_file.mp3" 音频文件,然后将人声去除,在 "output_file.mp3" 中输出伴奏。
阅读全文