asr.py 1.43 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

17
from interactive_asr.utils import add_asr_eval_argument, setup_asr, get_microphone_transcription, transcribe_file
18
19
20


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

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


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()