Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-samples-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- "src/viam/components/sensor/sensor.py"
- "src/viam/components/servo/servo.py"
- "src/viam/components/arm/arm.py"
- "src/viam/components/audio_input/audio_input.py"

- "src/viam/components/gantry/gantry.py"
- "src/viam/components/gripper/gripper.py"
- "src/viam/components/input/input.py"
Expand Down
71 changes: 0 additions & 71 deletions examples/server/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from viam.components.arm import Arm
from viam.components.audio_in import AudioIn, AudioResponse
from viam.components.audio_input import AudioInput
from viam.components.audio_out import AudioOut
from viam.components.base import Base
from viam.components.board import Board, TickStream
Expand All @@ -34,7 +33,6 @@
from viam.components.sensor import Sensor
from viam.components.servo import Servo
from viam.errors import ResourceNotFoundError
from viam.media.audio import Audio, AudioStream
from viam.media.video import CameraMimeType, NamedImage, ViamImage
from viam.operations import run_with_operation
from viam.proto.common import (
Expand All @@ -51,8 +49,6 @@
Vector3,
)
from viam.proto.component.arm import JointPositions
from viam.proto.component.audioin import AudioChunk as AudioInChunk
from viam.proto.component.audioinput import AudioChunk, AudioChunkInfo, SampleFormat
from viam.proto.component.encoder import PositionType
from viam.streams import StreamWithIterator
from viam.utils import SensorReading
Expand Down Expand Up @@ -110,73 +106,6 @@ async def get_kinematics(self, extra: Optional[Dict[str, Any]] = None, **kwargs)
async def get_geometries(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> List[Geometry]:
return GEOMETRIES


class ExampleAudioInput(AudioInput):
def __init__(self, name: str):
super().__init__(name)
self.latency = timedelta(milliseconds=20)
self.sample_rate = 48_000
self.channel_count = 1
self.step = 0
self.timer = asyncio.get_event_loop().call_later(self.latency.total_seconds(), self.run_task)

def run_task(self):
self.step += 1
self.timer = asyncio.get_event_loop().call_later(self.latency.total_seconds(), self.run_task)

def __del__(self):
self.timer.cancel()

@run_with_operation
async def stream(self, **kwargs) -> AudioStream:
"""Generate and stream a sine wave at 440Hz"""
operation = self.get_operation(kwargs)

length = self.sample_rate * self.latency.total_seconds() # the length of the sample
num_chunks = self.sample_rate / length # the number of chunks needed
angle = math.pi * 2 / (length * num_chunks)

async def read() -> AsyncIterator[Audio]:
while True:
if await operation.is_cancelled():
break
output = bytes()
step = int(self.step % num_chunks) # current location on the sine wave
for i in range(int(length)):
value = float(10) * math.sin(angle * 440 * (float(length * step) + i)) # calculate the value at the current location
output += bytes(struct.pack("f", value))

yield Audio(
AudioChunkInfo(
sample_format=SampleFormat.SAMPLE_FORMAT_FLOAT32_INTERLEAVED,
channels=self.channel_count,
sampling_rate=self.sample_rate,
),
AudioChunk(
data=output,
length=int(length),
),
)

await asyncio.sleep(self.latency.total_seconds())

return StreamWithIterator(read())

async def get_properties(self) -> AudioInput.Properties:
return AudioInput.Properties(
channel_count=self.channel_count,
latency=self.latency,
sample_rate=self.sample_rate,
sample_size=4,
is_big_endian=sys.byteorder != "little",
is_float=True,
is_interleaved=True,
)

async def get_geometries(self, extra: Optional[Dict[str, Any]] = None, **kwargs) -> List[Geometry]:
return GEOMETRIES


class ExampleAudioIn(AudioIn):
def __init__(self, name: str):
super().__init__(name)
Expand Down
3 changes: 0 additions & 3 deletions examples/server/v1/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
ExampleAnalog,
ExampleArm,
ExampleAudioIn,
ExampleAudioInput,
ExampleAudioOut,
ExampleBase,
ExampleBoard,
Expand All @@ -31,7 +30,6 @@

async def run(host: str, port: int, log_level: int):
my_arm = ExampleArm("arm0")
my_audio_input = ExampleAudioInput("audio_input0")
my_audio_in = ExampleAudioIn("audio_in0")
my_audio_out = ExampleAudioOut("audio_out0")
my_base = ExampleBase("base0")
Expand Down Expand Up @@ -80,7 +78,6 @@ async def run(host: str, port: int, log_level: int):
resources=[
my_arm,
my_audio_in,
my_audio_input,
my_audio_out,
my_base,
my_board,
Expand Down
18 changes: 0 additions & 18 deletions src/viam/components/audio_input/__init__.py

This file was deleted.

82 changes: 0 additions & 82 deletions src/viam/components/audio_input/audio_input.py

This file was deleted.

77 changes: 0 additions & 77 deletions src/viam/components/audio_input/client.py

This file was deleted.

Loading
Loading