ScrapExplorer - __main__.py

Home / misc / plxkit Lines: 1 | Size: 2573 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1import argparse 2from plxkit.utils import list_devices, get_device_index 3from plxkit.pipe import pipe_audio 4from plxkit.record import record_audio 5 6def main(): 7 parser = argparse.ArgumentParser(description="PLXkit audio utilities") 8 subparsers = parser.add_subparsers(dest="command") 9 10 # List devices 11 subparsers.add_parser("devices", help="List audio devices") 12 13 # Pipe 14 pipe_parser = subparsers.add_parser("pipe", help="Pipe audio input → output") 15 pipe_parser.add_argument("--in", dest="input", required=False, help="Input device name substring") 16 pipe_parser.add_argument("--out", dest="output", required=False, help="Output device name substring") 17 pipe_parser.add_argument("--nin", dest="num_input", type=int, default=1, help="Same as --in but using a index, use the devices command to find the index") 18 pipe_parser.add_argument("--nout", dest="num_output", type=int, default=1, help="Same as --out but using a index, use the devices command to find the index") 19 20 # Record 21 rec_parser = subparsers.add_parser("record", help="Record audio input → file") 22 rec_parser.add_argument("--in", dest="input", required=True, help="Input device name substring") 23 rec_parser.add_argument("--file", default="output.wav", help="Output file name") 24 rec_parser.add_argument("--duration", type=float, help="Duration in seconds (omit for manual stop)") 25 rec_parser.add_argument("--nin", dest="num_input", type=int, default=1, help="Same as --in but using a index, use the devices command to find the index") 26 27 args = parser.parse_args() 28 29 if args.command == "devices": 30 list_devices() 31 elif args.command == "pipe": 32 if args.num_input: 33 in_dev = args.num_input 34 else: 35 in_dev = get_device_index(args.input, is_input=True) 36 if args.num_output: 37 out_dev = args.num_output 38 else: 39 out_dev = get_device_index(args.output, is_input=False) 40 if in_dev is None or out_dev is None: 41 print("Error: Could not find matching input/output devices") 42 return 43 pipe_audio(in_dev, out_dev) 44 elif args.command == "record": 45 if args.num_input: 46 in_dev = args.num_input 47 else: 48 in_dev = get_device_index(args.input, is_input=True) 49 if in_dev is None: 50 print("Error: Could not find matching input device") 51 return 52 53 record_audio(in_dev, filename=args.file, duration=args.duration) 54 else: 55 parser.print_help() 56 57if __name__ == "__main__": 58 main() 59
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.