29 lines
880 B
Python
29 lines
880 B
Python
import os
|
|
from pathlib import Path
|
|
from config import settings
|
|
import asyncio
|
|
|
|
|
|
class TTSAudioCleaner:
|
|
|
|
|
|
@staticmethod
|
|
async def prepare_output_directory():
|
|
|
|
tts_dir = Path(settings.assets_dir) / "tts_audio"
|
|
loop = asyncio.get_running_loop()
|
|
await loop.run_in_executor(None, lambda: os.makedirs(tts_dir, exist_ok=True))
|
|
return tts_dir
|
|
|
|
@staticmethod
|
|
def generate_filename(device_id: str, session_id: str, sequence_number: int):
|
|
seq_str = f"{sequence_number:02d}"
|
|
file_name = f"{device_id}_{session_id}_{seq_str}"
|
|
output_file_prefix = os.path.join(settings.assets_dir, "tts_audio", file_name)
|
|
return output_file_prefix
|
|
|
|
@staticmethod
|
|
def generate_audio_url(audio_file_path: str):
|
|
file_name = os.path.basename(audio_file_path)
|
|
return f"assets/tts_audio/{file_name}"
|