generated from pollen-robotics/python-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 106-improve-code-documentation
- Loading branch information
Showing
17 changed files
with
311 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
# Python SDK for Reachy v2 | ||
# Python SDK for Reachy v2 | ||
|
||
## Install | ||
|
||
```console | ||
$ pip install -e .[pollen,dev] | ||
``` | ||
|
||
*[dev]* contains the tools for developers. | ||
*[pollen]* has the custom pollen robotics repos. It is mandatory but not in the default install because github actions cannot fetch private repo directly. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.isort] | ||
profile = "black" | ||
|
||
[tool.black] | ||
line-length = 128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
[metadata] | ||
name = reachy-v2-sdk | ||
version = 0.1.0 | ||
version = 2.0 | ||
author = Pollen Robotics | ||
author_email = [email protected] | ||
url = https://github.com/pollen-robotics/python-template | ||
description = Python template project | ||
url = https://github.com/pollen-robotics/reachy-v2-sdk | ||
description = Reachy SDK V2 | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
|
||
|
||
[options] | ||
packages = find: | ||
packages = reachy_v2_sdk | ||
zip_safe = True | ||
include_package_data = True | ||
package_dir= | ||
=src | ||
install_requires = | ||
numpy | ||
numpy==1.26.1 | ||
protobuf==4.25.0 | ||
grpcio==1.59.2 | ||
pyquaternion==0.9.9 | ||
|
||
[options.packages.find] | ||
where=reachy_sdk | ||
|
||
[options.extras_require] | ||
dev = black==23.3.0 | ||
flake8==6.0.0 | ||
pytest==7.3.1 | ||
coverage==7.2.5 | ||
mypy==1.0.0 | ||
dev = black==23.10.1 | ||
flake8==6.1.0 | ||
pytest==7.4.3 | ||
coverage==7.3.2 | ||
mypy==1.6.1 | ||
isort==5.12.0 | ||
types-protobuf==4.24.0.1 | ||
|
||
[options.entry_points] | ||
console_scripts = | ||
example_entry_point = example.celcius:main | ||
pollen = reachy-sdk-api-v2@git+ssh://[email protected]/pollen-robotics/reachy-sdk-api-v2.git#subdirectory=python | ||
|
||
[flake8] | ||
exclude = tests | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Reachy Audio module. | ||
Handles all specific method related to audio especially: | ||
- playing sounds | ||
- recording sounds | ||
""" | ||
from typing import List | ||
|
||
import grpc | ||
from google.protobuf.empty_pb2 import Empty | ||
from reachy_sdk_api_v2.sound_pb2 import ( | ||
RecordingRequest, | ||
SoundId, | ||
SoundRequest, | ||
VolumeRequest, | ||
) | ||
from reachy_sdk_api_v2.sound_pb2_grpc import SoundServiceStub | ||
|
||
|
||
class Audio: | ||
"""Audio class used for microphone and speakers. | ||
It exposes functions to: | ||
- play / stop sounds with defined speakers, | ||
- test the speakers, | ||
- record tracks with a defined microphone, | ||
""" | ||
|
||
def __init__(self, host: str, port: int) -> None: | ||
"""Set up audio module, along with microphone and speakers.""" | ||
self._grpc_audio_channel = grpc.insecure_channel(f"{host}:{port}") | ||
|
||
self._audio_stub = SoundServiceStub(self._grpc_audio_channel) | ||
self._setup_microphones() | ||
self._setup_speakers() | ||
|
||
def _setup_microphones(self) -> None: | ||
micro_info = self._audio_stub.GetAllMicrophone(Empty()) | ||
self._microphone_id = micro_info.microphone_info[0].id | ||
|
||
def _setup_speakers(self) -> None: | ||
speaker_info = self._audio_stub.GetAllSpeaker(Empty()) | ||
self._speaker_id = speaker_info.speaker_info[0].id | ||
|
||
def testing(self) -> None: | ||
self._audio_stub.TestSpeaker(self._speaker_id) | ||
|
||
def get_sounds_list(self) -> List[str]: | ||
sounds = self._audio_stub.GetSoundsList(Empty()) | ||
return [soundId.id for soundId in sounds.sounds] | ||
|
||
def play(self, sound_name: str, volume: float = 0.5) -> None: | ||
available_sounds = self.get_sounds_list() | ||
if sound_name not in available_sounds: | ||
raise ValueError(f"Sound to play not available! Sounds available are {available_sounds}") | ||
if not 0 <= volume <= 1: | ||
raise ValueError(f"Volume should be between 0 and 1, got {volume}") | ||
self._audio_stub.PlaySound(SoundRequest(speaker=self._speaker_id, sound=SoundId(id=sound_name, volume=volume))) | ||
|
||
def stop(self) -> None: | ||
self._audio_stub.StopSound(ComponentId=self._speaker_id) | ||
|
||
def start_recording(self, sound_name: str) -> None: | ||
self._audio_stub.StartRecording(RecordingRequest(micro=self._microphone_id, recording_id=SoundId(id=sound_name))) | ||
|
||
def stop_recording(self) -> None: | ||
self._audio_stub.StopRecording(self._microphone_id) | ||
|
||
def set_audio_volume(self, volume: int) -> None: | ||
self._audio_stub.ChangeVolume(VolumeRequest(id=self._speaker_id, volume=volume)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.