Args:
        filename: Audio filename
512327
def play_audio(filename: str):
    
    import platform
    from subprocess import Popen

    player = 'play' if platform.system() == 'Darwin' else 'aplay'
    Popen([player, '-q', filename])
208521
def _filenames_from_arg(filename):
    """"""
    if isinstance(filename, string_types):
        filenames = [filename]
    elif isinstance(filename, (list, tuple)):
        filenames = filename
    else:
        raise Exception('filename argument must be string, list or tuple')
    for fn in filenames:
        if not os.path.exists(fn):
            raise ValueError('file not found: %s' % fn)
        if not os.path.isfile(fn):
            raise ValueError('not a file: %s' % fn)
    return filenames
265387
def parse_arguments(args=sys.argv[1:]):
    """"""
    cmd_description = "Download tracklistings for BBC radio shows.\n\n" \
                      "Saves to a text file, tags audio file or does both.\n" \
                      "To select output file, filename " \
                      "must both be specified.\n" \
                      "If directory is not specified, directory is assumed" \
                      "to be where script is.\n" \
                      "Filename is the prefix, for someaudio.m4a, use " \
                      "--filename someaudio\n" \
                      "Otherwise, an attempt will be made to write " \
                      "text file to current directory.\n" \
                      "If choosing 'both', directory and filename should " \
                      "point to audio file.\n" \
                      "In this case, text file will have same name " \
                      "as audio file, but with .txt"

    # http://stackoverflow.com/questions/7869345/
    parser = ArgumentParser(formatter_class=RawTextHelpFormatter,
                            description=cmd_description)
    action_help = "tag: tag audio file with tracklisting\n" \
                  "text: write tracklisting to text file (default)\n" \
                  "both: tag audio file and write to text file"
    parser.add_argument('action', choices=('tag', 'text', 'both'),
                        default='text', help=action_help)
    parser.add_argument('pid', help="BBC programme id, e.g. b03fnc82")
    parser.add_argument('--directory', help="output directory")
    parser.add_argument('--fileprefix', help="output filename prefix")
    return parser.parse_args()
625224
public synchronized void setFilename(String filename)
    {
        if (filename!=null)
        {
            filename=filename.trim();
            if (filename.length()==0)
                filename=null;
        }
        
        if (isStarted() && _filename!=null && filename==null)
            _out=null;
        
        _reopen=isStarted() &&
            ((_filename==null && filename!=null)||
             (_filename!=null && !_filename.equals(filename)));
        _filename=filename;

        if (!isStarted() && _filename!=null)
            _out=null;
    }
767182
def filename_match(filename, patterns, default=True):
    
    if not patterns:
        return default
    return any(fnmatch(filename, pattern) for pattern in patterns)
6641
def runfile(self, filename, args=None):
        
        if args is not None and not is_text_string(args):
            raise TypeError("expected a character buffer object")
        self.namespace['__file__'] = filename
        sys.argv = [filename]
        if args is not None:
            for arg in args.split():
                sys.argv.append(arg)
        self.execfile(filename)
        sys.argv = ['']
        self.namespace.pop('__file__')
110506
def safe_filename(file_name, sep='_', default=None, extension=None):
    """"""
    if file_name is None:
        return decode_path(default)

    file_name = decode_path(file_name)
    file_name = os.path.basename(file_name)
    file_name, _extension = os.path.splitext(file_name)
    file_name = _safe_name(file_name, sep=sep)
    if file_name is None:
        return decode_path(default)
    file_name = file_name[:MAX_LENGTH]
    extension = _safe_name(extension or _extension, sep=sep)
    if extension is not None:
        file_name = '.'.join((file_name, extension))
        file_name = file_name[:MAX_LENGTH]
    return file_name
998941
def write_wav(self, filename):
        

        wave_output = None
        try:
            wave_output = wave.open(filename, 'w')

            wave_output.setparams(WAVE_PARAMS)

            frames = bytearray([x << 4 for x in self.sample_data])

            wave_output.writeframes(frames)
        finally:
            if wave_output is not None:
                wave_output.close()
697672
def to_file(self, filename):
        
        filename = os.path.expanduser(filename)
        libfn = utils.get_lib_fn('toFile%s'%self._libsuffix)
        libfn(self.pointer, filename)
1062923
def _startRecording(self, filename):
        
        self.setOption('_log_file_name', filename)
        self.setOption('_log_input_only', True)
        self.setOption('_log', True)
1278741
def get_audio_metadata(fname):
    
    from mutagenx.easyid3 import EasyID3
    audio = EasyID3(fname)
    audio_dict = {}
    
    try:
        artist = audio["artist"]
    except KeyError:
        artist = ''
        
    try:    
        title = audio["title"]
    except KeyError:
        print("Cant get title")
        
    try:
        album = audio["album"]
    except KeyError:
        album = ''
        
    
    audio_dict['album'] = album
    audio_dict['title'] = title
    audio_dict['artist'] = artist
    
    return audio_dict
291388
def _workout_filename(filename):
    '''
    
    '''
    if os.path.isfile(filename) or filename == '/':
        if filename == '/':
            filename = None
        return filename
    else:
        return _workout_filename(os.path.dirname(filename))
293587
def write(self, filename):
        
        if not filename.endswith(('.mid', '.midi', '.MID', '.MIDI')):
            filename = filename + '.mid'
        pm = self.to_pretty_midi()
        pm.write(filename)
1002322
def from_filename(self, filename):
        '''
        
        '''
        i = len(self.base_directory)
        if filename[:i] != self.base_directory:
            raise ValueError('Filename needs to start with "%s";\nyou passed "%s".' % (self.base_directory, filename))

        if filename.endswith(self.extension):
            if len(self.extension) > 0:
                j = -len(self.extension)
            else:
                j = None
            return self.key_transformer.from_path(tuple(filename[i:j].strip('/').split('/')))
10349
def read_wav(self, filename):
        
        wave_input = None

        try:
            wave_input = wave.open(filename, 'r')
            wave_frames = bytearray(
                wave_input.readframes(wave_input.getnframes()))

            self.sample_data = [x >> 4 for x in wave_frames]

        finally:
            if wave_input is not None:
                wave_input.close()
791312
def _addFilename(self, filename):
        
        cur = self._connection.cursor()
        try:
            cur.execute('INSERT INTO files(name) VALUES (?)', (filename,))
        except sqlite3.IntegrityError as e:
            if str(e).find('UNIQUE constraint failed') > -1:
                raise ValueError('Duplicate file name: %r' % filename)
            else:
                raise
        else:
            fileNumber = cur.lastrowid
            self._connection.commit()
            return fileNumber
962906
def __filename_to_modname(self, pathname):
        
        filename = PathOperations.pathname_to_filename(pathname)
        if filename:
            filename = filename.lower()
            filepart, extpart = PathOperations.split_extension(filename)
            if filepart and extpart:
                modName = filepart
            else:
                modName = filename
        else:
            modName = pathname
        return modName