You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 ay önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import time
  2. import edge_tts
  3. import asyncio
  4. from bridge.reply import Reply, ReplyType
  5. from common.log import logger
  6. from common.tmp_dir import TmpDir
  7. from voice.voice import Voice
  8. class EdgeVoice(Voice):
  9. def __init__(self):
  10. '''
  11. # 普通话
  12. zh-CN-XiaoxiaoNeural
  13. zh-CN-XiaoyiNeural
  14. zh-CN-YunjianNeural
  15. zh-CN-YunxiNeural
  16. zh-CN-YunxiaNeural
  17. zh-CN-YunyangNeural
  18. # 地方口音
  19. zh-CN-liaoning-XiaobeiNeural
  20. zh-CN-shaanxi-XiaoniNeural
  21. # 粤语
  22. zh-HK-HiuGaaiNeural
  23. zh-HK-HiuMaanNeural
  24. zh-HK-WanLungNeural
  25. # 湾湾腔
  26. zh-TW-HsiaoChenNeural
  27. zh-TW-HsiaoYuNeural
  28. zh-TW-YunJheNeural
  29. '''
  30. self.voice = "zh-CN-YunjianNeural"
  31. def voiceToText(self, voice_file):
  32. pass
  33. async def gen_voice(self, text, fileName):
  34. communicate = edge_tts.Communicate(text, self.voice)
  35. await communicate.save(fileName)
  36. def textToVoice(self, text):
  37. fileName = TmpDir().path() + "reply-" + str(int(time.time())) + "-" + str(hash(text) & 0x7FFFFFFF) + ".mp3"
  38. asyncio.run(self.gen_voice(text, fileName))
  39. logger.info("[EdgeTTS] textToVoice text={} voice file name={}".format(text, fileName))
  40. return Reply(ReplyType.VOICE, fileName)