Esempio n. 1
0
def stream_wav(file_name):
    wav_file = AudioFile.query.filter_by(name=file_name).first()
    size = wav_file.size
    byte1, byte2, length = get_byte_range(request, size)
    vfs = get_azure_vfs()
    with vfs.open(wav_file.path + '/' + wav_file.name) as f:
        f.seek(byte1)
        data = f.read(length)
    response = Response(data,
                        206,
                        mimetype='audio/x-wav',
                        direct_passthrough=True)
    response.headers.add(
        'Content-Range', 'bytes {0}-{1}/{2}'.format(byte1, byte1 + length - 1,
                                                    size))
    return response
Esempio n. 2
0
def get_clip(file_name, offset):
    window_size = current_app.config['CLIP_SECS']
    wav_file = AudioFile.query.filter_by(name=file_name).first()
    fpath = wav_file.path + '/' + wav_file.name
    vfs = get_azure_vfs()
    with vfs.open(fpath) as f:
        with sf.SoundFile(f) as sf_desc:
            sr = sf_desc.samplerate
            pos = int(float(offset) * sr)
            sf_desc.seek(pos)
            frame_duration = int(window_size * sr)
            clip_data = sf_desc.read(frames=frame_duration)

    tmp_f = io.BytesIO()
    sf.write(tmp_f, clip_data, sr, format='WAV')
    tmp_f.seek(0)
    return tmp_f
Esempio n. 3
0
def stream_compressed(file_name, file_type):
    wav_file = AudioFile.query.filter_by(name=file_name).first()
    vfs = get_azure_vfs()
    with vfs.open(wav_file.path + '/' + wav_file.name) as f:
        out_f, output_mime = compress_audio(f, file_type)
    size = sys.getsizeof(out_f)
    byte1, byte2, length = get_byte_range(request, size)
    out_f.seek(byte1)
    data = out_f.read(length)
    response = Response(data,
                        206,
                        mimetype=output_mime,
                        direct_passthrough=True)
    response.headers.add(
        'Content-Range', 'bytes {0}-{1}/{2}'.format(byte1, byte1 + length - 1,
                                                    size))
    return response
Esempio n. 4
0
app = create_app()
app.app_context().push()

# get the Azure path from the command line
base_path = sys.argv[1]

try:
    t = time()
    imported = 0
    skipped = 0
    existing = 0
    moved = 0
    duplicate = 0

    vfs = get_azure_vfs()
    dir_contents = vfs.walk(base_path, details=True)
    for item in dir_contents:
        if item['type'] == 'FILE':
            path = Path(item['name'])
            name_ext = path.suffix
            if name_ext == '.wav':
                file_name = path.name
                file_path = str(path.parent)
                file_size = item['length']
                name_meta = path.stem.split('_')
                if len(name_meta) == 3:
                    sn = name_meta[0]
                    timestamp = datetime.strptime(
                        name_meta[1] + ' ' + name_meta[2], '%Y%m%d %H%M%S')
                    # check for existing records for the file name