1""" 2/* Copyright (c) 2023 Amazon 3 Written by Jan Buethe */ 4/* 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 9 - Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*/ 28""" 29 30import argparse 31import os 32 33import yaml 34 35 36from utils.templates import dataset_template_v1, dataset_template_v2 37 38 39 40 41parser = argparse.ArgumentParser("add_dataset_config.py") 42 43parser.add_argument('path', type=str, help='path to folder containing feature and data file') 44parser.add_argument('--version', type=int, help="dataset version, 1 for classic LPCNet with 55 feature slots, 2 for new format with 36 feature slots.", default=2) 45parser.add_argument('--description', type=str, help='brief dataset description', default="I will add a description later") 46args = parser.parse_args() 47 48 49if args.version == 1: 50 template = dataset_template_v1 51 data_extension = '.u8' 52elif args.version == 2: 53 template = dataset_template_v2 54 data_extension = '.s16' 55else: 56 raise ValueError(f"unknown dataset version {args.version}") 57 58# get folder content 59content = os.listdir(args.path) 60 61features = [c for c in content if c.endswith('.f32')] 62 63if len(features) != 1: 64 print("could not determine feature file") 65else: 66 template['feature_file'] = features[0] 67 68data = [c for c in content if c.endswith(data_extension)] 69if len(data) != 1: 70 print("could not determine data file") 71else: 72 template['signal_file'] = data[0] 73 74template['description'] = args.description 75 76with open(os.path.join(args.path, 'info.yml'), 'w') as f: 77 yaml.dump(template, f) 78