Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write(self, file_name):
"""
Output to file using segment-specific __str__ function
"""
file_extension = file_name.split(
".")[-1] if "." in file_name else "stm"
file_name = sanitize_hyphens(file_name)
data_handler = importlib.import_module(
"asrtoolkit.data_handlers.{:}".format(file_extension))
with open(file_name, "w", encoding="utf-8") as f:
f.write(data_handler.header())
f.writelines(
data_handler.separator.join(
seg.__str__(data_handler) for seg in self.segments))
f.write(data_handler.footer())
# return back new object in case we are updating a list in place
return time_aligned_text(file_name)
def prepare_for_training(self, file_name, sample_rate=16000):
"""
Converts to single channel (from channel 1) audio file
in SPH file format
Returns audio_file object on success, else None
"""
if file_name.split(".")[-1] != "sph":
LOGGER.warning(
"Forcing training data to use SPH file format for %s",
file_name)
file_name = strip_extension(file_name) + ".sph"
file_name = sanitize_hyphens(file_name)
# return None if error code given, otherwise return audio_file object
output_file = (audio_file(file_name) if not subprocess.call(
"sox -V1 {} {} rate {} remix -".format(self.location, file_name,
sample_rate),
shell=True,
) else None)
return output_file