Exemplo n.º 1
0
async def end_file(file):
    "Put file in closed state"
    log.info(f"No recent modifications to {file.path}, scheduling analysis.")
    # try:
    #     proc = await asyncio.create_subprocess_shell(f'md5sum {file.path}', stdout=subprocess.PIPE)
    #     await proc.wait()
    #     return_val = await proc.stdout.readline()
    #     hash_val = return_val.split(b' ')[0]
    #     file.hash = hash_val
    #     file.save()
    # except (subprocess.CalledProcessError, ValueError) as e:
    #     log.error(e)
    if file.path.exists():
        async with aiofile.AIOFile(file.path, 'rb') as afile:
            ha = hashlib.md5()
            rdr = aiofile.Reader(afile, chunk_size=1024 * 1024)
            async for chunk in rdr:
                ha.update(chunk)
            file.hash = ha.hexdigest()
            file.save()
        for job in JOBS.FILES:
            log.info(f"Scheduling job {type(job).__name__} on {file.path}")
            file.spawn(job)
    else:
        TagJunction.delete().where(file == file).execute()
        TTagJunction.delete().where(file == file).execute()
        file.delete_instance()
    async def write_chunks():

        async with aiofile.AIOFile(file, 'rb') as afp:
            reader = aiofile.Reader(afp, chunk_size=media_sample_rate_hz * 1.024)
            async for chunk in reader:
                await stream.input_stream.send_audio_event(audio_chunk=chunk)
     
        await stream.input_stream.end_stream()
Exemplo n.º 3
0
 async def write_chunks():
     # An example file can be found at tests/integration/assets/test.wav
     # NOTE: For pre-recorded files longer than 5 minutes, the sent audio
     # chunks should be rate limited to match the realtime bitrate of the
     # audio stream to avoid signing issues.
     async with aiofile.AIOFile("tests/record.wav", "rb") as afp:
         reader = aiofile.Reader(afp, chunk_size=1024 * 16)
         async for chunk in reader:
             await stream.input_stream.send_audio_event(audio_chunk=chunk)
     await stream.input_stream.end_stream()
Exemplo n.º 4
0
 async def write_chunks():
     # An example file can be found at tests/integration/assets/test.wav
     # NOTE: For pre-recorded files longer than 5 minutes, the sent audio
     # chunks should be rate limited to match the realtime bitrate of the
     # audio stream to avoid signing issues.
     async with aiofile.AIOFile(
             "/Users/thunt/Downloads/5ab118cd-d252-4e5a-b5d0-b158f7c399c4-45.wav",
             "rb+") as afp:
         print("Reading file: %s", afp)
         reader = aiofile.Reader(afp, chunk_size=1024 * 16)
         async for chunk in reader:
             print("writing chunk...", len(chunk))
             await stream.input_stream.send_audio_event(audio_chunk=chunk)
             print("sent chunk...")
     print("ending stream....", stream)
     await stream.input_stream.end_stream()
Exemplo n.º 5
0
 async def write_chunks():
     async with aiofile.AIOFile(wavfile, 'rb') as afp:
         reader = aiofile.Reader(afp, chunk_size=1024 * 16)
         async for chunk in reader:
             await stream.input_stream.send_audio_event(audio_chunk=chunk)
         await stream.input_stream.end_stream()
Exemplo n.º 6
0
async def tokenize_in_fixed_chunks(f: aiofile.AIOFile) \
        -> AsyncIterator[Tuple[int, bytes]]:
    reader = aiofile.Reader(f, chunk_size=CHUNK_SIZE_IN_BYTES)
    async for i, chunk in async_enumerate(reader):
        yield i, chunk