|
20 | 20 |
|
21 | 21 | from viam.components.arm import Arm |
22 | 22 | from viam.components.audio_in import AudioIn, AudioResponse |
23 | | -from viam.components.audio_input import AudioInput |
24 | 23 | from viam.components.audio_out import AudioOut |
25 | 24 | from viam.components.base import Base |
26 | 25 | from viam.components.board import Board, TickStream |
|
35 | 34 | from viam.components.sensor import Sensor |
36 | 35 | from viam.components.servo import Servo |
37 | 36 | from viam.errors import ResourceNotFoundError |
38 | | -from viam.media.audio import Audio, AudioStream |
39 | 37 | from viam.media.video import CameraMimeType, NamedImage, ViamImage |
40 | 38 | from viam.operations import run_with_operation |
41 | 39 | from viam.proto.common import ( |
|
52 | 50 | Vector3, |
53 | 51 | ) |
54 | 52 | from viam.proto.component.arm import JointPositions |
55 | | -from viam.proto.component.audioin import AudioChunk as AudioInChunk |
56 | | -from viam.proto.component.audioinput import AudioChunk, AudioChunkInfo, SampleFormat |
57 | 53 | from viam.proto.component.encoder import PositionType |
58 | 54 | from viam.streams import StreamWithIterator |
59 | 55 | from viam.utils import SensorReading |
@@ -111,73 +107,6 @@ async def get_kinematics(self, extra: Optional[Dict[str, Any]] = None, **kwargs) |
111 | 107 | async def get_geometries(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> List[Geometry]: |
112 | 108 | return GEOMETRIES |
113 | 109 |
|
114 | | - |
115 | | -class ExampleAudioInput(AudioInput): |
116 | | - def __init__(self, name: str): |
117 | | - super().__init__(name) |
118 | | - self.latency = timedelta(milliseconds=20) |
119 | | - self.sample_rate = 48_000 |
120 | | - self.channel_count = 1 |
121 | | - self.step = 0 |
122 | | - self.timer = asyncio.get_event_loop().call_later(self.latency.total_seconds(), self.run_task) |
123 | | - |
124 | | - def run_task(self): |
125 | | - self.step += 1 |
126 | | - self.timer = asyncio.get_event_loop().call_later(self.latency.total_seconds(), self.run_task) |
127 | | - |
128 | | - def __del__(self): |
129 | | - self.timer.cancel() |
130 | | - |
131 | | - @run_with_operation |
132 | | - async def stream(self, **kwargs) -> AudioStream: |
133 | | - """Generate and stream a sine wave at 440Hz""" |
134 | | - operation = self.get_operation(kwargs) |
135 | | - |
136 | | - length = self.sample_rate * self.latency.total_seconds() # the length of the sample |
137 | | - num_chunks = self.sample_rate / length # the number of chunks needed |
138 | | - angle = math.pi * 2 / (length * num_chunks) |
139 | | - |
140 | | - async def read() -> AsyncIterator[Audio]: |
141 | | - while True: |
142 | | - if await operation.is_cancelled(): |
143 | | - break |
144 | | - output = bytes() |
145 | | - step = int(self.step % num_chunks) # current location on the sine wave |
146 | | - for i in range(int(length)): |
147 | | - value = float(10) * math.sin(angle * 440 * (float(length * step) + i)) # calculate the value at the current location |
148 | | - output += bytes(struct.pack("f", value)) |
149 | | - |
150 | | - yield Audio( |
151 | | - AudioChunkInfo( |
152 | | - sample_format=SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED, |
153 | | - channels=self.channel_count, |
154 | | - sampling_rate=self.sample_rate, |
155 | | - ), |
156 | | - AudioChunk( |
157 | | - data=output, |
158 | | - length=int(length), |
159 | | - ), |
160 | | - ) |
161 | | - |
162 | | - await asyncio.sleep(self.latency.total_seconds()) |
163 | | - |
164 | | - return StreamWithIterator(read()) |
165 | | - |
166 | | - async def get_properties(self) -> AudioInput.Properties: |
167 | | - return AudioInput.Properties( |
168 | | - channel_count=self.channel_count, |
169 | | - latency=self.latency, |
170 | | - sample_rate=self.sample_rate, |
171 | | - sample_size=4, |
172 | | - is_big_endian=sys.byteorder != "little", |
173 | | - is_float=True, |
174 | | - is_interleaved=True, |
175 | | - ) |
176 | | - |
177 | | - async def get_geometries(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> List[Geometry]: |
178 | | - return GEOMETRIES |
179 | | - |
180 | | - |
181 | 110 | class ExampleAudioIn(AudioIn): |
182 | 111 | def __init__(self, name: str): |
183 | 112 | super().__init__(name) |
|
0 commit comments