zarox commited on
Commit
42b3c3e
·
verified ·
1 Parent(s): 8c9b8a9
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -3,8 +3,7 @@ import secrets
3
  import threading
4
  import gradio as gr
5
  from io import BytesIO
6
- from AudioFusion import Fusion
7
- from pydub import AudioSegment
8
 
9
  from telethon.sync import TelegramClient, events, Button
10
 
@@ -168,7 +167,7 @@ async def buttons_handler(event):
168
  audio_file.seek(0)
169
 
170
  # Store the audio file in the user's state
171
- states[user_id] = audio_file
172
 
173
  await client.send_file(event.chat_id, file="image.jpg", caption="Preview the current modification:", buttons=buttons)
174
 
@@ -181,15 +180,15 @@ async def audio_effect_handler(event):
181
  return
182
 
183
  # Retrieve the audio file from the user's state
184
- audio_file = states[user_id]
185
 
186
  query = event.pattern_match.group(1).decode("UTF-8")
187
  try:
188
- sound = AudioSegment.from_file(audio_file, format="mp3")
189
  if query == 'slowed':
190
- modified_sound = Fusion.effectSlowed(sound, 0.82)
191
  elif query == 'speedup':
192
- modified_sound = Fusion.effectSlowed(sound, 1.2)
193
  elif query == '8d':
194
  modified_sound = Fusion.effect8D(sound)
195
  elif query == 'reverb':
@@ -201,9 +200,9 @@ async def audio_effect_handler(event):
201
 
202
 
203
  # Update the user's state with the modified sound
204
- states[user_id] = modified_sound
205
 
206
- await event.answer("Effect applied. Click /send to receive the modified audio file.")
207
 
208
  except Fusion.InvalidMusicFileError as e:
209
  await event.reply(str(e))
@@ -225,11 +224,11 @@ async def preview_handler(event):
225
  # Clean up - remove the saved preview audio file
226
  os.remove(output_file)
227
  else:
228
- await event.answer("No modified audio file found. Please apply an effect first.")
229
 
230
 
231
  @client.on(events.CallbackQuery(pattern=b'send'))
232
- async def send_handler(event):
233
  user_id = event.sender_id
234
  if user_id in states and states[user_id]:
235
  # Send the modified sound file
 
3
  import threading
4
  import gradio as gr
5
  from io import BytesIO
6
+ from fusion import Fusion
 
7
 
8
  from telethon.sync import TelegramClient, events, Button
9
 
 
167
  audio_file.seek(0)
168
 
169
  # Store the audio file in the user's state
170
+ states[user_id] = {'audio': audio_file}
171
 
172
  await client.send_file(event.chat_id, file="image.jpg", caption="Preview the current modification:", buttons=buttons)
173
 
 
180
  return
181
 
182
  # Retrieve the audio file from the user's state
183
+ audio_file = states[user_id]['audio']
184
 
185
  query = event.pattern_match.group(1).decode("UTF-8")
186
  try:
187
+ sound = Fusion.from_file(audio_file, format="mp3")
188
  if query == 'slowed':
189
+ modified_sound = Fusion.effectSlowed(sound, 0.9)
190
  elif query == 'speedup':
191
+ modified_sound = Fusion.effectSlowed(sound, 1.1)
192
  elif query == '8d':
193
  modified_sound = Fusion.effect8D(sound)
194
  elif query == 'reverb':
 
200
 
201
 
202
  # Update the user's state with the modified sound
203
+ states[user_id]['audio'] = modified_sound
204
 
205
+ await event.answer("Effect applied. Click /send to receive the modified audio file.", alert="True")
206
 
207
  except Fusion.InvalidMusicFileError as e:
208
  await event.reply(str(e))
 
224
  # Clean up - remove the saved preview audio file
225
  os.remove(output_file)
226
  else:
227
+ await event.answer("No modified audio file found. Please apply an effect first.", alert=True)
228
 
229
 
230
  @client.on(events.CallbackQuery(pattern=b'send'))
231
+ async def send_handler(event):
232
  user_id = event.sender_id
233
  if user_id in states and states[user_id]:
234
  # Send the modified sound file