edit below
I am getting the error FileNotFoundError: [WinError 2] The system cannot find the file specified
. I am using backslashes (used to escape characters) in the strings but they are not returning a unicode error so I am assuming that is not that problem (I've also tried changing the direction of the slashes). Here is the code with comments:
# I can use cd .\wav to get into the folder from where I am running the file
source_filepath = ".\wav" # I've tried changing to '/' and using the absolute path
target_filepath = ".\spect" # I've tried changing to '/' and using the absolute path
STEP_SIZE = 1.5
for filename in os.listdir(source_filepath):
id, ext = filename.split(".")
print(os.path.join(source_filepath, filename)) # prints ".\wav\UNIT1_20210501_042900.wav" for example
print(os.path.exists(os.path.join(source_filepath, filename))) # prints "True", it exists
print(os.path.isfile(os.path.join(source_filepath, filename))) # prints "True", it is a file
if ext == "wav":
sox_call = subprocess.run(['sox', '-D',
os.path.join(source_filepath, filename)],
stdout=subprocess.PIPE) # fails
duration = int(float(sox_call.stdout))
Here is the traceback:
Traceback (most recent call last):
File "C:\Users\Helana\Documents\projects\plan-b\extract-clips-and-create-spectrograms.py", line 18, in <module>
sox_call = subprocess.run(['sox', '-D',
File "C:\Users\Helana\anaconda3\lib\subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Helana\anaconda3\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Helana\anaconda3\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
The point of the file is to slice a wav file into pieces and turn each piece into a spectogram and store those spectograms in the "spect" folder. There is more code after this block but it's what I'm getting an error from, do let me know if more code needs to be shown. I am also on Windows 11, not sure if that could cause problems. Sox was installed via pip.
Edit:
Figured out sox was the problem, downloaded the right one from https://sourceforge.net/projects/sox/. Add to my PATH like:
Variable: sox Value: C:\Program Files (x86)\sox-14-4-2\
Based on the question here: How to use sox in windows
Still getting the same error as above when running my file, and running sox
in Powershell gives error:
sox : The term 'sox' is not recognized as the name of a cmdlet, function, script file, or operable program.