Update AudioEditingCode_Demo.ipynb
Browse files- AudioEditingCode_Demo.ipynb +159 -80
AudioEditingCode_Demo.ipynb
CHANGED
@@ -1,81 +1,160 @@
|
|
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 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {},
|
6 |
+
"source": [
|
7 |
+
"# AudioEditingCode Colab Demo\n",
|
8 |
+
"\n",
|
9 |
+
"This notebook demonstrates how to use the `AudioEditingCode` repository in Google Colab.\n",
|
10 |
+
"\n",
|
11 |
+
"## 1. Clone the repository\n"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": null,
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"!git clone https://github.com/HilaManor/AudioEditingCode.git\n",
|
21 |
+
"%cd AudioEditingCode\n"
|
22 |
+
]
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"cell_type": "markdown",
|
26 |
+
"metadata": {},
|
27 |
+
"source": [
|
28 |
+
"## 2. Install dependencies\n"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "code",
|
33 |
+
"execution_count": null,
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": [
|
37 |
+
"!pip install -r requirements.txt\n"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "markdown",
|
42 |
+
"metadata": {},
|
43 |
+
"source": [
|
44 |
+
"## 3. Demo Usage\n",
|
45 |
+
"\n",
|
46 |
+
"Here you can add examples of how to use the code. You might need to download some audio files for demonstration.\n",
|
47 |
+
"\n",
|
48 |
+
"### Download example audio\n"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": null,
|
54 |
+
"metadata": {},
|
55 |
+
"outputs": [],
|
56 |
+
"source": [
|
57 |
+
"!wget https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3 -O input_audio.mp3\n"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "markdown",
|
62 |
+
"metadata": {},
|
63 |
+
"source": [
|
64 |
+
"### Text-Based Editing Example\n",
|
65 |
+
"\n",
|
66 |
+
"This example uses `main_run.py` for text-based audio editing. You will need a Hugging Face token to use models like Stable Audio Open. Please visit [Hugging Face](https://huggingface.co/settings/tokens) to get your token and replace `<YOUR_HF_TOKEN>` below.\n"
|
67 |
+
]
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"cell_type": "code",
|
71 |
+
"execution_count": null,
|
72 |
+
"metadata": {},
|
73 |
+
"outputs": [],
|
74 |
+
"source": [
|
75 |
+
"import os\n",
|
76 |
+
"\n",
|
77 |
+
"# Replace with your actual Hugging Face token\n",
|
78 |
+
"os.environ[\"HF_TOKEN\"] = \"<YOUR_HF_TOKEN>\"\n",
|
79 |
+
"\n",
|
80 |
+
"!python code/main_run.py \\\n",
|
81 |
+
" --cfg_tar 1.5 \\\n",
|
82 |
+
" --cfg_src 0.5 \\\n",
|
83 |
+
" --init_aud input_audio.mp3 \\\n",
|
84 |
+
" --target_prompt \"a dog barking\" \\\n",
|
85 |
+
" --tstart 100 \\\n",
|
86 |
+
" --model_id cvssp/audioldm-s-full-v2 \\\n",
|
87 |
+
" --results_path results_text_based\n"
|
88 |
+
]
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"cell_type": "markdown",
|
92 |
+
"metadata": {},
|
93 |
+
"source": [
|
94 |
+
"### Unsupervised Editing Example\n",
|
95 |
+
"\n",
|
96 |
+
"First, extract the principal components:\n",
|
97 |
+
"\n"
|
98 |
+
]
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"cell_type": "code",
|
102 |
+
"execution_count": null,
|
103 |
+
"metadata": {},
|
104 |
+
"outputs": [],
|
105 |
+
"source": [
|
106 |
+
"!python code/main_pc_extract_inv.py \\\n",
|
107 |
+
" --init_aud input_audio.mp3 \\\n",
|
108 |
+
" --model_id cvssp/audioldm-s-full-v2 \\\n",
|
109 |
+
" --results_path results_unsupervised_extract \\\n",
|
110 |
+
" --drift_start 0 \\\n",
|
111 |
+
" --drift_end 200 \\\n",
|
112 |
+
" --n_evs 5\n"
|
113 |
+
]
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"cell_type": "markdown",
|
117 |
+
"metadata": {},
|
118 |
+
"source": [
|
119 |
+
"Then, apply the principal components:\n",
|
120 |
+
"\n"
|
121 |
+
]
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"cell_type": "code",
|
125 |
+
"execution_count": null,
|
126 |
+
"metadata": {},
|
127 |
+
"outputs": [],
|
128 |
+
"source": [
|
129 |
+
"!python code/main_pc_apply_drift.py \\\n",
|
130 |
+
" --extraction_path results_unsupervised_extract/input_audio_cvssp_audioldm-s-full-v2_inversion_data.pt \\\n",
|
131 |
+
" --drift_start 0 \\\n",
|
132 |
+
" --drift_end 200 \\\n",
|
133 |
+
" --amount 1.0 \\\n",
|
134 |
+
" --evs 0\n"
|
135 |
+
]
|
136 |
+
}
|
137 |
+
],
|
138 |
+
"metadata": {
|
139 |
+
"kernelspec": {
|
140 |
+
"display_name": "Python 3",
|
141 |
+
"language": "python",
|
142 |
+
"name": "python3"
|
143 |
+
},
|
144 |
+
"language_info": {
|
145 |
+
"codemirror_mode": {
|
146 |
+
"name": "ipython",
|
147 |
+
"version": 3
|
148 |
+
},
|
149 |
+
"file_extension": ".py",
|
150 |
+
"mimetype": "text/x-python",
|
151 |
+
"name": "python",
|
152 |
+
"nbconvert_exporter": "python",
|
153 |
+
"pygments_lexer": "ipython3",
|
154 |
+
"version": "3.10.12"
|
155 |
+
}
|
156 |
+
},
|
157 |
+
"nbformat": 4,
|
158 |
+
"nbformat_minor": 4
|
159 |
+
}
|
160 |
|