1

I'm using the Librosa function librosa.output.write_wav to output a time series as a .wav file and then trying to open it in pydub, but pydub is throwing a FileNotFoundError message (see below). The *.wav files are definitely in the same directory as my Jupyter notebook (convert_spect_to_wav.ipynb). The weird thing is my code works perfectly fine if I feed in *.wav files that were not generated by Librosa. I'm able to listen to the Librosa *.wav files, so I don't know what weird thing Librosa is doing that is making pydub not find the Librosa *.wav files.

Directory

[lashen.lashen-MOBL] ➤ ls -l
total 442
-rwx------    1 lashen   UsersGrp    103566 Feb 17 14:47 bdl_arctic_a0001.wav
-rwx------    1 lashen   UsersGrp     12973 Mar 17 12:56 convert_spect_to_wav.ipynb
drwx------    1 lashen   UsersGrp         0 Mar 17 12:38 generated
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_0.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_1.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_2.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_3.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_4.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:55 generated_5.wav
-rwx------    1 lashen   UsersGrp     43066 Mar 17 12:48 hello.wav
-rwx------    1 lashen   UsersGrp    103566 Feb 17 14:58 ksp_arctic_a0001.wav
-rwx------    1 lashen   UsersGrp     44530 Mar 17 12:40 ksp_arctic_a0001_0.wav
-rwx------    1 lashen   UsersGrp      1408 Mar  6 20:21 parameters.mat
-rwx------    1 lashen   UsersGrp     25971 Mar  6 19:54 style_transfer.ipynb
-rwx------    1 lashen   UsersGrp     96044 Mar 17 12:40 whole_clip.wav

FileNotFoundError message

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-67-6381f1840332> in <module>()
----> 1 convert_spect_to_wav('../dataset_processed/bdl_spectrogram_array.npy')

<ipython-input-66-a201b054f438> in convert_spect_to_wav(file_name)
     19 
     20     # Piece together the wav files
---> 21     stitch_wavs_together(file_names)

<ipython-input-65-63d881a5987a> in stitch_wavs_together(file_names)
      7     for file in clip_file_list:
      8         print (file)
----> 9         clip = AudioSegment.from_wav(file)
     10         wav_clips.append(clip)
     11 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pydub\audio_segment.py in from_wav(cls, file, parameters)
    542     @classmethod
    543     def from_wav(cls, file, parameters=None):
--> 544         return cls.from_file(file, 'wav', parameters)
    545 
    546     @classmethod

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pydub\audio_segment.py in from_file(cls, file, format, codec, parameters, **kwargs)
    510 
    511         with open(os.devnull, 'rb') as devnull:
--> 512             p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    513         p_out, p_err = p.communicate()
    514 

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    707                                 c2pread, c2pwrite,
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         except:
    711             # Cleanup if the child failed starting.

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
    995                                          env,
    996                                          os.fspath(cwd) if cwd is not None else None,
--> 997                                          startupinfo)
    998             finally:
    999                 # Child is launched. Close the parent's copy of those pipe

FileNotFoundError: [WinError 2] The system cannot find the file specified

I don't know why pydub cannot find the *.wav files outputted by Librosa. The issue is only with the Librosa *.wav files since other *.wav files work without error. Has anyone else encountered this before??

Here some relevant code: write_time_series_to_wav creates the Librosa *.wav file, stitch_wavs_together is where I'm trying to read the Librosa *.wav files using pydub, and convert_spect_to_wav calls these two functions.

def write_time_series_to_wav(time_series, sampling_rate):
    file_prefix = 'generated_'
    file_names_list = []

    i = 0
    for series in time_series:
        file_name = file_prefix + str(i) + '.wav'
        librosa.output.write_wav(file_name, series, sampling_rate)
        file_names_list.append(file_name)
        i = i + 1

    return file_names_list

def stitch_wavs_together(file_names):

    wav_clips = []
    clip_file_list = glob.glob('generated_*.wav')
    print (clip_file_list)

    for file in clip_file_list:
        print (file)
        clip = AudioSegment.from_wav(file)
        wav_clips.append(clip)

    whole_clip = wav_clips[0]

    for i in range(1, len(wav_clips)):
        whole_clip = whole_clip + wav_clips[i]

    whole_clip.export('whole_clip.wav', format='wav')

def convert_spect_to_wav(file_name):
    spectrogram_array = np.load(file_name)
    print (spectrogram_array.shape)
    spectrogram_list = []

    for spectrogram in spectrogram_array:
        #print (spectrogram.shape)
        spectrogram_list.append(spectrogram)

    #spectrogram_list = spectrogram_array.tolist()
    #print (spectrogram_list)

    # Convert spectrogram to time series
    time_series = convert_spect_to_time_series(spectrogram_list)

    # Write time series out to wav files
    file_names = write_time_series_to_wav(time_series, 22050)
    print (file_names)

    # Piece together the wav files
    stitch_wavs_together(file_names)

Any help or input is appreciated!!

lashen
  • 31
  • 5
  • often that error occurs because ffmpeg/avconv can't be found – Jiaaro Mar 20 '18 at 14:04
  • Thanks for the reply, Jiaaro. I though that *.wav files worked without ffmpeg/avconv? I suppose Librosa is doing something weird to the exported *.wav files. – lashen Mar 23 '18 at 05:06

0 Answers0