Descript transcript request file_extenstion
Browse files- App/TTS/Schemas.py +1 -0
- App/TTS/utils/Descript.py +6 -4
App/TTS/Schemas.py
CHANGED
|
@@ -27,6 +27,7 @@ class DescriptSfxRequest(BaseModel):
|
|
| 27 |
class DescriptTranscript(BaseModel):
|
| 28 |
audio_url: List[str]
|
| 29 |
text: str
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
class DescriptRequest(BaseModel):
|
|
|
|
| 27 |
class DescriptTranscript(BaseModel):
|
| 28 |
audio_url: List[str]
|
| 29 |
text: str
|
| 30 |
+
file_extenstion: str = ".wav"
|
| 31 |
|
| 32 |
|
| 33 |
class DescriptRequest(BaseModel):
|
App/TTS/utils/Descript.py
CHANGED
|
@@ -171,17 +171,19 @@ class DescriptTTS:
|
|
| 171 |
f"Failed to load existing refresh token. Status code: {response.status}, Error: {await response.text()}"
|
| 172 |
)
|
| 173 |
|
| 174 |
-
async def download_and_store_file(self, access_url):
|
| 175 |
temp_dir = tempfile.mkdtemp()
|
| 176 |
# Generate a unique random filename
|
| 177 |
-
random_filename = str(uuid.uuid4()) +
|
| 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(
|
|
|
|
|
|
|
| 185 |
else:
|
| 186 |
async with aiohttp.ClientSession() as session:
|
| 187 |
async with session.get(access_url) as response:
|
|
@@ -385,7 +387,7 @@ class DescriptTTS:
|
|
| 385 |
audio_paths = []
|
| 386 |
audio_path = ""
|
| 387 |
for url in query.audio_url:
|
| 388 |
-
audio_paths.append(self.download_and_store_file(url))
|
| 389 |
audio_paths = await asyncio.gather(*audio_paths)
|
| 390 |
audio_path = self.concatenate_wave_files(audio_paths)
|
| 391 |
data.add_field("audio", open(audio_path, "rb"))
|
|
|
|
| 171 |
f"Failed to load existing refresh token. Status code: {response.status}, Error: {await response.text()}"
|
| 172 |
)
|
| 173 |
|
| 174 |
+
async def download_and_store_file(self, access_url, file_extension=".wav"):
|
| 175 |
temp_dir = tempfile.mkdtemp()
|
| 176 |
# Generate a unique random filename
|
| 177 |
+
random_filename = str(uuid.uuid4()) + file_extension
|
| 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(
|
| 185 |
+
link=access_url, download_dir=temp_dir, filename=random_filename
|
| 186 |
+
)
|
| 187 |
else:
|
| 188 |
async with aiohttp.ClientSession() as session:
|
| 189 |
async with session.get(access_url) as response:
|
|
|
|
| 387 |
audio_paths = []
|
| 388 |
audio_path = ""
|
| 389 |
for url in query.audio_url:
|
| 390 |
+
audio_paths.append(self.download_and_store_file(url, query.file_extenstion))
|
| 391 |
audio_paths = await asyncio.gather(*audio_paths)
|
| 392 |
audio_path = self.concatenate_wave_files(audio_paths)
|
| 393 |
data.add_field("audio", open(audio_path, "rb"))
|