22import numpy as np
33import contextlib
44from dataclasses import dataclass
5- from typing import AsyncIterator , Optional
5+ from typing import AsyncIterable , Optional
66from .audio_frame import AudioFrame
77from .log import logger
88
9- _Stream = AsyncIterator [AudioFrame ]
9+ _Stream = AsyncIterable [AudioFrame ]
1010
1111
1212@dataclass
@@ -21,9 +21,9 @@ class _Contribution:
2121class AudioMixer :
2222 def __init__ (
2323 self ,
24- * ,
2524 sample_rate : int ,
2625 num_channels : int ,
26+ * ,
2727 blocksize : int = 0 ,
2828 stream_timeout_ms : int = 100 ,
2929 capacity : int = 100 ,
@@ -62,7 +62,7 @@ def __init__(
6262 self ._ending : bool = False
6363 self ._mixer_task : asyncio .Task = asyncio .create_task (self ._mixer ())
6464
65- def add_stream (self , stream : AsyncIterator [AudioFrame ]) -> None :
65+ def add_stream (self , stream : AsyncIterable [AudioFrame ]) -> None :
6666 """
6767 Add an audio stream to the mixer.
6868
@@ -79,7 +79,7 @@ def add_stream(self, stream: AsyncIterator[AudioFrame]) -> None:
7979 if stream not in self ._buffers :
8080 self ._buffers [stream ] = np .empty ((0 , self ._num_channels ), dtype = np .int16 )
8181
82- def remove_stream (self , stream : AsyncIterator [AudioFrame ]) -> None :
82+ def remove_stream (self , stream : AsyncIterable [AudioFrame ]) -> None :
8383 """
8484 Remove an audio stream from the mixer.
8585
@@ -169,7 +169,7 @@ async def _mixer(self) -> None:
169169 await self ._queue .put (None )
170170
171171 async def _get_contribution (
172- self , stream : AsyncIterator [AudioFrame ], buf : np .ndarray
172+ self , stream : AsyncIterable [AudioFrame ], buf : np .ndarray
173173 ) -> _Contribution :
174174 had_data = buf .shape [0 ] > 0
175175 exhausted = False
0 commit comments