예제 #1
0
 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))
예제 #2
0
    async def test_uneven_chunks(self):
        audio1 = b'\0\0' * 160
        audio2 = b'\0\0' * 80
        audio3 = b'\0\0' * 240

        audios = (audio1, audio2, audio3)
        chunks = [audio.AudioChunk(time.time(), x, 2, 16000) for x in audios]

        for chunk in audio.EvenChunkIterator(iter(chunks), 100):
            self.assertEqual(200, len(chunk.audio))
예제 #3
0
    async def test_uneven_chunks(self):
        audio1 = b'\0\0' * 160
        audio2 = b'\0\0' * 80
        audio3 = b'\0\0' * 240

        audios = (audio1, audio2, audio3)
        chunks = [
            audio.AudioChunk(time.time(), sample, 2, 16000)
            for sample in audios
        ]
        chunk_iter = AListIter(chunks)

        async for chunk in audio.EvenChunkIterator(chunk_iter, 100):
            self.assertEqual(200, len(chunk.audio))
예제 #4
0
 def gen_sample(self, start_time, sample_cnt):
     sample = b'\0\0' * sample_cnt
     return audio.AudioChunk(start_time=start_time,
                             audio=sample,
                             width=2,
                             freq=self._sample_rate)
예제 #5
0
 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)