Download audio_processing.py from TDN-M/GV-a: direct link, hf CLI and curl.
- Browser
- Download file 624 Bytes
-
https://huggingface.co/spaces/TDN-M/GV-a/resolve/main/audio_processing.py
- Command line
-
hf download hf://spaces/TDN-M/GV-a/audio_processing.py
-
curl -L -o audio_processing.py https://huggingface.co/spaces/TDN-M/GV-a/resolve/main/audio_processing.py
624 Bytes
| # 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) |