当前位置: 首页>>代码示例>>Python>>正文


Python AudioFile.__init__方法代码示例

本文整理汇总了Python中audiotools.AudioFile.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python AudioFile.__init__方法的具体用法?Python AudioFile.__init__怎么用?Python AudioFile.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在audiotools.AudioFile的用法示例。


在下文中一共展示了AudioFile.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        AudioFile.__init__(self, filename)

        try:
            f = file(filename, 'rb')
        except IOError, msg:
            raise InvalidAU(str(msg))
开发者ID:bspeice,项目名称:Melodia,代码行数:9,代码来源:__au__.py

示例2: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string"""

        AudioFile.__init__(self, filename)

        self.__channels__ = 0
        self.__sample_rate__ = 0
        self.__bits_per_sample__ = 0
        self.__data_size__ = 0
        self.__channel_mask__ = ChannelMask(0)

        from .bitstream import BitstreamReader

        fmt_read = data_read = False

        try:
            for chunk in self.chunks():
                if (chunk.id == "fmt "):
                    try:
                        (self.__channels__, self.__sample_rate__,
                         self.__bits_per_sample__,
                         self.__channel_mask__) = parse_fmt(
                             BitstreamReader(chunk.data(), 1))
                        fmt_read = True
                        if (fmt_read and data_read):
                            break
                    except IOError:
                        continue
                elif (chunk.id == "data"):
                    self.__data_size__ = chunk.size()
                    data_read = True
                    if (fmt_read and data_read):
                        break
        except IOError:
            raise InvalidWave("I/O error reading wave")
开发者ID:atempcode1,项目名称:python-audio-tools,代码行数:37,代码来源:__wav__.py

示例3: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        AudioFile.__init__(self, filename)

        from audiotools.bitstream import BitstreamReader
        from audiotools.text import (ERR_AU_INVALID_HEADER,
                                     ERR_AU_UNSUPPORTED_FORMAT)

        try:
            f = open(filename, 'rb')

            (magic_number,
             self.__data_offset__,
             self.__data_size__,
             encoding_format,
             self.__sample_rate__,
             self.__channels__) = BitstreamReader(f, 0).parse("4b 5* 32u")
        except IOError as msg:
            raise InvalidAU(str(msg))

        if (magic_number != '.snd'):
            raise InvalidAU(ERR_AU_INVALID_HEADER)
        try:
            self.__bits_per_sample__ = {2: 8, 3: 16, 4: 24}[encoding_format]
        except KeyError:
            raise InvalidAU(ERR_AU_UNSUPPORTED_FORMAT)
开发者ID:Kevin-Russell,项目名称:python-audio-tools,代码行数:27,代码来源:au.py

示例4: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        from audiotools.id3 import skip_id3v2_comment

        AudioFile.__init__(self, filename)

        try:
            with open(filename, "rb") as f:
                skip_id3v2_comment(f)

                from audiotools.bitstream import BitstreamReader
                from audiotools.text import (ERR_TTA_INVALID_SIGNATURE,
                                             ERR_TTA_INVALID_FORMAT)

                reader = BitstreamReader(f, True)

                (signature,
                 format_,
                 self.__channels__,
                 self.__bits_per_sample__,
                 self.__sample_rate__,
                 self.__total_pcm_frames__) = reader.parse(
                    "4b 16u 16u 16u 32u 32u 32p")

                if (signature != b"TTA1"):
                    raise InvalidTTA(ERR_TTA_INVALID_SIGNATURE)
                elif (format_ != 1):
                    raise InvalidTTA(ERR_TTA_INVALID_FORMAT)

                self.__total_tta_frames__ = div_ceil(
                    self.__total_pcm_frames__ * 245,
                    self.__sample_rate__ * 256)
                self.__frame_lengths__ = list(reader.parse(
                    "%d* 32u" % (self.__total_tta_frames__) + "32p"))
        except IOError as msg:
            raise InvalidTTA(str(msg))
开发者ID:bossjones,项目名称:python-audio-tools,代码行数:37,代码来源:tta.py

示例5: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string"""

        from audiotools.bitstream import BitstreamReader

        AudioFile.__init__(self, filename)

        # first, fetch the mdia atom
        # which is the parent of both the mp4a and mdhd atoms
        try:
            with BitstreamReader(open(filename, "rb"), False) as reader:
                mdia = get_m4a_atom(reader,
                                    b"moov", b"trak", b"mdia")[1]
                mdia_start = mdia.getpos()
        except IOError:
            from audiotools.text import ERR_M4A_IOERROR
            raise InvalidM4A(ERR_M4A_IOERROR)
        except KeyError:
            from audiotools.text import ERR_M4A_MISSING_MDIA
            raise InvalidM4A(ERR_M4A_MISSING_MDIA)

        try:
            stsd = get_m4a_atom(mdia, b"minf", b"stbl", b"stsd")[1]
        except KeyError:
            from audiotools.text import ERR_M4A_MISSING_STSD
            raise InvalidM4A(ERR_M4A_MISSING_STSD)

        # then, fetch the mp4a atom for bps, channels and sample rate
        try:
            (stsd_version, descriptions) = stsd.parse("8u 24p 32u")
            (mp4a,
             self.__channels__,
             self.__bits_per_sample__) = stsd.parse(
                "32p 4b 48p 16p 16p 16p 4P 16u 16u 16p 16p 32p")
        except IOError:
            from audiotools.text import ERR_M4A_INVALID_MP4A
            raise InvalidM4A(ERR_M4A_INVALID_MP4A)

        # finally, fetch the mdhd atom for total track length
        mdia.setpos(mdia_start)
        try:
            mdhd = get_m4a_atom(mdia, b"mdhd")[1]
        except KeyError:
            from audiotools.text import ERR_M4A_MISSING_MDHD
            raise InvalidM4A(ERR_M4A_MISSING_MDHD)
        try:
            (version, ) = mdhd.parse("8u 24p")
            if version == 0:
                (self.__sample_rate__,
                 self.__length__,) = mdhd.parse("32p 32p 32u 32u 2P 16p")
            elif version == 1:
                (self.__sample_rate__,
                 self.__length__,) = mdhd.parse("64p 64p 32u 64U 2P 16p")
            else:
                from audiotools.text import ERR_M4A_UNSUPPORTED_MDHD
                raise InvalidM4A(ERR_M4A_UNSUPPORTED_MDHD)
        except IOError:
            from audiotools.text import ERR_M4A_INVALID_MDHD
            raise InvalidM4A(ERR_M4A_INVALID_MDHD)
