Spaces:
Sleeping
Sleeping
| # app/services/audio_service.py | |
| from gtts import gTTS | |
| import os, uuid, logging | |
| logger = logging.getLogger(__name__) | |
| def generate_audio_file(text: str, language: str = "en") -> str: | |
| """Generate an MP3 file in Hugging Face writable /tmp directory.""" | |
| try: | |
| os.makedirs("/tmp", exist_ok=True) | |
| file_path = os.path.join("/tmp", f"audio_{uuid.uuid4().hex}.mp3") | |
| tts = gTTS(text=text, lang=language, slow=False) | |
| tts.save(file_path) | |
| logger.info(f"Generated Audio: {file_path}") | |
| return file_path | |
| except Exception as e: | |
| logger.error(f"Audio Generation Failed: {str(e)}") | |
| raise | |