@@ -33,6 +33,14 @@ def _load_lib():
3333 _lib .tts_speak_sync .argtypes = [ctypes .c_void_p , ctypes .c_char_p ]
3434 _lib .tts_stop .restype = None
3535 _lib .tts_stop .argtypes = [ctypes .c_void_p ]
36+ _lib .tts_pause .restype = None
37+ _lib .tts_pause .argtypes = [ctypes .c_void_p ]
38+ _lib .tts_resume .restype = None
39+ _lib .tts_resume .argtypes = [ctypes .c_void_p ]
40+ _lib .tts_synth_to_bytes .restype = ctypes .c_int32
41+ _lib .tts_synth_to_bytes .argtypes = [ctypes .c_void_p , ctypes .c_char_p , ctypes .POINTER (ctypes .POINTER (ctypes .c_uint8 )), ctypes .POINTER (ctypes .c_size_t )]
42+ _lib .tts_free_bytes .restype = None
43+ _lib .tts_free_bytes .argtypes = [ctypes .POINTER (ctypes .c_uint8 ), ctypes .c_size_t ]
3644 _lib .tts_set_voice .restype = None
3745 _lib .tts_set_voice .argtypes = [ctypes .c_void_p , ctypes .c_char_p ]
3846 _lib .tts_set_rate .restype = None
@@ -102,6 +110,23 @@ def speak_sync(self, text: str) -> None:
102110 def stop (self ) -> None :
103111 self ._lib .tts_stop (self ._ctx )
104112
113+ def pause (self ) -> None :
114+ self ._lib .tts_pause (self ._ctx )
115+
116+ def resume (self ) -> None :
117+ self ._lib .tts_resume (self ._ctx )
118+
119+ def synth_to_bytes (self , text : str ) -> bytes :
120+ buf = ctypes .POINTER (ctypes .c_uint8 )()
121+ length = ctypes .c_size_t ()
122+ result = self ._lib .tts_synth_to_bytes (self ._ctx , text .encode (), ctypes .byref (buf ), ctypes .byref (length ))
123+ if result != 0 :
124+ raise RuntimeError ("Synthesis to bytes failed" )
125+ data = ctypes .string_at (buf , length .value ) if buf and length .value > 0 else b""
126+ if buf :
127+ self ._lib .tts_free_bytes (buf , length .value )
128+ return data
129+
105130 def set_voice (self , voice_id : str ) -> None :
106131 self ._lib .tts_set_voice (self ._ctx , voice_id .encode ())
107132
0 commit comments