开发者ID:KristoforMaynard,项目名称:python-audio-tools,代码行数:61,代码来源:m4a.py

示例6: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string."""

        AudioFile.__init__(self, filename)
        try:
            self.__read_metadata__()
        except IOError, msg:
            raise InvalidVorbis(str(msg))
开发者ID:bspeice,项目名称:Melodia,代码行数:10,代码来源:__vorbis__.py

示例7: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string."""

        AudioFile.__init__(self, filename)
        try:
            f = open(filename, 'rb')
        except IOError, msg:
            raise InvalidShorten(str(msg))
开发者ID:bspeice,项目名称:Melodia,代码行数:10,代码来源:__shn__.py

示例8: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string."""

        AudioFile.__init__(self, filename)

        try:
            mp3file = file(filename, "rb")
        except IOError, msg:
            raise InvalidMP3(str(msg))
开发者ID:bspeice,项目名称:Melodia,代码行数:11,代码来源:__mp3__.py

示例9: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string."""

        AudioFile.__init__(self, filename)

        (self.__samplespersec__,
         self.__channels__,
         self.__bitspersample__,
         self.__totalsamples__) = ApeAudio.__ape_info__(filename)
开发者ID:mr-robot,项目名称:python-audio-tools,代码行数:11,代码来源:__ape__.py

