| # audio_processing.py | |
| import asyncio | |
| import os | |
| import tempfile | |
| import edge_tts | |
| def text_to_speech(text, voice): | |
| """ | |
| Chuyển đổi văn bản thành giọng nói bằng edge-tts. | |
| """ | |
| output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") | |
| tts = edge_tts.Communicate(text, voice) | |
| tts.save(output_file.name).get() | |
| return output_file.name | |
| async def async_text_to_speech(text, voice): | |
| """ | |
| Chuyển đổi văn bản thành giọng nói (bất đồng bộ). | |
| """ | |
| loop = asyncio.get_event_loop() | |
| return await loop.run_in_executor(text_to_speech, text, voice) |