Ejemplo n.º 1
0
    def from_wave(cls, filename, wave_filename, compression=None,
                  block_size=256):
        """Encodes a new AudioFile from an existing .wav file.

        Takes a filename string, wave_filename string
        of an existing WaveAudio file
        and an optional compression level string.
        Encodes a new audio file from the wave's data
        at the given filename with the specified compression level
        and returns a new ShortenAudio object."""

        wave = WaveAudio(wave_filename)

        if (wave.bits_per_sample() not in (8, 16)):
            raise UnsupportedBitsPerSample()

        (head, tail) = wave.pcm_split()
        if (len(tail) > 0):
            blocks = [head, None, tail]
        else:
            blocks = [head, None]

        import audiotools.encoders

        try:
            audiotools.encoders.encode_shn(filename=filename,
                                           pcmreader=wave.to_pcm(),
                                           block_size=block_size,
                                           verbatim_chunks=blocks)

            return cls(filename)
        except IOError, err:
            cls.__unlink__(filename)
            raise EncodingError(str(err))
Ejemplo n.º 2
0
    def from_wave(cls, filename, wave_filename, compression=None):
        wave = WaveAudio(wave_filename)

        if (wave.bits_per_sample() not in (8,16)):
            raise UnsupportedBitsPerSample()

        (head,tail) = wave.pcm_split()
        if (len(tail) > 0):
            blocks = [head,None,tail]
        else:
            blocks = [head,None]

        import audiotools.encoders

        try:
            audiotools.encoders.encode_shn(filename=filename,
                                           pcmreader=wave.to_pcm(),
                                           block_size=256,
                                           verbatim_chunks=blocks)

            return cls(filename)
        except IOError:
            raise EncodingError("shn")