Beispiel #1
0
  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.writelines("\n".join(seg.__str__(data_handler) for seg in self.segments))

    # 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
    """
    if file_name.split(".")[-1] != 'sph':
      print("Forcing training data to use SPH file format")
      file_name = strip_extension(file_name) + ".sph"

    file_name = sanitize_hyphens(file_name)
    subprocess.call(["sox {} {} rate {} remix -".format(self.location, file_name, sample_rate)], shell=True)

    # return new object
    return audio_file(file_name)
Beispiel #3
0
    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