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


Python Sndfile.sync方法代码示例

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


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

示例1: WaveWriter

# 需要导入模块: from scikits.audiolab import Sndfile [as 别名]
# 或者: from scikits.audiolab.Sndfile import sync [as 别名]
class WaveWriter(object) :
	def __init__(self,
				filename,
				samplerate = 44100,
				channels = 1,
				format = Format('wav','float32'),
				) :

		self._info = {	'filename' : filename , 
				'samplerate' : samplerate,
				'channels' : channels,
				'format' : format,
				'frames' : 0,
				} # TODO: metadata not implemented

		self._sndfile = Sndfile(filename, 'w', format, channels, samplerate)
		if not self._sndfile :
			raise NameError('Sndfile error loading file %s' % filename)

	def __enter__(self) :
		return self
	def __exit__(self, type, value, traceback) :
		self._sndfile.sync()
		self._sndfile.close()
		if value: raise # ????

	def write(self, data) :
		nframes, channels = data.shape
		assert channels == self._info['channels']
		self._sndfile.write_frames(data)
开发者ID:asiniscalchi,项目名称:back2back,代码行数:32,代码来源:__init__.py

示例2: TelegraphWriter

# 需要导入模块: from scikits.audiolab import Sndfile [as 别名]
# 或者: from scikits.audiolab.Sndfile import sync [as 别名]
class TelegraphWriter(Telegraph):
    """Write Morse Code to an Audio File. TelegraphWriter uses SndFile from the scikits.audiolab package to write out
    audio data,  and as such TelegraphWriter can output to whatever formats are available. See the
    :func:`available_file_formats` and :func:`available_encodings` to determine what audio outputs are available.

    :param filename: (str) Filename to output to
    :param audio_format: (str) Audio format
    :param audio_encoding: (str) Encoding of audio_format
    :param alphabet: (str) Morse Code alphabet to be used
    :raise InvalidFormatEncoding:

    The default format and encoding is ogg vorbis (http://www.vorbis.com). This produces good quality compressed
    files, but is slower that (say) WAV 16pcm
    """

    def __init__(self, filename, audio_format="ogg", audio_encoding="vorbis", alphabet="international"):
        super(TelegraphWriter, self).__init__(alphabet)
        self.__filename = filename        
        self.__audio_format = audio_format
        self.__audio_encoding = audio_encoding

        self.__output_formats = available_file_formats()

        from scikits.audiolab import Format, Sndfile          
        if self.__audio_format not in available_file_formats() or self.__audio_encoding not in available_encodings(self.__audio_format):
            raise InvalidFormatEncoding(self.__audio_format, self.__audio_encoding)
        output_format = Format(self.__audio_format, self.__audio_encoding)
        self.__output_file = Sndfile(self.__filename, 'w', output_format, 1, 44100)

    def __write_character(self, character):
        """Write a character to the output file. 

        :param character: (str) Character to be written
        :raise TypeError: If a single character is not passed
        :raise CharacterNotFound: if ignore_unknown is set to False and a character is not found
        """
        self.__output_file.write_frames(character)

    def encode(self, message):
        """Write a message to the output file. 

        :param message: (str) Message to be written
        :raise CharacterNotFound: if ignore_unknown is set to False and a character is not found
        """
        super(TelegraphWriter, self)._encode_message(self._clean_message(message), self.__write_character)
        self.__output_file.sync()
开发者ID:tyndyll,项目名称:py-morsecode,代码行数:48,代码来源:code.py

示例3: test_float_frames

# 需要导入模块: from scikits.audiolab import Sndfile [as 别名]
# 或者: from scikits.audiolab.Sndfile import sync [as 别名]
    def test_float_frames(self):
        """ Check nframes can be a float"""
        rfd, fd, cfilename   = open_tmp_file('pysndfiletest.wav')
        try:
            # Open the file for writing
            format = Format('wav', 'pcm16')
            a = Sndfile(fd, 'rw', format, channels=1, samplerate=22050)
            tmp = np.random.random_integers(-100, 100, 1000)
            tmp = tmp.astype(np.short)
            a.write_frames(tmp)
            a.seek(0)
            a.sync()
            ctmp = a.read_frames(1e2, dtype=np.short)
            a.close()

        finally:
            close_tmp_file(rfd, cfilename)
开发者ID:LiberationFrequency,项目名称:BazzArch,代码行数:19,代码来源:test_sndfile.py


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