i'm trying to use this python script to compare sound but i can't find where to upload them ''source file'' and ''target file''

Viewed 18

i'm new to python and to programming in general, i just need to compare 2 sound files and this script seems to do it but i can't figure out how to upload my .WAV files to this script so please help me

#!/usr/bin/python3
# compare.py
import argparse
from correlation import correlate

def initialize():
    parser = argparse.ArgumentParser()
    parser.add_argument("-i ", "--source-file", help="source file")
    parser.add_argument("-o ", "--target-file", help="target file")
    args = parser.parse_args()
  
    SOURCE_FILE = args.source_file if args.source_file else None
    TARGET_FILE = args.target_file if args.target_file else None
    if not SOURCE_FILE or not TARGET_FILE:
      raise Exception("Source or Target files not specified.")
    return SOURCE_FILE, TARGET_FILE
  
if __name__ == "__main__":
    SOURCE_FILE, TARGET_FILE = initialize()
    correlate(SOURCE_FILE, TARGET_FILE)
1 Answers

This looks like a program that can be run from the command line. Assuming you already have python3 installed, you can launch it as

python compare.py -h

and it will print a help message on how to use it. (This requires you to first navigate to the directory that contains the compare.py file you showed us. That is done with the cd command)

If you place your two sound files in the same directory as the compare.py, you can simply specify their names:

python compare.py -i sourcefile.wav -o targetfile.wav

If the files are not in the same folder, you should write the full path of the files instead.


Minor Remark regarding Terminology: I wouldn't call it uploading the files to the script. You keep everything local on your computer, nothing is being uploaded. You are trying to specify the files as command line arguments to the python script.

Related