Beispiel #1
0
def getSignalFromFile(filename):
    filepath = os.path.join(WAV_PATH, filename)
    framerate, signal = scipy_read(filepath)
    assert (framerate == Parameters.sampling_rate)
    assert (signal.shape[1] == Parameters.n_channels)
    return signal
Beispiel #2
0
 def __init__(self, path: str, hop_size: int):
     super().__init__(hop_size)
     self.samplerate, self.data = scipy_read(path)
     self.duration_s = self.data.shape[0] / self.samplerate
Beispiel #3
0
    df = pd.concat(df, axis=0, ignore_index=True).reset_index(drop=True)
    p.close()
    p.join()
    print('After Shape: ', df.shape)
    return df


#if not os.path.exists('../input/train/audio/silence'): #use on your own device to add files and use for noise in class files
#        os.makedirs('../input/train/audio/silence')

samples = pd.DataFrame(
    glob.glob('../input/train/audio/_background_noise_/**.wav'),
    columns=['path'])
n = 10000
for w in samples.path:
    rate, wav = scipy_read(w)
    print(w, rate, wav.shape)
    for i in range(0, len(wav) - 16000, 16000):
        #scipy_write('../input/train/audio/silence/' + str(n) + '.wav', rate, wav[i:i+16000])
        n += 1

audio_classes = [
    'yes', 'no', 'up', 'down', 'left', 'right', 'on', 'off', 'stop', 'go',
    'silence', 'unknown'
]
print('train...')
train = pd.DataFrame(glob.glob('../input/train/audio/**/**.wav'),
                     columns=['path'])
train['label'] = train['path'].map(lambda x: x.split('/')[4])
train['label'] = train['label'].map(lambda x: x
                                    if x in audio_classes else 'unknown')
Beispiel #4
0
def fscipy_read(path):
    try:
        return scipy_read(path)[1]
    except:
        print(path)
        return
Beispiel #5
0
# were used during training

# Number of MFCC features to use
N_FEATURES = 26

# Size of the context window used for producing timesteps in the input vector
N_CONTEXT = 9

ds = Model(lm_binary, N_FEATURES, N_CONTEXT, alphabet, BEAM_WIDTH)
ds.enableDecoderWithLM(alphabet, lm_binary, trie, LM_WEIGHT, WORD_COUNT_WEIGHT,
                       VALID_WORD_COUNT_WEIGHT)

# #python to batch process
# import subprocess
#
# for index, i in enumerate(prediction.fname):
#     argument = output_graph +" "+ files[i]+" " + alphabet+" " + lm_binary+" " + trie
#
#
#     with subprocess.Popen(['deepspeech', argument], shell=True,stdout=subprocess.PIPE) as item:
#         for line in item.stdout:
#             print (line)

for index, i in enumerate(prediction.fname):
    with scipy_read(files[i]) as a:
        fs, audio = a
        #get the inference and replace it inside the pandas dataframe
        prediction.set_value(index, 'label', ds.stt(audio, fs))

#save the prediction
prediction.to_csv("predictions.csv")