from email.mime import audio
import tensorrt as trt
import pycuda.autoinit
import pycuda.driver as cuda
import pycuda
import numpy as np
import time
import argparse
import os.path as path
# import tensorflow as tf
import ctypes
import sys
import os
import time
import copy
from pathlib import Path
from scipy.io.wavfile import write
import pprint

def my_callback(my_str):
    print(">> calling callback : {}".format(my_str))

from concurrent.futures.thread import ThreadPoolExecutor
_tps = ThreadPoolExecutor(1)
_tts = None
if __name__ == "__main__":
    text = 'This'
    def calling(text):
      try:
        global _tts
        if _tts == None:
            print("initializing tts class...")
            from thread_toy_for_enc import NEW_TTS_SYNTH as TTS_SYNTH
            _tts = TTS_SYNTH()
        _tts.synth(my_callback)
        print("{} has been called suscessfully!".format(text))
      except Exception as e:
        print('error : ', text, e)
        _tts.destroy()
        del _tts
    for i in range(30):
        _tps.submit(calling, i)
        #calling(i)
    _tts.destroy()
    del _tts


