示例#1
0
    def __init__(self, q, pcm_stream_state):
        threading.Thread.__init__(self)
        self.threadID = confvars.G_SRT_WRITER_THREAD_ID
        self.name = confvars.G_SRT_WRITER_THREAD_NAME

        self.q = q
        self.pcm_stream_state = pcm_stream_state
        self.verbose_mode = confvars.G_VERBOSE
        self.logger = amg_logger.amagi_logger(
            "com.amagi.stt.SRTWriter",
            amg_logger.LOG_INFO,
            log_stream=confvars.G_LOGGER_STREAM)
        if confvars.G_OFLAGS_APPEND_MODE:
            self.open_mode = "a"
        else:
            self.open_mode = "w"
        if confvars.G_OFLAGS_APPEND_NULL_CHAR:
            self.null_char = "\0"
        else:
            self.null_char = ""
        self.last_rcvd_epoch = 0
        self.srt_count = 0
        self.srt_fname = confvars.G_OUTPUT_SRT_PATH
        self.last_srt_sub = []  #[tcin,tcout,text]
        self.last_consumed_pts = 0

        self.first_response_time = 0
        self.words_list = [
        ]  #[ (word, epoch_time_rcvd_at, is consumed, timestamp), ()... ]
示例#2
0
    def __init__(self, threadID, name, q,srt_fname, append_mode, \
            append_null_char, dump_gcp_response = ""):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.q = q
        self.exit_flag = False
        self.dump_gcp_response = dump_gcp_response
        self.logger = amg_logger.amagi_logger ("com.amagi.stt.resp_to_srt", amg_logger.LOG_INFO, log_stream=stt_globals.G_LOGGER_STREAM)
        if append_mode:
            self.open_mode = "a"
        else:
            self.open_mode = "w"
        if append_null_char:
            self.null_char = "\0"
        else:
            self.null_char = ""
        self.last_rcvd_epoch = 0
        self.srt_count = 0
        self.srt_fname = srt_fname
        self.last_srt_sub = []#[tcin,tcout,text]
        self.last_consumed_pts = 0

        self.first_response_time = 0
        self.words_list = []#[ (word, epoch_time_rcvd_at, is consumed, timestamp), ()... ]
示例#3
0
 def __init__(self, q, pcm_stream_state):
     self.q = q
     self.pcm_stream_state = pcm_stream_state
     self.logger = logr.amagi_logger("com.amagi.stt.PCMGenerator",
                                     logr.LOG_INFO,
                                     log_stream=confvars.G_LOGGER_STREAM)
     self.logger.info("PCMGenerator initialized")
示例#4
0
def dump_config_vars():

    logger = amg_logger.amagi_logger("com.amagi.stt.globals",
                                     amg_logger.LOG_INFO, amg_logger.LOG_USER,
                                     G_LOGGER_STREAM)

    for key, value in globals().items():
        if (key.startswith("G_")):
            logger.info(f"{key} = {value}")
示例#5
0
 def __init__ (self, inp_file, G_CHUNK_SIZE_BYTES, q, exit_on_zero_size):
     threading.Thread.__init__(self)
     self.fname = inp_file
     self.fp = open (self.fname, mode="rb")
     self.chunk = G_CHUNK_SIZE_BYTES 
     self.exit_flag = False
     self.q = q
     self.last_log_time = time.time()
     self.data_read = 0
     self.logger = amg_logger.amagi_logger ("com.amagi.stt.readgen", amg_logger.LOG_INFO, log_stream=stt_globals.G_LOGGER_STREAM)
    def __init__(self, q):
        threading.Thread.__init__(self)
        self.threadID = confvars.G_PACKPCM_READER_THREAD_ID
        self.name = confvars.G_PACKPCM_READER_THREAD_NAME

        self.fname = confvars.G_INPUT_AUDIO_PATH
        self.fp = open(self.fname, mode="rb")
        self.chunk = confvars.G_CHUNK_SIZE_BYTES
        self.q = q
        self.last_log_time = time.time()
        self.data_read = 0
        self.logger = logr.amagi_logger("com.amagi.stt.PacketizedPCMReader",
                                        logr.LOG_INFO,
                                        log_stream=confvars.G_LOGGER_STREAM)
