LOGGER = logging.getLogger("AsyncProcess")
-DEFAULT_CHUNKSIZE = 1000000
+DEFAULT_CHUNKSIZE = 512000
class AsyncProcess:
async def __aexit__(self, exc_type, exc_value, traceback) -> bool:
"""Exit context manager."""
self._cancelled = True
- if await self.loop.run_in_executor(None, self._proc.poll) is None:
+ if self._proc.poll() is None:
# prevent subprocess deadlocking, send terminate and read remaining bytes
- await self.loop.run_in_executor(None, self._proc.terminate)
- await self.loop.run_in_executor(None, self.__read)
- del self._proc
+ def close_proc():
+ self._proc.terminate()
+ self._proc.stdin.close()
+ self._proc.stdout.read(-1)
+
+ await self.loop.run_in_executor(None, close_proc)
return exc_type not in (GeneratorExit, asyncio.CancelledError)
async def iterate_chunks(
fill_buffer_task = self.mass.loop.create_task(fill_buffer())
# start yielding audio chunks
- async for chunk in sox_proc.iterate_chunks(8000000):
+ chunk_size = sample_rate * 4 * 2 * 10
+ async for chunk in sox_proc.iterate_chunks(chunk_size):
yield chunk
await asyncio.wait([fill_buffer_task])
# start streaming
LOGGER.debug("Start streaming %s (%s)", queue_item_id, queue_item.name)
async for _, audio_chunk in self.async_get_sox_stream(
- streamdetails, gain_db_adjust=gain_correct, chunk_size=8000000
+ streamdetails, gain_db_adjust=gain_correct, chunk_size=4000000
):
yield audio_chunk
LOGGER.debug("Finished streaming %s (%s)", queue_item_id, queue_item.name)