Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_temp(id, output):
temp_file = join(samples_dir, "%s.actual" % id)
content = u"\n".join([u"\t".join(item) for item in output])
write(temp_file, content)
except:
pass
finally:
os.mkdir(wav_folder)
for wav in wavs_test:
new_path = join(wav_folder, basename(wav))
shutil.copyfile(wav, new_path)
wavs_test_new_path = [join("wav", basename(wav)) for wav in wavs_test]
speech_recognition = {
"texts_test": texts_test,
"texts_pred": texts_pred,
"wavs_test": wavs_test_new_path,
}
content = json.dumps(speech_recognition, ensure_ascii=False)
log_file = join(log_folder, "speechrecognition.json")
write(log_file, content)
print("Result is written in {}".format(log_file))
print("WER: {}%".format(wer * 100))
model_id = "1"
try:
shutil.rmtree(join(test_dir, model_id))
except:
pass
mkdir(join(test_dir, model_id))
for f in files:
input = load_input(join(test_dir, f))
output = ner(input)
actual = "\n".join(["\t".join(tokens) for tokens in output])
expected = load_output(join(test_dir, f))
if actual != expected:
print("\n{}".format(f))
diff = '\n'.join(ndiff(expected.splitlines(), actual.splitlines()))
write(join(test_dir, model_id, f), "\n".join([extract_sentence(actual), actual]))
write(join(test_dir, model_id, f + ".diff"), "\n".join([extract_sentence(actual), diff]))
def save(self, folder, format):
"""save wscorpus to files
:param str folder: path to directory
:type folder: string
:param str format: either TEXT or COLUMN
:type format: str
"""
try:
mkdir(folder)
except Exception:
pass
for document in self.documents:
f = join(folder, document.id)
content = u"\n".join(document.sentences)
write(f, content)
def save(self, folder):
"""save corpus to files
:param str folder: path to directory
:type folder: string
"""
try:
mkdir(folder)
except Exception:
pass
for document in self.documents:
filename = join(folder, document.id)
content = u"\n".join(document.sentences)
write(filename, content)