Ejemplo n.º 1
0
def main():
    import argparse
    global model, spect_parser, decoder, args, device
    parser = argparse.ArgumentParser(
        description='DeepSpeech transcription server')
    parser.add_argument('--host',
                        type=str,
                        default='0.0.0.0',
                        help='Host to be used by the server')
    parser.add_argument('--port',
                        type=int,
                        default=8888,
                        help='Port to be used by the server')
    parser = add_inference_args(parser)
    parser = add_decoder_args(parser)
    args = parser.parse_args()
    logging.getLogger().setLevel(logging.DEBUG)

    logging.info('Setting up server...')
    torch.set_grad_enabled(False)
    device = torch.device("cuda" if args.cuda else "cpu")
    model = load_model(device, args.model_path, args.half)

    if args.decoder == "beam":
        from deepspeech_pytorch.decoder import BeamCTCDecoder

        decoder = BeamCTCDecoder(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,
                                 num_processes=args.lm_workers)
    else:
        decoder = GreedyDecoder(model.labels,
                                blank_index=model.labels.index('_'))

    spect_parser = SpectrogramParser(model.audio_conf, normalize=True)
    logging.info('Server initialised')
    app.run(host=args.host, port=args.port, debug=True, use_reloader=False)
Ejemplo n.º 2
0
import argparse
import json

import torch

from deepspeech_pytorch.decoder import GreedyDecoder
from deepspeech_pytorch.loader.data_loader import SpectrogramDataset, AudioDataLoader
from deepspeech_pytorch.opts import add_decoder_args, add_inference_args
from deepspeech_pytorch.testing import evaluate
from deepspeech_pytorch.utils import load_model, load_decoder

parser = argparse.ArgumentParser(description='DeepSpeech transcription')
parser = add_inference_args(parser)
parser.add_argument('--test-manifest',
                    metavar='DIR',
                    help='path to validation manifest csv',
                    default='data/test_manifest.csv')
parser.add_argument('--batch-size',
                    default=5,
                    type=int,
                    help='Batch size for testing')
parser.add_argument('--num-workers',
                    default=8,
                    type=int,
                    help='Number of workers used in dataloading')
parser.add_argument('--verbose',
                    action="store_true",
                    help="print out decoded output and error of each sample")
parser.add_argument('--save-output',
                    default=None,
                    help="Saves output of model from test to this file_path")
Ejemplo n.º 3
0
        spect_parser=spect_parser,
        model=model,
        decoder=decoder,
        device=device,
        use_half=args.half)

    transcription = decode_results(
        decoded_output, decoded_offsets)["output"][0]["transcription"]

    print(transcription)


if __name__ == "__main__":
    arg_parser = argparse.ArgumentParser(
        description='DeepSpeech transcription')
    arg_parser = add_inference_args(arg_parser)
    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,