1616
1717import os
1818import random
19- import subprocess
2019from io import BytesIO
2120
2221from pyrogram import Client , filters
2322from pyrogram .raw .functions .messages import SendMedia
2423from pyrogram .raw .types import DocumentAttributeAudio , InputMediaUploadedDocument
2524from pyrogram .types import Message
26- from utils .scripts import format_exc , generate_waveform , import_library
2725
2826from utils import modules_help , prefix
27+ from utils .scripts import format_exc , generate_waveform , import_library
2928
29+ import_library ("miniaudio" )
3030tabulate = import_library ("tabulate" )
3131edge_tts = import_library ("edge_tts" , "edge-tts" )
3232
3535from tabulate import tabulate
3636
3737
38- async def send_voice (client , chat_id , voice_bytes , duration ):
39- waveform = generate_waveform (voice_bytes .getvalue ())
40-
38+ async def send_voice (client , chat_id , voice_bytes , duration , waveform ):
4139 voice_bytes .seek (0 )
4240 file = await client .save_file (voice_bytes )
4341
@@ -56,26 +54,6 @@ async def send_voice(client, chat_id, voice_bytes, duration):
5654 )
5755
5856
59- async def get_duration (file_path : str ):
60- command = [
61- "ffprobe" ,
62- "-v" , "error" ,
63- "-show_entries" , "format=duration" ,
64- "-of" , "default=noprint_wrappers=1:nokey=1" ,
65- file_path
66- ]
67-
68- try :
69- process = subprocess .run (command , capture_output = True , text = True , check = True )
70- output = process .stdout .strip ()
71- if output :
72- return int (float (output ))
73- except Exception :
74- pass
75-
76- return 0
77-
78-
7957async def all_voices (* , proxy : str | None ) -> None :
8058 """All available voices."""
8159 voices = await list_voices (proxy = proxy )
@@ -130,16 +108,16 @@ async def etts(client: Client, message: Message):
130108 communicate = Communicate (text = text , voice = lang )
131109 communicate .save_sync ("voice.ogg" )
132110
133- duration = await get_duration ("voice.ogg" )
134-
135111 with open ("voice.ogg" , "rb" ) as f :
136112 data = f .read ()
137113
114+ waveform , duration = await generate_waveform (data )
115+
138116 voice = BytesIO (data )
139117 voice .name = "voice.ogg"
140118
141119 await message .delete ()
142- await send_voice (client , message .chat .id , voice , duration )
120+ await send_voice (client , message .chat .id , voice , duration , waveform )
143121
144122 except Exception as e :
145123 await message .edit (format_exc (e ))
@@ -195,17 +173,17 @@ async def estts(client: Client, message: Message):
195173 with open ("voice.srt" , "w" , encoding = "utf-8" ) as file :
196174 file .write (submaker .get_srt ())
197175
198- duration = await get_duration ("voice.ogg" )
199-
200176 with open ("voice.ogg" , "rb" ) as f :
201177 data = f .read ()
202178
179+ waveform , duration = await generate_waveform (data )
180+
203181 voice = BytesIO (data )
204182 voice .name = "voice.ogg"
205183
206184 await message .delete ()
207185
208- await send_voice (client , message .chat .id , voice , duration )
186+ await send_voice (client , message .chat .id , voice , duration , waveform )
209187 await client .send_document (message .chat .id , "voice.srt" )
210188
211189 except Exception as e :
0 commit comments