< Back to IRCAM Forum

How to specify input sound file when imposing statistics?

I’ve run into an obstacle while trying to implement Xtextures. When I attempt to impose statistics on an existing sound file via the --init flag, I receive

Traceback (most recent call last):
File “./impose_cnn_stats.py”, line 139, in
init_sig = read_snd(args.init_file, samp_rate, logger=ilog, ffmpeg_bin=args.ffmpeg)
File “/Users/Robert/Xtextures/XTextures_impl/util.py”, line 201, in read_snd
snd, in_srate, _ = sndio.read(snd_file, dtype=np.dtype(dtype))
File “/Users/Robert/opt/anaconda3/envs/Xtextures/lib/python3.7/site-packages/pysndfile/sndio.py”, line 165, in read
with PySndfile(name) as sf:
File “_pysndfile.pyx”, line 720, in _pysndfile.PySndfile.cinit
OSError: PySndfile::error while opening b’*/snd_examples/6-Nihal-8_Nihal22050.wav’

->b'System error : No such file or directory.'

My file is in the snd_examples folder; I’ve also tried moving it around to a couple of other locations within the Xtextures folder to no avail. Where is the proper location?

Thanks in advance,

Robert

Dear Robert,

Where is the proper location?

Where ever you like. But you need to specify the location correctly to the --init flag.

When I attempt to impose statistics on an existing sound file via the --init flag, I receive

...
OSError: PySndfile::error while opening b’*/snd_examples/6-Nihal-8_Nihal22050.wav’

For such questions you better provide the full command line you used. Here the error message seems to imply that you specified the file as --init */snd_examples/6-Nihal-8_Nihal22050.wav. The “*” is a pattern matching operator. You probably just need to remove */ from your filename
and if your current directory is the Xtextures root folder and the file exists in the snd_examples sub folder this should work.

A few explanations about using *:

  1. If you write --init */snd_examples/6-Nihal-8_Nihal22050.wav in the bash command line the shell will search for files matching the pattern */snd_examples/6-Nihal-8_Nihal22050.wav starting from the current working directory. If it finds one or more it will replace the pattern by all files it found. If it does not find a matching file it keeps the pattern unchanged. So here as the impose script reports not being able to open the file */snd_examples/6-Nihal-8_Nihal22050.wav I would conclude that the shell did not find any matching files. The problem is therefore not the placement but the way you specify the file. You can debug you command line simply by means of echo. Let’s see two examples supposing you are located in the Xtextures root folder with an incomplete command line (having only the --init flag).
1> echo ./impose_cnn_stats.py --init snd_examples/Fr*.flac
./impose_cnn_stats.py --init snd_examples/FreeJazz_Drum.flac

The echo command does not execute the command but displays it. So you can see the command line the shell has constructed. It found a single flac files starting with Fr in the snd_examples folder and replaced the pattern on the command line. Now using your pattern:

2> echo ./impose_cnn_stats.py --init */snd_examples/Fr*.flac
./impose_cnn_stats.py --init */snd_examples/Fr*.flac

The shell did not find a matching file and kept the pattern. This wont work.

In fact the pattern */snd_examples/Fr*.flac searchers for folders containing folders named snd_examples containg files starting with Fr.

  1. the --init expects a single file. The * pattern may find more than one, in which case the resulting command line will have more than one file after the --init flag which will lead to an error.

In case you want to run over multiple files and you are using bash you could use for loops like this

 for file in  snd/examples/*.wav; do
   ./impose_cnn_stats.py  --init $file ...other flags and 
 done
1 Like