zarox commited on
Commit
b16d41d
·
verified ·
1 Parent(s): 84b7a86
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -8,6 +8,9 @@ from fusion import Fusion
8
 
9
  from telethon import TelegramClient, events, Button
10
 
 
 
 
11
  API_ID = os.environ.get("API_ID")
12
  API_HASH = os.environ.get("API_HASH")
13
  BOT_TOKEN = os.environ.get("BOT_TOKEN")
@@ -138,13 +141,24 @@ with gr.Blocks(title="Audio Fusion") as iface:
138
 
139
  client = TelegramClient('session_name', API_ID, API_HASH)
140
 
141
- # Define the states for user interaction
142
- # class State:
143
- # def __init__(self, client) -> None:
144
- # self.slow =
145
- # self.speed =
146
- # self.reverb =
147
- # self.reverse =
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  states = {}
150
 
@@ -211,7 +225,7 @@ async def audio_effect_handler(event):
211
  # Update the user's state with the modified sound
212
  states[user_id]['audio'] = audio
213
 
214
- await event.answer("Effect applied. Click /send to receive the modified audio file.", alert="True")
215
 
216
 
217
 
@@ -237,13 +251,15 @@ async def send_handler(event):
237
  user_id = event.sender_id
238
  if user_id in states and states[user_id]:
239
  # Send the modified sound file
240
- output_file_name = f"{user_id}_modified_audio"
241
- output_file = await Fusion.saveSound(states[user_id]["audio"], output_file_name)
242
- await event.reply(file=output_file)
 
 
243
 
244
  # Clean up - remove the user's state and the saved audio file
245
  del states[user_id]
246
- os.remove(output_file)
247
  await event.delete()
248
  else:
249
  await event.answer("No modified audio file found. Please apply an effect first.")
 
8
 
9
  from telethon import TelegramClient, events, Button
10
 
11
+ from telethon.tl.functions.messages import SendMedia
12
+ from telethon.tl.types import InputMediaUploadedDocument
13
+
14
  API_ID = os.environ.get("API_ID")
15
  API_HASH = os.environ.get("API_HASH")
16
  BOT_TOKEN = os.environ.get("BOT_TOKEN")
 
141
 
142
  client = TelegramClient('session_name', API_ID, API_HASH)
143
 
144
+
145
+ async def send_audio(chat, audio):
146
+ media = InputMediaUploadedDocument(
147
+ file=await client.upload_file(io.BytesIO(audio)),
148
+ mime_type='audio/mpeg',
149
+ attributes=[
150
+ DocumentAttributeAudio(
151
+ title='Audio Title', # Set the title of the audio
152
+ )
153
+ ]
154
+ )
155
+
156
+ # Send the audio file as music
157
+ await client(SendMedia(
158
+ peer=chat,
159
+ media=media,
160
+ message='Optional caption for the audio'
161
+ ))
162
 
163
  states = {}
164
 
 
225
  # Update the user's state with the modified sound
226
  states[user_id]['audio'] = audio
227
 
228
+ await event.answer("Effect applied. Click /send to receive the modified audio file.", alert=True)
229
 
230
 
231
 
 
251
  user_id = event.sender_id
252
  if user_id in states and states[user_id]:
253
  # Send the modified sound file
254
+ # output_file_name = f"{user_id}_modified_audio"
255
+ # output_file = await Fusion.saveSound(states[user_id]["audio"], output_file_name)
256
+ # await event.reply(file=output_file)
257
+
258
+ await send_audio(event.chat_id, states[user_id]["audio"])
259
 
260
  # Clean up - remove the user's state and the saved audio file
261
  del states[user_id]
262
+ # os.remove(output_file)
263
  await event.delete()
264
  else:
265
  await event.answer("No modified audio file found. Please apply an effect first.")