伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
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.

aques.py 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from ctypes import *
  2. class Aques:
  3. @classmethod
  4. def main (cls, text: str) -> bytearray | None:
  5. return cls.__synthe_utf8 (text, speed = 100)
  6. @staticmethod
  7. def __synthe_utf8 (text, speed, phont_file = None) -> bytearray | None:
  8. if phont_file is None:
  9. phont = None
  10. else:
  11. with open (phont_file, 'rb') as f:
  12. phont = f.read ()
  13. aqkoe = cdll.LoadLibrary ('libAqKanji2Koe.so')
  14. dic_path: str = './aq_dic'
  15. err = c_int (0)
  16. aqkoe.AqKanji2Koe_Create.restype = c_void_p
  17. handle = aqkoe.AqKanji2Koe_Create (dic_path, byref (err))
  18. koe: str = ''
  19. aqkoe.AqKanji2Koe_Convert.restype = c_int
  20. aqkoe.AqKanji2Koe_Convert (handle, text.encode ('utf-8'), koe, 4096)
  21. aqtk = cdll.LoadLibrary ('libAquesTalk2Eva.so')
  22. aqtk.AquesTalk2_Synthe_Utf8.restype = POINTER (ARRAY (c_ubyte, 0))
  23. size = c_int (0)
  24. wav_p = aqtk.AquesTalk2_Synthe_Utf8 (koe.encode ('utf-8'), speed,
  25. byref (size), phont)
  26. if not bool (wav_p):
  27. return None
  28. wav_p = cast (wav_p, POINTER (ARRAY (c_ubyte, size.value)))
  29. wav = bytearray (wav_p.contents)
  30. aqtk.AquuesTalk2_FreeWave (wav_p)
  31. return wav