AudioIO Objects¶
Provide real time audio playback and recording, with special classes to concurrently read input audio.
- class pytta.Streaming(IO: str, samplingRate: int, device: int, datatype: str = 'float32', blocksize: int = 0, inChannels: Optional[ChannelsList] = None, outChannels: Optional[ChannelsList] = None, excitation: Optional[SignalObj] = None, duration: Optional[float] = None, numSamples: Optional[int] = None, monitor: Optional[Monitor] = None, *args, **kwargs)[source]¶
Stream control.
- __init__(IO: str, samplingRate: int, device: int, datatype: str = 'float32', blocksize: int = 0, inChannels: Optional[ChannelsList] = None, outChannels: Optional[ChannelsList] = None, excitation: Optional[SignalObj] = None, duration: Optional[float] = None, numSamples: Optional[int] = None, monitor: Optional[Monitor] = None, *args, **kwargs)[source]¶
Manage input and output of audio.
- Parameters:
IO (str) – DESCRIPTION.
msmnt (Measurement) – DESCRIPTION.
datatype (str, optional) – DESCRIPTION. Defaults to ‘float32’.
blocksize (int, optional) – DESCRIPTION. Defaults to 0.
duration (Optional[float], optional) – DESCRIPTION. Defaults to 5.
monitor (Optional[Monitor], optional) – DESCRIPTION. Defaults to None.
*args (TYPE) – DESCRIPTION.
**kwargs (TYPE) – DESCRIPTION.
- Returns:
None.
- __enter__()[source]¶
Provide context functionality, the with keyword, e.g.
>>> with Streaming(*args, **kwargs) as strm: # <-- called here ... strm.playrec() ... >>>
- __exit__(exc_type: Type, exc_val: Exception, exc_tb: Type)[source]¶
Provide context functionality, the with keyword, e.g.
>>> with Streaming(*args, **kwargs) as strm: ... strm.playrec() ... # <-- called here >>>
- set_io_properties(io: str, channels: ChannelsList)[source]¶
Allocate memory for input and output of data, set counter.
- Parameters:
msmnt (TYPE) – DESCRIPTION.
- Returns:
None.
- set_monitoring(monitor: Optional[Monitor] = None)[source]¶
Set up the class used as monitor. It must have the following methods with these names.
def setup(None) -> None:
_Call any function and other object configuration needed for the monitoring_ return
- def callback(indata: np.ndarray, outdata: np.ndarray,
frames: int, status: sd.CallbackFlags) -> None:
_Process the data gathered from the stream_ return
It will be called from within a parallel process that the Recorder starts and terminates during it’s .run() call.
- Parameters:
monitor (object) – Object or class that will be used to monitor the stream data flow.
- runner(StreamType: Type, stream_callback: Callable, numchannels: Union[List[int], int])[source]¶
Do the work.
Instantiates a sounddevice.*Stream and calls for a threading.Thread if any Monitor is set up. Then turn on the monitorCheck Event, and starts the stream. Waits for it to finish, unset the event And terminates the process
- Returns:
- Return type:
- input_callback(indata: ndarray, frames: int, times: type, status: CallbackFlags)[source]¶
This method will be called from the stream, as stated on sounddevice’s documentation.
- class pytta.Monitor(numsamples: int, samplingrate: int = 44100, numchannels: List[int] = [1, 1], datatype: str = 'float32')[source]¶
PyTTa default Monitor base class.
- __init__(numsamples: int, samplingrate: int = 44100, numchannels: List[int] = [1, 1], datatype: str = 'float32')[source]¶
Default Monitor class.
Subclasses must override setup, callback and tear_down methods.
- Parameters:
numsamples (int) – DESCRIPTION.
samplingrate (int, optional) – DESCRIPTION. The default is default.samplingRate.
numchannels (List[int], optional) – DESCRIPTION. The default is [len(default.inChannel), len(default.outChannel)].
datatype (str, optional) – DESCRIPTION. The default is ‘float32’.
- Return type:
None.