a method to transcribe the text from an audio url

        :param file_path: string with url to audio file on web
        :param clip_length: [optional] integer with seconds to divide clips into
        :param compress: [optional] boolean to convert file to audio/ogg
        :return: dictionary with transcribed text segments in 'segments' key

def transcribe_url(self, file_url, clip_length=None, compress=True):

        '''
            a method to transcribe the text from an audio url

        :param file_path: string with url to audio file on web
        :param clip_length: [optional] integer with seconds to divide clips into
        :param compress: [optional] boolean to convert file to audio/ogg
        :return: dictionary with transcribed text segments in 'segments' key
        '''

        title = '%s.transcribe_url' % self.__class__.__name__

    # validate inputs
        input_fields = {
            'file_url': file_url,
        }
        if clip_length is not None:
            input_fields['clip_length'] = clip_length
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)

    # construct empty file details
        file_details = {
            'name': '',
            'mimetype': '',
            'extension': ''
        }

    # retrieve file name
        from urllib.parse import urlsplit
        file_arg = '%s(file_url=%s)' % (title, str(file_url))
        url_path = urlsplit(file_url).path
        path_segments = url_path.split('/')
        file_details['name'] = path_segments[-1]
        if not file_details['name']:
            raise ValueError('%s must have a file name.' % file_arg)

    # validate file extension
        ext_kwargs = {
            'file_name': file_details['name'],
            'extension_map': self.fields.schema['audio_extensions'],
            'method_title': title,
            'argument_title': 'file_url'
        }
        file_details = self._validate_extension(**ext_kwargs)

    # retrieve file data
        file_buffer = self._get_data(file_url, file_details['name'], title, 'file_url')
        if isinstance(file_buffer, dict):
            raise Exception(str(file_buffer))

    # validate file mimetype
        if self.magic:
            file_data = file_buffer.getvalue()
            magic_details = self.magic.analyze(byte_data=file_data)
            mimetype_text = file_details['mimetype'][6:]
            if mimetype_text not in magic_details['mimetype']:
                raise ValueError('%s byte data mimetype %s does not match %s file extension.' % (file_arg, magic_details['mimetype'], file_details['extension']))

    # construct default return
        transcript_details = {
            'error': '',
            'segments': []
        }

    # transcribe entire buffer
        if clip_length is None:
            try:
                file_data = file_buffer.getvalue()
                transcript = self.client.recognize(file_data, file_details['mimetype'], continuous=True)
                if transcript['results']:
                    for result in transcript['results']:
                        transcript_details['segments'].append(result['alternatives'][0])
            except Exception as err:
                transcript_details['error'] = err

    # save buffer to disk, segment and transcribe in multiple threads
        else:
            import os
            from time import sleep
            from math import ceil
            from moviepy.editor import AudioFileClip

        # save buffer to disk
            clip_folder = self._create_folder()
            full_name = 'audio_full.%s' % file_details['extension']
            full_path = os.path.join(clip_folder, full_name)
            with open(full_path, 'wb') as f:
                f.write(file_buffer.getvalue())
                f.close()

        # convert file
            if compress:
                file_name, file_extension = os.path.splitext(full_path)
                if file_extension != '.ogg':
                    full_path = self.convert_audio(full_path, 'audio/ogg', True)
                    file_details = {
                        'name': 'audio_full.ogg',
                        'extension': '.ogg',
                        'mimetype': 'audio/ogg'
                    }

        # open audio file
            count = 0
            retry_count = 10
            while True:
                try:
                    audio = AudioFileClip(full_path)
                    break
                except PermissionError:
                    sleep(.05)
                    count += 1
                    if count > retry_count:
                        raise
            audio_duration = audio.duration

        # construct list of files to transcribe
            file_list = []
            if audio_duration < clip_length:
                file_list.append(full_path)
            else:

        # create temporary audio files
                count = 0
                t_start = 0
                while t_start < audio_duration:
                    t_end = t_start + clip_length
                    if t_end > audio_duration:
                        t_end = ceil(audio_duration)
                        segment = audio.subclip(t_start)
                    else:
                        segment = audio.subclip(t_start, t_end)
                    clip_name = 'audio%s.%s' % (count, file_details['extension'])
                    clip_path = os.path.join(clip_folder, clip_name)
                    segment.write_audiofile(clip_path, verbose=False)
                    file_list.append(clip_path)
                    count += 1
                    t_start = t_end

        # run file transcription method
            transcript_details = self._transcribe_files(file_list, file_details['mimetype'])

        # remove temp files
            if len(file_list) > 1:
                from labpack.records.settings import remove_settings
                for file in file_list:
                    remove_settings(file, remove_dir=True)

        return transcript_details