samples folder has a bunch of samples a,b,c,d,e
.
while saving the final output features_with_times
to a file, I want it to be appended with name of the file it just processed.
I approached using Creating a new file, filename contains loop variable, python , and I did the following, but getting small error.
from __future__ import division
import librosa
import os
import numpy as np
test_src = 'samples/'
path_to_audios = [os.path.join(test_src, f) for f in os.listdir(test_src)]
for audio_path in path_to_audios:
# blah ..
# blah
# blah . .
# blah . .
features_with_times= some_val
# np.savetxt('koo'+ str(k) + '.txt')
print "saving mfcc features"
np.savetxt('mfcc_flwts'+str(audio_path)+'.txt', features_with_times,newline ='\n', delimiter= '\t')
ERROR : IOError: [Errno 2] No such file or directory: 'mfcc_flwtssamples/abc.mp3.txt'
How to fix this ? how do _prevent the samples/
tag from coming in between.
I know I can have names_to_append = [f for f in os.listdir(test_src)]
which will save the names of the files present in the sample/ folder. to a list.
How do I pass these to the np.savetxt()
step.
Newbie question.
UPDATE: I crude solution I came up with was to subtract the two strings:
a = 'samples/'
b = audio_path
val = b.replace(a,'')
np.savetxt('mfcc_flwts_'+str(val)+'.txt', features_with_times,newline ='\n', delimiter= '\t')
Is there a better way to achieve my solution.
UPDATE : 2 :
I am also able to save it to a folder of my choice as follows:
save_destination = 'outputss/'
np.savetxt(os.path.join(save_destination,'mfcc_flwts_'+str(val)+'.txt'), features_with_times,newline ='\n', delimiter= '\t')