@@ -61,6 +61,20 @@ def __init__(
61
61
super ().__init__ ()
62
62
63
63
def get_audio_params (self , target : str ) -> AudioParams :
64
+ """
65
+ Retrieve audio parameters for a specified device.
66
+
67
+ Parameters
68
+ ----------
69
+ target : str
70
+ The name of the device for which to retrieve audio parameters.
71
+
72
+ Returns
73
+ -------
74
+ AudioParams
75
+ An `AudioParams` object containing the sample rate, input channels,
76
+ and output channels of the specified device.
77
+ """
64
78
return AudioParams (
65
79
self .devices [target ].sample_rate ,
66
80
self .devices [target ].in_channels ,
@@ -72,9 +86,47 @@ def configure_device(
72
86
target : str ,
73
87
config : SoundDeviceConfig ,
74
88
):
89
+ """
90
+ Configure and register a new audio device.
91
+
92
+ Parameters
93
+ ----------
94
+ target : str
95
+ The name identifier for the device to configure.
96
+ config : SoundDeviceConfig
97
+ The configuration settings to initialize the device with.
98
+
99
+ Notes
100
+ -----
101
+ The configured device is stored in `self.devices` under the given target name.
102
+ """
75
103
self .devices [target ] = SoundDeviceAPI (config )
76
104
77
105
def send_message (self , message : SoundDeviceMessage , target : str , ** kwargs ) -> None :
106
+ """
107
+ Send an audio message to a specified device.
108
+
109
+ Parameters
110
+ ----------
111
+ message : SoundDeviceMessage
112
+ The message containing audio data or control commands (e.g., stop or read request).
113
+ target : str
114
+ The name of the target device to which the message will be sent.
115
+ **kwargs
116
+ Additional keyword arguments (currently unused).
117
+
118
+ Raises
119
+ ------
120
+ SoundDeviceError
121
+ If the message requests reading (unsupported) or if no audio data is provided
122
+ when attempting to play audio.
123
+
124
+ Notes
125
+ -----
126
+ - If `message.stop` is `True`, the device will be stopped.
127
+ - If `message.read` is `True`, an error is raised (reading must use actions or services).
128
+ - Otherwise, attempts to write audio data to the device.
129
+ """
78
130
if message .stop :
79
131
self .devices [target ].stop ()
80
132
elif message .read :
@@ -90,6 +142,10 @@ def send_message(self, message: SoundDeviceMessage, target: str, **kwargs) -> No
90
142
def receive_message (
91
143
self , source : str , timeout_sec : float = 1.0 , ** kwargs
92
144
) -> SoundDeviceMessage :
145
+ """
146
+ SoundDeviceConnector does not support receiving messages. For recording use start_action or service_call with read=True.
147
+
148
+ """
93
149
raise SoundDeviceError (
94
150
"SoundDeviceConnector does not support receiving messages. For recording use start_action or service_call with read=True."
95
151
)
@@ -103,6 +159,41 @@ def service_call(
103
159
duration : float = 1.0 ,
104
160
** kwargs ,
105
161
) -> SoundDeviceMessage :
162
+ """
163
+ Perform a blocking service call to a sound device for playback or recording.
164
+
165
+ Depending on the message content, either records audio from the device or plays
166
+ provided audio data in a blocking manner.
167
+
168
+ Parameters
169
+ ----------
170
+ message : SoundDeviceMessage
171
+ The message specifying the operation: playback (with audio data) or recording (read flag).
172
+ target : str
173
+ The name of the target device on which to perform the action.
174
+ timeout_sec : float, optional
175
+ Timeout for the operation in seconds. Currently unused. Defaults to `1.0`.
176
+ duration : float, optional
177
+ Duration for recording audio in seconds. Only relevant when reading. Defaults to `1.0`.
178
+ **kwargs
179
+ Additional keyword arguments (currently unused).
180
+
181
+ Returns
182
+ -------
183
+ SoundDeviceMessage
184
+ A new message containing recorded audio if reading, or an empty message after successful playback.
185
+
186
+ Raises
187
+ ------
188
+ SoundDeviceError
189
+ If stopping is requested (unsupported in this method) or if playback is attempted
190
+ without providing audio data.
191
+
192
+ Notes
193
+ -----
194
+ - To stop a device, use `send_message` with `stop=True` instead.
195
+ - Audio recording is done synchronously with `blocking=True`.
196
+ """
106
197
if message .stop :
107
198
raise SoundDeviceError ("For stopping use send_message with stop=True." )
108
199
elif message .read :
@@ -128,6 +219,46 @@ def start_action(
128
219
timeout_sec : float = 1.0 ,
129
220
** kwargs ,
130
221
) -> str :
222
+ """
223
+ Start an asynchronous streaming action on a sound device.
224
+
225
+ Depending on the action data, either opens a read (recording) or write (playback)
226
+ audio stream. Handles for ongoing actions are tracked internally.
227
+
228
+ Parameters
229
+ ----------
230
+ action_data : SoundDeviceMessage, optional
231
+ The action request containing operation details. Must not be `None`.
232
+ If `read` is `True`, a read (recording) stream is opened; otherwise, a write (playback) stream.
233
+ target : str
234
+ The name of the target device to interact with.
235
+ on_feedback : Callable
236
+ Callback function to handle feedback during the stream.
237
+ on_done : Callable
238
+ Callback function called upon stream completion.
239
+ timeout_sec : float, optional
240
+ Timeout for starting the stream, in seconds. Defaults to `1.0`. (Currently unused.)
241
+ **kwargs
242
+ Additional parameters:
243
+ - `sample_rate` (int, optional): Desired sample rate for playback streams.
244
+ - `channels` (int, optional): Number of channels for playback streams.
245
+
246
+ Returns
247
+ -------
248
+ str
249
+ A unique handle identifying the started action.
250
+
251
+ Raises
252
+ ------
253
+ SoundDeviceError
254
+ If `action_data` is not provided (`None`).
255
+
256
+ Notes
257
+ -----
258
+ - For recording streams, `open_read_stream` is used.
259
+ - For playback streams, `open_write_stream` is used, optionally customized by `sample_rate` and `channels`.
260
+ - Started actions are stored in `self.action_handles` with the handle as the key.
261
+ """
131
262
handle = self ._generate_handle ()
132
263
if action_data is None :
133
264
raise SoundDeviceError ("action_data must be provided" )
0 commit comments