justinsalamon / scaper

A library for soundscape synthesis and augmentation
BSD 3-Clause "New" or "Revised" License
384 stars 56 forks source link

Unable to use on Windows because of dependency on grep #25

Closed mthaak closed 6 years ago

mthaak commented 7 years ago

When, after installing the latest version using pip on Windows 10, I import Scaper I get the following error:

'grep' is not recognized as an internal or external command, operable program or batch file.

with traceback

Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1683, in main() File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1677, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev\pydevd.py", line 1087, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.3\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "E:/Github/how-noisy/util/create_soundscapes.py", line 6, in import scaper File "E:\Development\Python3\Anaconda3\lib\site-packages\scaper__init.py", line 4, in from .core import Scaper File "E:\Development\Python3\Anaconda3\lib\site-packages\scaper\core.py", line 1, in import sox File "E:\Development\Python3\Anaconda3\lib\site-packages\sox\init__.py", line 19, in from . import file_info File "E:\Development\Python3\Anaconda3\lib\site-packages\sox\file_info.py", line 7, in from .core import VALID_FORMATS File "E:\Development\Python3\Anaconda3\lib\site-packages\sox\core.py", line 96, in VALID_FORMATS = _get_valid_formats() File "E:\Development\Python3\Anaconda3\lib\site-packages\sox\core.py", line 90, in _get_valid_formats shell=True File "E:\Development\Python3\Anaconda3\lib\subprocess.py", line 336, in check_output **kwargs).stdout File "E:\Development\Python3\Anaconda3\lib\subprocess.py", line 418, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command 'sox -h | grep "AUDIO FILE FORMATS"' returned non-zero exit status 255.

`

mthaak commented 7 years ago

It's a sox problem. I changed on line 96 of sox/core.py: VALID_FORMATS = _get_valid_formats() to VALID_FORMATS = ["wav"] And now I can use Scaper again (with .wav files).

justinsalamon commented 6 years ago

@mthaak thanks for posting the issue and for figuring out what the problem is. Have you posted the issue on the pysox repo?

A more general solution would be to check for the OS and use the appropriate command:

import platform

def _get_valid_formats():
    ''' Calls SoX help for a lists of audio formats available with the current
    install of SoX.
    Returns:
    --------
    formats : list
        List of audio file extensions that SoX can process.
    '''
    if NO_SOX:
        return []

    pfm = platform.system()
    if pfm == 'Windows':
        shell_output = subprocess.check_output(
            'sox -h | findstr "AUDIO FILE FORMATS"',
            shell=True)
    else:
        shell_output = subprocess.check_output(
            'sox -h | grep "AUDIO FILE FORMATS"',
            shell=True)

    formats = str(shell_output).strip('\n').split(' ')[3:]
    return formats

VALID_FORMATS = _get_valid_formats()

I don't have access to a windows machine right now so I can't verify that this actually works - @mthaak any chance you can give this a spin? I'm sure @rabitt would be happy to receive a PR :)

mthaak commented 6 years ago

@justinsalamon I have just created an issue on the pysox repo (https://github.com/rabitt/pysox/issues/66) with a solution based on yours.

justinsalamon commented 6 years ago

@mthaak great, let's continue the discussion over there.