asr.py 1.38 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
18
19
20
21
from interactive_asr.utils import (
    add_asr_eval_argument,
    get_microphone_transcription,
    setup_asr,
    transcribe_file,
)
22
23
24


def main(args):
25
26
27
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    task, generator, models, sp, tgt_dict = setup_asr(args, logger)
28

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


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