Ejemplo n.º 1
0
    def inference(self,
                  test_path: str,
                  model_path: str,
                  cuda: bool,
                  precision: int,
                  lm_config: LMConfig):
        # Select one file from our test manifest to run inference
        if os.path.isdir(test_path):
            file_path = next(Path(test_path).rglob('*.wav'))
        else:
            with open(test_path) as f:
                # select a file to use for inference test
                manifest = json.load(f)
                file_name = manifest['samples'][0]['wav_path']
                directory = manifest['root_path']
                file_path = os.path.join(directory, file_name)

        transcribe_cfg = TranscribeConfig(
            model=ModelConfig(
                cuda=cuda,
                model_path=model_path,
                precision=precision
            ),
            lm=lm_config,
            audio_path=file_path
        )
        transcribe(transcribe_cfg)
Ejemplo n.º 2
0
    def inference(self, test_manifest: str, model_path: str, cuda: bool,
                  use_half: bool, lm_config: LMConfig):
        # Select one file from our test manifest to run inference
        with open(test_manifest) as f:
            file_path = next(f).strip().split(',')[0]

        transcribe_cfg = TranscribeConfig(model=ModelConfig(
            cuda=cuda, model_path=model_path, use_half=use_half),
                                          lm=lm_config,
                                          audio_path=file_path)
        transcribe(transcribe_cfg)
Ejemplo n.º 3
0
def hydra_main(cfg: TranscribeConfig):
    transcribe(cfg=cfg)
Ejemplo n.º 4
0
def hydra_main(cfg: TranscribeConfig):
    transcript, meta = transcribe(cfg=cfg)

    print("\n Output transcript : \033[94m", transcript, "\033[0m")
Ejemplo n.º 5
0
def hydra_main(cfg: TranscribeConfig):
    transcript, transcribeGreedy, meta = transcribe(cfg=cfg)

    print("\n Output transcript with LM     : \033[94m", transcript, "\033[0m")
    print("\n Output transcript with greedy : \033[94m", transcribeGreedy,
          "\033[0m")
Ejemplo n.º 6
0
                            help='Audio file to predict on')
    arg_parser.add_argument('--offsets',
                            dest='offsets',
                            action='store_true',
                            help='Returns time offset information')
    arg_parser = add_decoder_args(arg_parser)
    args = arg_parser.parse_args()
    device = torch.device("cuda" if args.cuda else "cpu")
    model = load_model(device, args.model_path, args.half)

    decoder = load_decoder(decoder_type=args.decoder,
                           labels=model.labels,
                           lm_path=args.lm_path,
                           alpha=args.alpha,
                           beta=args.beta,
                           cutoff_top_n=args.cutoff_top_n,
                           cutoff_prob=args.cutoff_prob,
                           beam_width=args.beam_width,
                           lm_workers=args.lm_workers)

    spect_parser = SpectrogramParser(audio_conf=model.audio_conf,
                                     normalize=True)

    decoded_output, decoded_offsets = transcribe(audio_path=args.audio_path,
                                                 spect_parser=spect_parser,
                                                 model=model,
                                                 decoder=decoder,
                                                 device=device,
                                                 use_half=args.half)
    print(json.dumps(decode_results(decoded_output, decoded_offsets)))