def join(self, inputWavfile: wave.Wave_read, start, end):
     length = end - start
     if start < 0 or end < 0 or length < 0:
         raise ValueError("Invalid start value was given")
     params = inputWavfile.getparams()
     if not self.__compareParams(params):
         raise ValueError("File can not be joined due to inappropriate parameters")
     else:
         inputWavfile.setpos(int(start * self.frameRate))
         data = inputWavfile.readframes(int(length * self.frameRate))
         self.__output.writeframes(data)
예제 #2
0
 def read(file: wave.Wave_read):
     """
     Reads file and produces an audiodata from its data
     Returns that audiodata
     """
     params = file.getparams()
     frames_number = file.getnframes()
     frames = file.readframes(frames_number)
     characters_per_frame = len(frames) // frames_number
     framesdata = split_frames_into_sounds(frames, characters_per_frame)
     return AudioData(params, framesdata)
예제 #3
0
def trim(sound_file: wave.Wave_read, ratio, new_file_path):
    """
    Creates a new trimmed file out of the given one
    :param sound_file: Source file
    :param ratio: The ratio by which the function trims
    :param new_file_path: Path to the output file
    """
    frame_count = sound_file.getnframes()
    target_frame_count = int(frame_count * ratio)

    new_frames = sound_file.readframes(target_frame_count)
    new_file = wave.open(new_file_path, 'w')
    new_file.setparams(sound_file.getparams())
    new_file.writeframes(new_frames)
    new_file.close()