示例10: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string"""

        AudioFile.__init__(self, filename)
        self.__sample_rate__ = 0
        self.__channels__ = 0
        try:
            self.__read_identification__()
        except IOError, msg:
            raise InvalidVorbis(str(msg))
开发者ID:SeverVladMuresan,项目名称:python-audio-tools,代码行数:12,代码来源:vorbis.py

示例11: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string"""

        from audiotools.bitstream import BitstreamReader

        AudioFile.__init__(self, filename)
        try:
            f = open(filename, 'rb')
        except IOError, msg:
            raise InvalidShorten(str(msg))
开发者ID:XiaonuoGantan,项目名称:python-audio-tools,代码行数:12,代码来源:__shn__.py

示例12: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string."""

        AudioFile.__init__(self, filename)

        from .bitstream import BitstreamReader

        try:
            mp3file = open(filename, "rb")
        except IOError, msg:
            raise InvalidMP3(str(msg))
开发者ID:bluemutedwisdom,项目名称:python-audio-tools,代码行数:13,代码来源:__mp3__.py

示例13: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        """filename is a plain string"""

        from .bitstream import BitstreamReader
        from . import ChannelMask
        import cStringIO

        AudioFile.__init__(self, filename)
        try:
            f = open(filename, 'rb')
        except IOError, msg:
            raise InvalidShorten(str(msg))
开发者ID:Excito,项目名称:audiotools,代码行数:14,代码来源:shn.py

示例14: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        from audiotools.bitstream import BitstreamReader

        AudioFile.__init__(self, filename)

        try:
            with BitstreamReader(
                open(self.filename, "rb"), True) as ogg_reader:
                (magic_number,
                 version,
                 header_type,
                 granule_position,
                 self.__serial_number__,
                 page_sequence_number,
                 checksum,
                 segment_count) = ogg_reader.parse("4b 8u 8u 64S 32u 32u 32u 8u")

                if magic_number != b'OggS':
                    from audiotools.text import ERR_OGG_INVALID_MAGIC_NUMBER
                    raise InvalidVorbis(ERR_OGG_INVALID_MAGIC_NUMBER)
                if version != 0:
                    from audiotools.text import ERR_OGG_INVALID_VERSION
                    raise InvalidVorbis(ERR_OGG_INVALID_VERSION)

                segment_lengths = [ogg_reader.read(8) for i in
                                   range(segment_count)]

                (speex_string,
                 speex_version,
                 speex_version_id,
                 header_size,
                 self.__sampling_rate__,
                 mode,
                 mode_bitstream_version,
                 self.__channels__,
                 bitrate,
                 frame_size,
                 vbr,
                 frame_per_packet,
                 extra_headers,
                 reserved1,
                 reserved2) = ogg_reader.parse("8b 20b 13*32u")

                if speex_string != b"Speex   ":
                    raise InvalidSpeex(ERR_SPEEX_INVALID_VERSION)
        except IOError as err:
            raise InvalidSpeex(str(err))
开发者ID:KristoforMaynard,项目名称:python-audio-tools,代码行数:49,代码来源:speex.py

示例15: __init__

# 需要导入模块: from audiotools import AudioFile [as 别名]
# 或者: from audiotools.AudioFile import __init__ [as 别名]
    def __init__(self, filename):
        AudioFile.__init__(self, filename)

        from .bitstream import BitstreamReader

        try:
            f = file(filename, 'rb')

            (magic_number,
             self.__data_offset__,
             self.__data_size__,
             encoding_format,
             self.__sample_rate__,
             self.__channels__) = BitstreamReader(f, 0).parse(
                "4b 32u 32u 32u 32u 32u")
        except IOError, msg:
            raise InvalidAU(str(msg))
开发者ID:mr-robot,项目名称:python-audio-tools,代码行数:19,代码来源:__au__.py


注:本文中的audiotools.AudioFile.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。