async def test_large_chunk(self): chunk_audio = bytes(range(100)) large_chunk = audio.AudioChunk(time.time(), chunk_audio, 2, 16000) chunks = [] for chunk in audio.EvenChunkIterator(iter((large_chunk, )), 10): chunks.append(chunk) self.assertEqual(5, len(chunks)) self.assertEqual(large_chunk, audio.merge_chunks(chunks))
async def test_hello_44100_wave_get_chunk(self): path = os.path.join(os.path.dirname(__file__), 'test_data/hello_44100.wav') src = audio.WaveSource(path, chunk_frames=1000) chunks = [] async with src.listen(): async for chunk in src.chunks: chunks.append(chunk) for chunk in chunks[:-1]: self.assertEqual(2000, len(chunk.audio)) self.assertEqual(2, chunk.width) self.assertEqual(44100, chunk.freq) full_chunk = audio.merge_chunks(chunks) self.assertEqual(2, full_chunk.width) self.assertEqual(44100, full_chunk.freq)
async def test_split_join_chunk(self): chunk_audio = bytes(range(100)) chunk = audio.AudioChunk(time.time(), chunk_audio, 2, 16000) left_chunk, right_chunk = audio.split_chunk(chunk, 20) cmp_chunk = audio.merge_chunks((left_chunk, right_chunk)) self.assertEqual(chunk, cmp_chunk)