Spaces:
Running
Running
UPDATE
Browse files
app.py
CHANGED
@@ -136,15 +136,128 @@ with gr.Blocks(title="Audio Fusion") as iface:
|
|
136 |
|
137 |
client = TelegramClient('session_name', API_ID, API_HASH)
|
138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
@client.on(events.NewMessage(pattern='/start'))
|
140 |
async def start_handler(event):
|
141 |
-
await event.respond(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
-
@client.on(events.NewMessage(
|
144 |
-
async def
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
async def initiation():
|
150 |
await client.send_message(-1001662130485, "**Hugging is Running.**", buttons=[(Button.url("Execal", "https://t.me/execal"),)],)
|
|
|
136 |
|
137 |
client = TelegramClient('session_name', API_ID, API_HASH)
|
138 |
|
139 |
+
|
140 |
+
# Define the available commands
|
141 |
+
commands = {
|
142 |
+
'/start': 'Welcome to Audio Bot! Send me an audio file to get started.',
|
143 |
+
'/help': 'List all available commands.',
|
144 |
+
'/trim': 'Trim the audio. Usage: /trim start_time end_time',
|
145 |
+
'/volume': 'Adjust volume. Usage: /volume level',
|
146 |
+
'/reverse': 'Reverse the audio.',
|
147 |
+
'/reverb': 'Apply reverb effect to the audio. Usage: /reverb roomSize damping width wetLevel dryLevel',
|
148 |
+
'/speedup': 'Increase the speed of the audio.',
|
149 |
+
'/slowdown': 'Decrease the speed of the audio.',
|
150 |
+
'/effect8D': 'Apply 8D effect to the audio. Usage: /effect8D panBoundary jumpPercentage timeLtoR volumeMultiplier',
|
151 |
+
'/save': 'Save the modified audio. Usage: /save outputFileName',
|
152 |
+
}
|
153 |
+
|
154 |
@client.on(events.NewMessage(pattern='/start'))
|
155 |
async def start_handler(event):
|
156 |
+
await event.respond(commands['/start'])
|
157 |
+
|
158 |
+
@client.on(events.NewMessage(pattern='/help'))
|
159 |
+
async def help_handler(event):
|
160 |
+
help_text = '\n'.join(f'{cmd}: {desc}' for cmd, desc in commands.items())
|
161 |
+
await event.respond(help_text)
|
162 |
+
|
163 |
+
@client.on(events.NewMessage(incoming=True))
|
164 |
+
async def audio_handler(event):
|
165 |
+
reply = await event.get_reply_message()
|
166 |
+
if event.message.media and event.message.media.document.mime_type.startswith('audio') and event.is_private:
|
167 |
+
# Download the audio file
|
168 |
+
file_path = await client.download_media(event.message, f"downloads/{event.sender.id}_audio.mp3")
|
169 |
+
try:
|
170 |
+
# Load the audio file using your AudioFusion class
|
171 |
+
audio = Fusion.loadSound(file_path)
|
172 |
+
except Fusion.InvalidMusicFileError as e:
|
173 |
+
await event.respond(f'Error: {e}')
|
174 |
+
return os.remove(file_path)
|
175 |
+
elif event.is_group and reply and event.text.startswith("/edit"):
|
176 |
+
file_path = await reply.download_media(f"downloads/{event.sender.id}_audio.mp3")
|
177 |
+
try:
|
178 |
+
# Load the audio file using your AudioFusion class
|
179 |
+
audio = Fusion.loadSound(file_path)
|
180 |
+
except Fusion.InvalidMusicFileError as e:
|
181 |
+
await event.respond(f'Error: {e}')
|
182 |
+
return os.remove(file_path)
|
183 |
+
else:
|
184 |
+
if event.is_private: return await event.respond("`Please send an audio file...`")
|
185 |
+
|
186 |
|
187 |
+
@client.on(events.NewMessage(incoming=True))
|
188 |
+
async def audio_editor(event):
|
189 |
+
file_path = f"downloads/{event.sender.id}_audio.mp3"
|
190 |
+
try:
|
191 |
+
# Load the audio file using your AudioFusion class
|
192 |
+
audio = Fusion.loadSound(file_path)
|
193 |
+
except Fusion.InvalidMusicFileError as e:
|
194 |
+
await event.respond(f'Error: {e}')
|
195 |
+
return os.remove(file_path)
|
196 |
|
197 |
+
|
198 |
+
# Process the user's command
|
199 |
+
if event.raw_text.startswith('/trim'):
|
200 |
+
# Parse parameters and apply the trim effect
|
201 |
+
# Example usage: /trim 5000 10000
|
202 |
+
parameters = event.raw_text.split()[1:]
|
203 |
+
start_time, end_time = map(int, parameters)
|
204 |
+
audio = audio[start_time:end_time]
|
205 |
+
await event.reply("`Following effect added to your audio file...`")
|
206 |
+
|
207 |
+
elif event.raw_text.startswith('/volume'):
|
208 |
+
# Parse parameters and adjust volume
|
209 |
+
# Example usage: /volume 3
|
210 |
+
parameters = event.raw_text.split()[1:]
|
211 |
+
volume_level = int(parameters[0])
|
212 |
+
audio = audio + volume_level # Adjust volume using Pydub's volume adjustment
|
213 |
+
await event.reply("`Following effect added to your audio file...`")
|
214 |
+
|
215 |
+
elif event.raw_text.startswith('/reverse'):
|
216 |
+
# Reverse the audio
|
217 |
+
audio = audio.reverse()
|
218 |
+
await event.reply("`Following effect added to your audio file...`")
|
219 |
+
|
220 |
+
elif event.raw_text.startswith('/speedup'):
|
221 |
+
# Increase the speed of the audio
|
222 |
+
audio = Fusion.effectSlowed(audio, speedMultiplier=0.8)
|
223 |
+
await event.reply("`Following effect added to your audio file...`")
|
224 |
+
|
225 |
+
elif event.raw_text.startswith('/slowdown'):
|
226 |
+
# Decrease the speed of the audio
|
227 |
+
audio = Fusion.effectSlowed(audio, speedMultiplier=1.2)
|
228 |
+
await event.reply("`Following effect added to your audio file...`")
|
229 |
+
|
230 |
+
elif event.raw_text.startswith('/effect8D'):
|
231 |
+
# Parse parameters and apply the effect
|
232 |
+
# Example usage: /effect8D 100 5 10000 6
|
233 |
+
parameters = event.raw_text.split()[1:]
|
234 |
+
audio = Fusion.effect8D(audio, *map(int, parameters))
|
235 |
+
await event.reply("`Following effect added to your audio file...`")
|
236 |
+
|
237 |
+
elif event.raw_text.startswith('/effectReverb'):
|
238 |
+
# Parse parameters and apply the effect
|
239 |
+
# Example usage: /effectReverb 0.8 1 0.5 0.3 0.8
|
240 |
+
parameters = event.raw_text.split()[1:]
|
241 |
+
audio = Fusion.effectReverb(audio, *map(float, parameters))
|
242 |
+
await event.reply("`Following effect added to your audio file...`")
|
243 |
+
|
244 |
+
|
245 |
+
elif event.raw_text.startswith('/save'):
|
246 |
+
# Parse parameters and save the modified audio
|
247 |
+
# Example usage: /save outputFileName
|
248 |
+
parameters = event.raw_text.split()[1:]
|
249 |
+
output_file_name = parameters[0]
|
250 |
+
output_file_path = Fusion.saveSound(audio, output_file_name)
|
251 |
+
|
252 |
+
# Send the modified audio file to the user
|
253 |
+
await client.send_file(event.chat_id, output_file_path, caption=f'Modified audio: {output_file_name}.mp3')
|
254 |
+
|
255 |
+
# Clean up the temporary files
|
256 |
+
os.remove(file_path)
|
257 |
+
os.remove(output_file_path)
|
258 |
+
|
259 |
+
elif event.raw_text.startswith('/delete'):
|
260 |
+
os.remove(file_path)
|
261 |
|
262 |
async def initiation():
|
263 |
await client.send_message(-1001662130485, "**Hugging is Running.**", buttons=[(Button.url("Execal", "https://t.me/execal"),)],)
|