From ff392ea999104312e21350a4a76f897b5cc757a3 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 2 Dec 2023 18:04:48 +0900 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E5=A3=B0=E5=90=88=E6=88=90=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aques.py | 31 +++++++++++++++++++++++++++++++ main.py | 9 ++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 aques.py diff --git a/aques.py b/aques.py new file mode 100644 index 0000000..bfd2baa --- /dev/null +++ b/aques.py @@ -0,0 +1,31 @@ +from ctypes import * + + +class Aques: + @classmethod + def main (cls, text: str) -> bytearray | None: + return cls.__synthe_utf8 (text, speed = 100) + + @staticmethod + def __synthe_utf8 (text, speed, phont_file = None) -> bytearray | None: + if phont_file is None: + phont = None + else: + with open (phont_file, 'rb') as f: + phont = f.read () + + aqtk = cdll.LoadLibrary ('libAquesTalk2Eva.so') + aqtk.AquesTalk2_Synthe_Utf8.restype = POINTER (ARRAY (c_ubyte, 0)) + size = c_int (0) + wav_p = aqtk.AquesTalk2_Synthe_Utf8 (text.encode ('utf-8'), speed, + byref (size), phont) + + if not bool (wav_p): + return None + + wav_p = cast (wav_p, POINTER (ARRAY (c_ubyte, size.value))) + wav = bytearray (wav_p.contents) + aqtk.AquuesTalk2_FreeWave (wav_p) + + return wav + diff --git a/main.py b/main.py index 25d4d8f..e4ce5e7 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,8 @@ import time import random from talk import Talk import subprocess +from aques import Aques +from playsound import playsound YOUTUBE_ID: str = 'aq3QwuYz-KU' @@ -47,7 +49,12 @@ class Main: noon.play () - # subprocess.run (r'wine .\') + wav: bytearray | None = Aques.main (answer) + if wav is not None: + with open ('./nizika_talking.wav', 'wb') as f: + f.write (wav) + + playsound ('./nizika_talking.wav') time.sleep (10)