asr.py 1.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3
# Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the LICENSE file in
# the root directory of this source tree. An additional grant of patent rights
# can be found in the PATENTS file in the same directory.
"""
Run inference for pre-processed data with a trained model.
"""

import datetime as dt
import logging

15
from fairseq import options
16
from interactive_asr.utils import add_asr_eval_argument, get_microphone_transcription, setup_asr, transcribe_file
17
18
19


def main(args):
20
21
22
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    task, generator, models, sp, tgt_dict = setup_asr(args, logger)
23

24
    print("READY!")
25
    if args.input_file:
26
        transcription_time, transcription = transcribe_file(args, task, generator, models, sp, tgt_dict)
27
        print("transcription:", transcription)
28
        print("transcription_time:", transcription_time)
29
    else:
30
        for transcription in get_microphone_transcription(args, task, generator, models, sp, tgt_dict):
31
            print("{}: {}".format(dt.datetime.now().strftime("%H:%M:%S"), transcription[0][0]))
32
33
34
35
36
37
38
39
40
41
42


def cli_main():
    parser = options.get_generation_parser()
    parser = add_asr_eval_argument(parser)
    args = options.parse_args_and_arch(parser)
    main(args)


if __name__ == "__main__":
    cli_main()