0

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.
Helana Brock
  • 45
  • 15
  • 4
    It's not about the files. It can't find `sox`. Where is that located? Is it on your path? – Tim Roberts Nov 19 '22 at 00:08
  • 4
    Is `sox` on your PATH? If you open a terminal and type `sox`, what does it say? – Carcigenicate Nov 19 '22 at 00:08
  • @TimRoberts and @ Carcigenicate ok that is good to know I am not going crazy if it is sox. It is not on my path and it is not recognized in the powershell. I am always confused on how to add to my path. I would name it "sox" with a path to the pip installation? I can try to figure it out on my own and come back – Helana Brock Nov 19 '22 at 00:11
  • @HelanaBrock Find where pip installed it, and add that location to the PATH. Or use an absolute path to that location in your code. – Carcigenicate Nov 19 '22 at 00:14
  • @HelanaBrock pretty sure the thing you installed with pip is just a wrapper around another program called `sox`, which is not installed or otherwise not available in the path. IOW, the pip installation is for a Python program, which is not actually sox – juanpa.arrivillaga Nov 19 '22 at 00:19
  • @Carcigenicate don't think that's what's going on here – juanpa.arrivillaga Nov 19 '22 at 00:19
  • Yeah, pretty sure that Python library just assumes there is a `sox` in the path: https://github.com/rabitt/pysox/blob/0a428b88f76c41e93eecbf49bb27b97c7b3f9de7/sox/core.py#L59 so you actually have to install `sox`, not `pysox`. – juanpa.arrivillaga Nov 19 '22 at 00:21
  • @juanpa.arrivillaga hm, looking at the info via pip show, it does look a little wrong. Not to mention it is in c:\users\helana\anaconda3\lib\site-packages, not Program Files (x86). Trying to follow instructions here: https://stackoverflow.com/questions/17667491/how-to-use-sox-in-windows – Helana Brock Nov 19 '22 at 00:21
  • @juanpa.arrivillaga Ah, I assumed it downloaded the binary with the wrapper. – Carcigenicate Nov 19 '22 at 00:24
  • @juanpa.arrivillaga I am downloading what I believe to be the right thing (https://sourceforge.net/projects/sox/) into the Program File (x86) – Helana Brock Nov 19 '22 at 00:24
  • 1
    Then you either need to modify your path, or include the full path to the `sox.exe` binary in your call to `subprocess.run`. Python can't guess where the program is located. – Tim Roberts Nov 19 '22 at 01:38
  • @TimRoberts Python is a program language so yes it cannot guess. I tried to include sox.exe at the end as well as other ways of modifying my path. Still did not work, and I read that it wasn't needed, you just need to include up to the folder the exe file was in. Maybe that was outdated or not correct for Windows 11. I will keep trying. – Helana Brock Nov 19 '22 at 01:44
  • @TimRoberts adding the full path to the `sox.exe` binary to the code has allowed me to move on. Thank you for your solution. – Helana Brock Nov 19 '22 at 01:49

0 Answers0