Analyzing folders on Windows in Python

57 views
Skip to first unread message

Dylan Osterhaus

unread,
Jan 13, 2022, 4:51:20 PM1/13/22
to birdvox
Hello,
I am trying to analyze the following folder C:\Users\dylano\Desktop\Sound using the following code form github. This folder contains 10, 1-hour long .wav files.
"""""""""""""""""""""""""""""""""""""""""""""""""""
import birdvoxdetect as bvd
df = bvd.process_file('C:/Users/dylano/Desktop/Sound')
"""""""""""""""""""""""""""""""""""""""""""""""""""

and receive the following error

"""""""""""""""""""""""""""""""""""""""""""""""""""""
>>> df = bvd.process_file('C:/Users/dylano/Desktop/Sound')
Traceback (most recent call last):
  File "C:\Users\dylano\AppData\Local\Programs\Python\Python37\lib\site-packages\birdvoxdetect\core.py", line 121, in process_file
    sound_file = sf.SoundFile(filepath)
  File "C:\Users\dylano\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 740, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "C:\Users\dylano\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 1265, in _open
    "Error opening {0!r}: ".format(self.name))
  File "C:\Users\dylano\AppData\Local\Programs\Python\Python37\lib\site-packages\soundfile.py", line 1455, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening 'C:/Users/dylano/Desktop/Sound': System error.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\dylano\AppData\Local\Programs\Python\Python37\lib\site-packages\birdvoxdetect\core.py", line 123, in process_file
    raise BirdVoxDetectError("Could not open file: {}".format(filepath))
birdvoxdetect.birdvoxdetect_exceptions.BirdVoxDetectError: Could not open file: C:/Users/dylano/Desktop/Sound
"""""""""""""""""""""""""""""""""""""""""""""""""""

What is the correct code that I need to run in order to analyze this folder? Any help would be appreciated!

Thank you,

Dylan Osterhaus

Vincent Lostanlen

unread,
Jan 13, 2022, 4:54:32 PM1/13/22
to bir...@googlegroups.com

Hello Dylan,

Looking from your traceback, it seems like PySoundFile cannot open your audio data.

This may either be a problem in the audio encoding of the data (likely) or a problem with your PySoundFile installation (less likely).

I don't think this is specifically a BirdVoxDetect problem, but i might be wrong.


I hope this helps!

Sincerely,

Vincent.

--
You received this message because you are subscribed to the Google Groups "birdvox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to birdvox+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/birdvox/5349f982-0546-476f-86fa-56d6aeeae6ddn%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dylan Osterhaus

unread,
Jan 13, 2022, 4:58:07 PM1/13/22
to birdvox
Vincent,

When I analyze one of the files within the folder individually (using the code below), everything works as it should. Would this eliminate an audio encoding issue?

df = bvd.process_file('C:/Users/dylano/Desktop/Sound/WS1_20210901_045556.wav')

Thank you,
Dylan

Vincent Lostanlen

unread,
Jan 13, 2022, 5:03:25 PM1/13/22
to bir...@googlegroups.com

Ah, i hadn't seen you were trying to analyze a folder, not a specific file.

process_file can only take paths from files, not folders, at input (as the name implies)


To analyze a folder, i recommend you make your own for loop. Something like:


data_dir = 'C:/Users/dylano/Desktop/Sound'

dfs = {}

for name in os.listdir(data_dir):
    df[name] = bvd.process_file(data_dir + "/" + name)



Or else use the command-line :)

birdvoxdetect path/to/folder


I hope this helps!

Vincent.

Dylan Osterhaus

unread,
Jan 13, 2022, 5:15:46 PM1/13/22
to birdvox
Vincent,

I tried the command line option and received a syntax error
""""""""""""""""
>>> birdvoxdetect C:\Users\dylano\Desktop\Sound
  File "<stdin>", line 1
    birdvoxdetect C:\Users\dylano\Desktop\Sound
                              ^
SyntaxError: invalid syntax
"""""""""""""""""

I am sure this is probably an easy fix but I am not at all familiar with Python. I appreciate the help!

Dylan
Reply all
Reply to author
Forward
0 new messages