本文整理汇总了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)
示例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()
示例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)