Spaces:
Sleeping
Sleeping
Commit
·
7a67d26
1
Parent(s):
52d3b9c
1st
Browse files- README.md +127 -1
- app.py +61 -0
- requirements.txt +2 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: BGMixer
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
@@ -11,3 +11,129 @@ short_description: 幫一段podcast mp3 做背景音樂BGM混音的工具
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: BGMixer
|
3 |
+
emoji: 🎵
|
4 |
colorFrom: green
|
5 |
colorTo: yellow
|
6 |
sdk: gradio
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
14 |
+
|
15 |
+
|
16 |
+
# 🎵 BGMixer - Podcast 背景音樂混音工具
|
17 |
+
|
18 |
+
BGMixer 是一款簡單易用的 Podcast 背景音樂混音工具,讓你輕鬆將背景音樂 (BGM) 添加到 Podcast,並調整音量、淡入淡出效果,適合 Podcast 製作人或內容創作者。
|
19 |
+
|
20 |
+
🚀 **特色功能:**
|
21 |
+
- ✅ **Podcast & BGM 上傳**:支援 MP3 格式
|
22 |
+
- ✅ **BGM 音量調整**:可調整背景音樂音量(預設 -14 dB)
|
23 |
+
- ✅ **BGM 循環播放 (Loop)**:可選是否自動重複 BGM 來符合 Podcast 長度
|
24 |
+
- ✅ **淡入淡出 (Fade in/out)**:可選擇是否開啟,並設定秒數(預設 5 秒)
|
25 |
+
- ✅ **即時預覽 & 下載**:混音完成後可直接播放 & 下載 MP3
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
## 🛠️ 安裝與執行方式
|
30 |
+
|
31 |
+
### **1️⃣ 本機運行**
|
32 |
+
|
33 |
+
#### **📌 安裝必要套件**
|
34 |
+
```bash
|
35 |
+
pip install gradio pydub
|
36 |
+
```
|
37 |
+
|
38 |
+
#### **📌 執行應用程式**
|
39 |
+
```bash
|
40 |
+
python app.py
|
41 |
+
```
|
42 |
+
|
43 |
+
應用程式將會在本機啟動,並提供 Web UI 讓你操作。
|
44 |
+
|
45 |
+
---
|
46 |
+
|
47 |
+
### **2️⃣ 部署到 Hugging Face Spaces**
|
48 |
+
1. 前往 [Hugging Face Spaces](https://huggingface.co/spaces) 建立新空間
|
49 |
+
2. 選擇 **Gradio** 作為應用類型
|
50 |
+
3. 連結 GitHub Repo 或手動上傳 `app.py`
|
51 |
+
4. 在 `requirements.txt` 加入:
|
52 |
+
```
|
53 |
+
gradio
|
54 |
+
pydub
|
55 |
+
```
|
56 |
+
5. 等待自動部署完成 🎉
|
57 |
+
|
58 |
+
---
|
59 |
+
|
60 |
+
## 🚀 **使用方式**
|
61 |
+
|
62 |
+
1️⃣ **上傳** 你的 Podcast (MP3) 與 BGM (MP3) 🔼
|
63 |
+
2️⃣ **設定音量**、是否開啟 **Loop** 與 **淡入淡出**
|
64 |
+
3️⃣ 點擊 **開始混音** 🚀
|
65 |
+
4️⃣ **播放預覽 & 下載** 你的混音 Podcast 🎧
|
66 |
+
|
67 |
+
---
|
68 |
+
|
69 |
+
## 🤝 貢獻指南
|
70 |
+
歡迎 Pull Requests!請確保:
|
71 |
+
- 使用 Python 進行開發
|
72 |
+
- 遵循 `pydub` & `gradio` 標準
|
73 |
+
- 提交 PR 時附上簡要說明
|
74 |
+
|
75 |
+
---
|
76 |
+
|
77 |
+
# 🎵 BGMixer - Podcast Background Music Mixer
|
78 |
+
|
79 |
+
BGMixer is a simple and user-friendly tool that allows you to mix background music (BGM) into your podcast, adjust volume, apply fade effects, and more. Ideal for podcast creators and content producers.
|
80 |
+
|
81 |
+
🚀 **Features:**
|
82 |
+
- ✅ **Upload Podcast & BGM** (MP3 support)
|
83 |
+
- ✅ **Adjust BGM Volume** (default -14 dB)
|
84 |
+
- ✅ **Loop BGM** (optional, automatically repeats BGM to match podcast length)
|
85 |
+
- ✅ **Fade In/Out** (optional, customizable duration, default 5 sec)
|
86 |
+
- ✅ **Preview & Download** mixed MP3 files
|
87 |
+
|
88 |
+
---
|
89 |
+
|
90 |
+
## 🛠️ Installation & Usage
|
91 |
+
|
92 |
+
### **1️⃣ Run Locally**
|
93 |
+
|
94 |
+
#### **📌 Install dependencies**
|
95 |
+
```bash
|
96 |
+
pip install gradio pydub
|
97 |
+
```
|
98 |
+
|
99 |
+
#### **📌 Start the application**
|
100 |
+
```bash
|
101 |
+
python app.py
|
102 |
+
```
|
103 |
+
|
104 |
+
The app will launch locally, providing a user-friendly web interface.
|
105 |
+
|
106 |
+
---
|
107 |
+
|
108 |
+
### **2️⃣ Deploy on Hugging Face Spaces**
|
109 |
+
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces) and create a new space
|
110 |
+
2. Select **Gradio** as the application type
|
111 |
+
3. Connect your GitHub repository or manually upload `app.py`
|
112 |
+
4. Add the following to `requirements.txt`:
|
113 |
+
```
|
114 |
+
gradio
|
115 |
+
pydub
|
116 |
+
```
|
117 |
+
5. Wait for automatic deployment 🎉
|
118 |
+
|
119 |
+
---
|
120 |
+
|
121 |
+
## 🚀 **How to Use**
|
122 |
+
|
123 |
+
1️⃣ **Upload** your Podcast (MP3) and BGM (MP3) 🔼
|
124 |
+
2️⃣ **Adjust volume**, enable/disable **Loop** and **Fade In/Out**
|
125 |
+
3️⃣ Click **Start Mixing** 🚀
|
126 |
+
4️⃣ **Preview & Download** the mixed Podcast 🎧
|
127 |
+
|
128 |
+
---
|
129 |
+
|
130 |
+
## 🤝 Contribution Guide
|
131 |
+
Pull requests are welcome! Please ensure:
|
132 |
+
- Development is done in Python
|
133 |
+
- Code follows `pydub` & `gradio` standards
|
134 |
+
- PRs include a brief description of changes
|
135 |
+
|
136 |
+
---
|
137 |
+
|
138 |
+
🎵 Happy Podcast Mixing! 🎙️
|
139 |
+
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pydub import AudioSegment
|
3 |
+
import os
|
4 |
+
|
5 |
+
def mix_audio(podcast_file, bgm_file, bgm_volume, loop, fade_in_out, fade_duration):
|
6 |
+
if not podcast_file or not bgm_file:
|
7 |
+
return "請上傳 Podcast 和 BGM 檔案", None
|
8 |
+
|
9 |
+
# 讀取音檔
|
10 |
+
podcast = AudioSegment.from_file(podcast_file)
|
11 |
+
bgm = AudioSegment.from_file(bgm_file)
|
12 |
+
|
13 |
+
# 調整 BGM 音量
|
14 |
+
bgm = bgm - abs(bgm_volume) # 降低 dB
|
15 |
+
|
16 |
+
# 是否需要 loop BGM
|
17 |
+
if loop:
|
18 |
+
loop_count = len(podcast) // len(bgm) + 1
|
19 |
+
bgm = bgm * loop_count # 重複播放
|
20 |
+
bgm = bgm[:len(podcast)] # 修剪至 Podcast 長度
|
21 |
+
|
22 |
+
# 是否添加淡入淡出效果
|
23 |
+
if fade_in_out:
|
24 |
+
bgm = bgm.fade_in(fade_duration * 1000).fade_out(fade_duration * 1000)
|
25 |
+
|
26 |
+
# 混音
|
27 |
+
mixed = podcast.overlay(bgm)
|
28 |
+
|
29 |
+
# 儲存混音結果
|
30 |
+
output_file = "mixed_podcast.mp3"
|
31 |
+
mixed.export(output_file, format="mp3")
|
32 |
+
|
33 |
+
return "混音完成!點擊下載", output_file
|
34 |
+
|
35 |
+
# 建立 Gradio 介面
|
36 |
+
with gr.Blocks() as app:
|
37 |
+
gr.Markdown("## 🎙️ Podcast 混音工具 🎵")
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
podcast_input = gr.File(label="📥 上傳 Podcast MP3", type="file")
|
42 |
+
bgm_input = gr.File(label="🎵 上傳背景音樂 MP3", type="file")
|
43 |
+
bgm_volume = gr.Slider(-30, 0, value=-14, label="🎚️ 背景音樂音量調整 (dB, 越小越小聲)")
|
44 |
+
loop_option = gr.Checkbox(value=True, label="🔁 背景音樂循環")
|
45 |
+
fade_option = gr.Checkbox(value=True, label="🎼 添加淡入淡出效果")
|
46 |
+
fade_duration = gr.Slider(1, 10, value=5, label="⏳ 淡入淡出秒數")
|
47 |
+
process_button = gr.Button("🚀 開始混音")
|
48 |
+
|
49 |
+
with gr.Column():
|
50 |
+
output_message = gr.Textbox(label="📢 處理狀態", interactive=False)
|
51 |
+
audio_output = gr.Audio(label="🎧 預覽混音結果", interactive=True)
|
52 |
+
download_output = gr.File(label="⬇️ 下載混音 MP3")
|
53 |
+
|
54 |
+
process_button.click(
|
55 |
+
fn=mix_audio,
|
56 |
+
inputs=[podcast_input, bgm_input, bgm_volume, loop_option, fade_option, fade_duration],
|
57 |
+
outputs=[output_message, download_output]
|
58 |
+
)
|
59 |
+
|
60 |
+
# 執行 Gradio 應用
|
61 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pydub
|