Exemplo n.º 1
0
    def convert(self,
                target_path,
                target_class,
                compression=None,
                progress=None):
        """encodes a new AudioFile from existing AudioFile

        take a filename string, target class and optional compression string
        encodes a new AudioFile in the target class and returns
        the resulting object
        may raise EncodingError if some problem occurs during encoding"""

        # A Shorten file cannot contain both RIFF and AIFF chunks
        # at the same time.

        from audiotools import WaveAudio
        from audiotools import AiffAudio
        from audiotools import to_pcm_progress

        if ((self.has_foreign_wave_chunks()
             and hasattr(target_class, "from_wave")
             and callable(target_class.from_wave))):
            return WaveContainer.convert(self, target_path, target_class,
                                         compression, progress)
        elif (self.has_foreign_aiff_chunks()
              and hasattr(target_class, "from_aiff")
              and callable(target_class.from_aiff)):
            return AiffContainer.convert(self, target_path, target_class,
                                         compression, progress)
        else:
            return target_class.from_pcm(target_path,
                                         to_pcm_progress(self, progress),
                                         compression,
                                         total_pcm_frames=self.total_frames())
Exemplo n.º 2
0
    def convert(self, target_path, target_class, compression=None,
                progress=None):
        """encodes a new AudioFile from existing AudioFile

        take a filename string, target class and optional compression string
        encodes a new AudioFile in the target class and returns
        the resulting object
        may raise EncodingError if some problem occurs during encoding"""

        #A Shorten file cannot contain both RIFF and AIFF chunks
        #at the same time.

        import tempfile
        from . import WaveAudio
        from . import AiffAudio
        from . import to_pcm_progress

        if ((self.has_foreign_wave_chunks() and
             hasattr(target_class, "from_wave") and
             callable(target_class.from_wave))):
            return WaveContainer.convert(self,
                                         target_path,
                                         target_class,
                                         compression,
                                         progress)
        elif (self.has_foreign_aiff_chunks() and
              hasattr(target_class, "from_aiff") and
              callable(target_class.from_aiff)):
            return AiffContainer.convert(self,
                                         target_path,
                                         target_class,
                                         compression,
                                         progress)
        else:
            return target_class.from_pcm(
                target_path,
                to_pcm_progress(self, progress),
                compression,
                total_pcm_frames=self.total_frames())