aria2 downloading support
Browse files- App/TTS/utils/Descript.py +33 -11
- Dockerfile +5 -2
App/TTS/utils/Descript.py
CHANGED
@@ -7,6 +7,7 @@ from datetime import datetime, timedelta
|
|
7 |
from pydantic import BaseModel, HttpUrl
|
8 |
from App.TTS.Schemas import DescriptTranscript
|
9 |
from pydub import AudioSegment
|
|
|
10 |
|
11 |
|
12 |
class Metadata(BaseModel):
|
@@ -54,6 +55,20 @@ class DescriptTTS:
|
|
54 |
self.refresh_token = refresh_token
|
55 |
self.tau_id = "90f9e0ad-594e-4203-9297-d4c7cc691e5x"
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def concatenate_wave_files(self, input_file_paths):
|
58 |
"""
|
59 |
Concatenates multiple wave files and saves the result to a new file.
|
@@ -162,15 +177,21 @@ class DescriptTTS:
|
|
162 |
random_filename = str(uuid.uuid4()) + ".wav"
|
163 |
file_path = os.path.join(temp_dir, random_filename)
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
# Schedule the file for deletion after 10 minutes
|
176 |
delete_time = datetime.now() + timedelta(minutes=10)
|
@@ -187,8 +208,9 @@ class DescriptTTS:
|
|
187 |
return file_path
|
188 |
|
189 |
def calculate_audio_duration(self, audio_file):
|
190 |
-
|
191 |
-
|
|
|
192 |
return duration_in_seconds
|
193 |
|
194 |
async def search_unsplash_images(self, query_terms):
|
|
|
7 |
from pydantic import BaseModel, HttpUrl
|
8 |
from App.TTS.Schemas import DescriptTranscript
|
9 |
from pydub import AudioSegment
|
10 |
+
import subprocess
|
11 |
|
12 |
|
13 |
class Metadata(BaseModel):
|
|
|
55 |
self.refresh_token = refresh_token
|
56 |
self.tau_id = "90f9e0ad-594e-4203-9297-d4c7cc691e5x"
|
57 |
|
58 |
+
def download_with_wget(self, link, download_dir, filename):
|
59 |
+
headers = [
|
60 |
+
"--header",
|
61 |
+
"Cookie: __Host-session=63EQahvTpHuoFSkEW75hC",
|
62 |
+
"--header",
|
63 |
+
"Cookie: __cf_bm=CDGicP5OErYjDI85UmQSRKlppJLlbcgCXlWcODoIQAI-1716296320-1.0.1.1-4Rm5_wdxupmrDWgddOQjEV01TMFC4UJ479GRIAKKGHNgXu3N8ZkASEZXGwCWaRyUYazsUaLMALk.4frWWJzHQ",
|
64 |
+
]
|
65 |
+
|
66 |
+
# Construct the full command
|
67 |
+
command = ["aria2c"] + headers + [link, "-d", download_dir, "-o", filename]
|
68 |
+
|
69 |
+
# Run the command
|
70 |
+
subprocess.run(command)
|
71 |
+
|
72 |
def concatenate_wave_files(self, input_file_paths):
|
73 |
"""
|
74 |
Concatenates multiple wave files and saves the result to a new file.
|
|
|
177 |
random_filename = str(uuid.uuid4()) + ".wav"
|
178 |
file_path = os.path.join(temp_dir, random_filename)
|
179 |
|
180 |
+
if "https://pi.ai" in access_url:
|
181 |
+
random_filename = str(uuid.uuid4()) + ".mp3"
|
182 |
+
file_path = os.path.join(temp_dir, random_filename)
|
183 |
+
|
184 |
+
self.download_with_wget(download_dir=temp_dir, filename=random_filename)
|
185 |
+
else:
|
186 |
+
async with aiohttp.ClientSession() as session:
|
187 |
+
async with session.get(access_url) as response:
|
188 |
+
if response.status == 200:
|
189 |
+
with open(file_path, "wb") as file:
|
190 |
+
while True:
|
191 |
+
chunk = await response.content.read(1024)
|
192 |
+
if not chunk:
|
193 |
+
break
|
194 |
+
file.write(chunk)
|
195 |
|
196 |
# Schedule the file for deletion after 10 minutes
|
197 |
delete_time = datetime.now() + timedelta(minutes=10)
|
|
|
208 |
return file_path
|
209 |
|
210 |
def calculate_audio_duration(self, audio_file):
|
211 |
+
file_format = audio_file.split(".")[-1]
|
212 |
+
temp_file = AudioSegment.from_file(audio_file, format=file_format)
|
213 |
+
duration_in_seconds = str(float(len(temp_file) / 1000))
|
214 |
return duration_in_seconds
|
215 |
|
216 |
async def search_unsplash_images(self, query_terms):
|
Dockerfile
CHANGED
@@ -9,8 +9,11 @@ RUN chmod 755 /srv
|
|
9 |
|
10 |
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
COPY requirements.txt .
|
15 |
RUN pip install --no-cache-dir -r requirements.txt
|
16 |
|
@@ -20,6 +23,6 @@ USER admin
|
|
20 |
COPY --chown=admin . /srv
|
21 |
|
22 |
# Command to run the application
|
23 |
-
CMD uvicorn App.app:app --host 0.0.0.0 --port 7860 --workers
|
24 |
# Expose the server port
|
25 |
EXPOSE 7860
|
|
|
9 |
|
10 |
|
11 |
|
12 |
+
RUN apt-get update && \
|
13 |
+
apt-get install -y --no-install-recommends \
|
14 |
+
aria2c
|
15 |
|
16 |
+
#copy requirements
|
17 |
COPY requirements.txt .
|
18 |
RUN pip install --no-cache-dir -r requirements.txt
|
19 |
|
|
|
23 |
COPY --chown=admin . /srv
|
24 |
|
25 |
# Command to run the application
|
26 |
+
CMD uvicorn App.app:app --host 0.0.0.0 --port 7860 --workers 4
|
27 |
# Expose the server port
|
28 |
EXPOSE 7860
|