#NEWLINE# def __enter__( self ) : #NEWLINE# #INDENT# assert ( self . stream is None ) , 'This audio source is already inside a context manager' #NEWLINE# try : #NEWLINE# #INDENT# self . audio_reader = wave . open ( self . filename_or_fileobject , 'rb' ) #NEWLINE# self . little_endian = True #NEWLINE# #UNINDENT# except wave . Error : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . audio_reader = aifc . open ( self . filename_or_fileobject , 'rb' ) #NEWLINE# self . little_endian = False #NEWLINE# #UNINDENT# except aifc . Error : #NEWLINE# #INDENT# if hasattr ( self . filename_or_fileobject , 'read' ) : #NEWLINE# #INDENT# flac_data = self . filename_or_fileobject . read ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# with open ( self . filename_or_fileobject , 'rb' ) as f : #NEWLINE# #INDENT# flac_data = f . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# flac_converter = get_flac_converter ( ) #NEWLINE# process = subprocess . Popen ( [ flac_converter , '--stdout' , '--totally-silent' , '--decode' , '--force-aiff-format' , '-' ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) #NEWLINE# ( aiff_data , stderr ) = process . communicate ( flac_data ) #NEWLINE# aiff_file = io . BytesIO ( aiff_data ) #NEWLINE# self . audio_reader = aifc . open ( aiff_file , 'rb' ) #NEWLINE# self . little_endian = False #NEWLINE# #UNINDENT# #UNINDENT# assert ( 1 <= self . audio_reader . getnchannels ( ) <= 2 ) , 'Audio must be mono or stereo' #NEWLINE# self . SAMPLE_WIDTH = self . audio_reader . getsampwidth ( ) #NEWLINE# self . SAMPLE_RATE = self . audio_reader . getframerate ( ) #NEWLINE# self . CHUNK = 4096 #NEWLINE# self . FRAME_COUNT = self . audio_reader . getnframes ( ) #NEWLINE# self . DURATION = ( self . FRAME_COUNT / float ( self . SAMPLE_RATE ) ) #NEWLINE# self . stream = AudioFile . AudioFileStream ( self . audio_reader , self . little_endian ) #NEWLINE# return self