示例#7
0
 def __init__(self):
     self.stream_time = get_current_time()
     self.restart_counter = 0
     self._consumed_ms = 0
     self.last_iter_consumed_ms = 0
     self.max_sent_audio_q_len = 500 / confvars.G_CHUNK_MS
     self.sent_audio_q = queue.Queue()
     self.sent_q_head_pts = 0
     self._last_sub_pts = 0
     self.old_data_sent_ms = 0
     self.audio_pts_map = OrderedDict()  # 0_pts:actual:pts
     self.audio_pts_map_lock = threading.Lock()
     self.logger = logr.amagi_logger("com.amagi.stt.PCMStreamState",
                                     logr.LOG_INFO,
                                     log_stream=confvars.G_LOGGER_STREAM)
示例#8
0
 def __init__ (self, q, stream):
     self.q = q
     self.exit_flag = False
     self.stream = stream
     self.logger = amg_logger.amagi_logger ("com.amagi.stt.GeneratorClass", amg_logger.LOG_INFO, log_stream=stt_globals.G_LOGGER_STREAM)
示例#9
0
        (dump_def_config, cp) = args.gen_config_from_cmdargs(sys.argv[1:])

        if (dump_def_config):
            comn.eprint(defconf.stt_default_config_str)
            os._exit(0)

        confvars.config_ini_2_vars(cp)

        if (confvars.G_VERBOSE):
            confvars.dump_config_vars()

        if (confvars.G_NO_RUN):
            os._exit(0)

        glbl.main_logger = logr.amagi_logger(
            "com.amagi.stt.main",
            logr.LOG_INFO,
            log_stream=confvars.G_LOGGER_STREAM)

        transcriber = Transcriber()
        transcriber.run()

        glbl.main_logger.info("### Ending transcribe normally")

    except Exception as e:
        #except google.auth.exceptions.DefaultCredentialsError:
        #except FileNotFoundError:

        if (glbl.main_logger != None):
            glbl.main_logger.error(traceback.format_exc())
        if (transcriber != None):
            transcriber.terminate()
示例#10
0
def gen_config_from_cmdargs(argv):
    """
        returns either (dump_def_config=True,  ConfigParser=None)
                or     (dump_def_config=False, ConfigParser=...)

        the ConfigParser object contains 
            * the default configuration
            * overridden by the optional specified configuration and 
            * finally overridden by the optional command line arguments

        the expected behaviour of the caller should be as follows:

        if (dump_def_config == true):
            # dump default config on stderr
            # exit

        use the ConfigParser object to run the program
    """

    cmdargs_parser = argparse.ArgumentParser()

    #+--------------------------------------------------+
    #| Step 1: populate the argument parser with values |
    #|         from default configuration               |
    #+--------------------------------------------------+

    # use default configuration parser to set default cmdarg values
    set_default_cmdarg_values(cmdargs_parser)

    #+--------------------------------------+
    #| Step 2: parse command line arguments |
    #+--------------------------------------+

    cmdargs = cmdargs_parser.parse_args(argv)

    if (cmdargs.dump_def_config):
        return (True, None)

    #+-----------------------------------------------+
    #| Step 2: create the desired configuration with |
    #|         command line overrides                |
    #+-----------------------------------------------+

    cp = None

    if (len(cmdargs.config_path) > 0):
        if (not os.path.isfile(cmdargs.config_path)):
            stt_commons.eprint(
                f"configuration file {cmdargs.config_path} not found")
            raise FileNotFoundError(
                    errno.ENOENT, \
                    os.strerror(errno.ENOENT), \
                    cmdargs.config_path)

        # read the configuration with defaults supplied from
        # default configuration
        cp = stt_config_fnxs.generate_with_defaults(cmdargs.config_path,
                                                    cmdargs.verbose)

        if (cmdargs.verbose):
            stt_commons.eprint(
                f"using config from {cmdargs.config_path} with defaults")

    else:

        # use the default configuration
        cp = stt_config_fnxs.DefaultSttConfig().get_config_parser()

        if (cmdargs.verbose):
            stt_commons.eprint(f"using default config")

    #+----------------------------------------------------------------+
    #| Step 4: override the configuration values with those specified |
    #|         in command line and dump final configuration           |
    #+----------------------------------------------------------------+

    set_cmdarg_values_in_config(cp, cmdargs)

    logger = amg_logger.amagi_logger("com.amagi.stt.cmdargs",
                                     amg_logger.LOG_INFO, amg_logger.LOG_USER,
                                     cp.get("LOGGING", "logger_stream"))

    if (cp.getboolean("LOGGING", "verbose")):
        dump_cmdarg_values(cmdargs, logger)

    if (cp.getboolean("LOGGING", "verbose")):
        logger.info(f"final configuration is as follows:")
        f_str = io.StringIO()
        cp.write(f_str)
        f_str.seek(0)
        logger.info(f_str.read())
        f_str.close()

    return (False, cp)