伊地知ニジカ放送局だぬ゛ん゛. 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.

38 lines
1.3 KiB

  1. import subprocess
  2. from ctypes import ARRAY # type: ignore
  3. from ctypes import POINTER, byref, c_int, c_ubyte, cast, cdll
  4. class Aques:
  5. @classmethod
  6. def main (cls, text: str, goatoh_mode: bool = False) -> bytearray | None:
  7. return cls.__synthe_utf8 (text, 100, './phont/ar_m5.phont' if goatoh_mode else './phont/ar_mf2.phont')
  8. @staticmethod
  9. def __synthe_utf8 (text, speed, phont_file = None) -> bytearray | None:
  10. if phont_file is None:
  11. phont = None
  12. else:
  13. with open (phont_file, 'rb') as f:
  14. phont = f.read ()
  15. p = subprocess.Popen ('./aques', stdin = subprocess.PIPE,
  16. stdout = subprocess.PIPE)
  17. koe: str = p.communicate (text.encode ())[0].decode ()
  18. aqtk = cdll.LoadLibrary ('libAquesTalk2Eva.so')
  19. aqtk.AquesTalk2_Synthe_Utf8.restype = POINTER (ARRAY (c_ubyte, 0))
  20. size = c_int (0)
  21. wav_p = aqtk.AquesTalk2_Synthe_Utf8 (koe.encode ('utf-8'), speed,
  22. byref (size), phont)
  23. if not bool (wav_p):
  24. return None
  25. wav_p = cast (wav_p, POINTER (ARRAY (c_ubyte, size.value)))
  26. wav = bytearray (wav_p.contents)
  27. aqtk.AquesTalk2_FreeWave (wav_p)
  28. return wav