3434from viam .components .sensor import Sensor
3535from viam .components .servo import Servo
3636from viam .errors import ResourceNotFoundError
37- from viam .streams import StreamWithIterator
3837from viam .media .audio import Audio , AudioStream
3938from viam .media .video import CameraMimeType , NamedImage , ViamImage
4039from viam .operations import run_with_operation
4140from viam .proto .common import (
41+ AudioInfo ,
4242 Capsule ,
4343 Geometry ,
4444 GeoPoint ,
5151 Vector3 ,
5252)
5353from viam .proto .component .arm import JointPositions
54+ from viam .proto .component .audioin import AudioChunk as AudioInChunk
5455from viam .proto .component .audioinput import AudioChunk , AudioChunkInfo , SampleFormat
5556from viam .proto .component .encoder import PositionType
57+ from viam .streams import StreamWithIterator
5658from viam .utils import SensorReading
57- from viam .proto .component .audioin import AudioChunk as AudioInChunk
58- from viam .proto .common import AudioInfo
5959
6060GEOMETRIES = [
6161 Geometry (center = Pose (x = 1 , y = 2 , z = 3 , o_x = 2 , o_y = 3 , o_z = 4 , theta = 20 ), sphere = Sphere (radius_mm = 2 )),
@@ -188,9 +188,9 @@ def __init__(self, name: str):
188188 self .volume_scale = 0.2
189189 self .frequency_hz = 440
190190
191- async def get_audio (self , codec : str , duration_seconds : float , previous_timestamp_ns : int ,
192- * , timeout : Optional [float ] = None , ** kwargs ) -> AudioIn . AudioStream :
193-
191+ async def get_audio (
192+ self , codec : str , duration_seconds : float , previous_timestamp_ns : int , * , timeout : Optional [float ] = None , ** kwargs
193+ ) -> AudioIn . AudioStream :
194194 async def read () -> AsyncIterator [AudioIn .AudioResponse ]:
195195 # Generate chunks based on duration
196196 chunk_duration_ms = 100 # 100ms per chunk
@@ -209,22 +209,18 @@ async def read() -> AsyncIterator[AudioIn.AudioResponse]:
209209 amplitude = int (32767 * self .volume_scale * math .sin (2 * math .pi * self .frequency_hz * time_offset ))
210210
211211 # Convert to 16-bit PCM stereo
212- sample_bytes = amplitude .to_bytes (2 , byteorder = ' little' , signed = True )
212+ sample_bytes = amplitude .to_bytes (2 , byteorder = " little" , signed = True )
213213 chunk_data += sample_bytes * self .num_channels
214214
215215 chunk_start_time = previous_timestamp_ns + (i * chunk_duration_ms * 1000000 ) # Convert ms to ns
216216 chunk_end_time = chunk_start_time + (chunk_duration_ms * 1000000 )
217217
218218 audio_chunk = AudioInChunk (
219219 audio_data = bytes (chunk_data ),
220- audio_info = AudioInfo (
221- codec = codec ,
222- sample_rate_hz = int (self .sample_rate ),
223- num_channels = self .num_channels
224- ),
220+ audio_info = AudioInfo (codec = codec , sample_rate_hz = int (self .sample_rate ), num_channels = self .num_channels ),
225221 sequence = i ,
226222 start_timestamp_nanoseconds = chunk_start_time ,
227- end_timestamp_nanoseconds = chunk_end_time
223+ end_timestamp_nanoseconds = chunk_end_time ,
228224 )
229225 audio_response = AudioResponse (audio = audio_chunk )
230226 yield audio_response
@@ -235,11 +231,7 @@ async def read() -> AsyncIterator[AudioIn.AudioResponse]:
235231
236232 async def get_properties (self , * , timeout : Optional [float ] = None , ** kwargs ) -> AudioIn .Properties :
237233 """Return the audio input device properties."""
238- return AudioIn .Properties (
239- supported_codecs = self .supported_codecs ,
240- sample_rate_hz = self .sample_rate ,
241- num_channels = self .num_channels
242- )
234+ return AudioIn .Properties (supported_codecs = self .supported_codecs , sample_rate_hz = self .sample_rate , num_channels = self .num_channels )
243235
244236 async def get_geometries (self , extra : Optional [Dict [str , Any ]] = None , ** kwargs ) -> List [Geometry ]:
245237 return GEOMETRIES
@@ -254,39 +246,36 @@ def __init__(self, name: str):
254246 self .volume = 1.0
255247 self .is_playing = False
256248
257- async def play (self ,
258- data : bytes ,
259- info : Optional [AudioInfo ] = None ,
260- * ,
261- extra : Optional [Dict [str , Any ]] = None ,
262- timeout : Optional [float ] = None ,
263- ** kwargs ) -> None :
249+ async def play (
250+ self ,
251+ data : bytes ,
252+ info : Optional [AudioInfo ] = None ,
253+ * ,
254+ extra : Optional [Dict [str , Any ]] = None ,
255+ timeout : Optional [float ] = None ,
256+ ** kwargs ,
257+ ) -> None :
264258 """Play the given audio data."""
265259
266260 # Simulate playing audio
267261 self .is_playing = True
268262 if info :
269- print (f"Playing audio: { len (data )} bytes, codec={ info .codec } , "
270- f"sample_rate={ info .sample_rate_hz } , channels={ info .num_channels } " )
263+ print (
264+ f"Playing audio: { len (data )} bytes, codec={ info .codec } , " f"sample_rate={ info .sample_rate_hz } , channels={ info .num_channels } "
265+ )
271266 else :
272267 print (f"Playing audio: { len (data )} bytes (no audio info provided)" )
273268
274269 await asyncio .sleep (0.1 )
275270
276271 self .is_playing = False
277272
278- async def get_properties (self ,
279- * ,
280- extra : Optional [Dict [str , Any ]] = None ,
281- timeout : Optional [float ] = None ,
282- ** kwargs ) -> AudioOut .Properties :
273+ async def get_properties (
274+ self , * , extra : Optional [Dict [str , Any ]] = None , timeout : Optional [float ] = None , ** kwargs
275+ ) -> AudioOut .Properties :
283276 """Return the audio output device properties."""
284277
285- return AudioOut .Properties (
286- supported_codecs = self .supported_codecs ,
287- sample_rate_hz = self .sample_rate ,
288- num_channels = self .num_channels
289- )
278+ return AudioOut .Properties (supported_codecs = self .supported_codecs , sample_rate_hz = self .sample_rate , num_channels = self .num_channels )
290279
291280 async def get_geometries (self , extra : Optional [Dict [str , Any ]] = None , ** kwargs ) -> List [Geometry ]:
292281 return GEOMETRIES
@@ -627,6 +616,9 @@ async def is_moving(self):
627616 async def get_geometries (self , extra : Optional [Dict [str , Any ]] = None , ** kwargs ) -> List [Geometry ]:
628617 return GEOMETRIES
629618
619+ async def get_kinematics (self , * , extra = None , timeout = None , ** kwargs ) -> Tuple [KinematicsFileFormat .ValueType , bytes ]:
620+ return (KinematicsFileFormat .KINEMATICS_FILE_FORMAT_UNSPECIFIED , b"abc" )
621+
630622
631623class ExampleGripper (Gripper ):
632624 def __init__ (self , name : str ):
@@ -647,12 +639,7 @@ async def grab(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> bool:
647639 self .holding_something = random .choice ([True , False ])
648640 return self .holding_something
649641
650- async def is_holding_something (
651- self ,
652- * ,
653- extra : Optional [Dict [str , Any ]] = None ,
654- ** kwargs
655- ) -> Gripper .HoldingStatus :
642+ async def is_holding_something (self , * , extra : Optional [Dict [str , Any ]] = None , ** kwargs ) -> Gripper .HoldingStatus :
656643 return Gripper .HoldingStatus (self .holding_something )
657644
658645 async def stop (self , extra : Optional [Dict [str , Any ]] = None , ** kwargs ):
0 commit comments