1 Star 0 Fork 0

HappyDog/egg-tts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
threadenglish.py 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
import os
import asyncio
import threading
import edge_tts
from translator import BaiduTranslator
mp3_folder = 'engtohanmp3'
voice = 'zh-CN-YunxiNeural'
async def text_to_speech(text, filename):
tts = edge_tts.Communicate(text=text, voice=voice)
await tts.save(os.path.join(mp3_folder, filename + '.mp3'))
def translate_text(text):
translator = BaiduTranslator()
translation = translator.translate(text, 'zh')
return translation
def main():
# Check if MP3 folder exists, if not create it
if not os.path.exists(mp3_folder):
os.mkdir(mp3_folder)
loop = asyncio.get_event_loop()
files = os.listdir('engtohan/')
threads = []
for i, file in enumerate(files):
filename = str(i + 1)
with open(os.path.join('engtohan/', file), encoding='utf-8') as f:
text = f.read()
translated = translate_text(text)
thread = threading.Thread(target=asyncio.run,
args=(text_to_speech(translated, filename),))
threads.append(thread)
thread.start()
# Join all threads
for thread in threads:
thread.join()
# Close event loop
loop.close()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HappyDogs/egg-tts.git
git@gitee.com:HappyDogs/egg-tts.git
HappyDogs
egg-tts
egg-tts
master

搜索帮助