Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and push Docker image on tag by mvitale1989 #1

Closed
wants to merge 17 commits into from
Closed
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
12 changes: 11 additions & 1 deletion docs/tutorial_2mic.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This tutorial should work for almost any Raspberry Pi and USB microphone. Audio

## Install OS

Follow instructions to [install Raspberry Pi OS](https://www.raspberrypi.com/software/). Under "Choose OS", pick "Raspberry Pi OS (other)" and "Raspberry Pi OS (Legacy, **64-bit**) Lite".
Follow instructions to [install Raspberry Pi OS](https://www.raspberrypi.com/software/). Under "Choose OS", pick "Raspberry Pi OS (other)" and "Raspberry Pi OS (**64-bit**) Lite".

When asking if you'd like to apply customization settings, choose "Edit Settings" and:

Expand Down Expand Up @@ -305,6 +305,13 @@ python3 -m venv --system-site-packages .venv
.venv/bin/pip3 install 'wyoming==1.5.2'
```

In case you use a ReSpeaker USB 4mic array v2.0, additionally install pixel-ring:

```sh
.venv/bin/pip3 install 'pixel-ring'
```


The `--system-site-packages` argument is used to access the pre-installed `gpiozero` and `spidev` Python packages. If these are **not already installed** in your system, run:

```sh
Expand Down Expand Up @@ -385,4 +392,7 @@ Try a voice command and see if the LEDs change. Use `journalctl` to check the lo
journalctl -u 2mic_leds.service -f
```

If you encounter any issues, you can add the `--debug` argument to the command line to increase the log level.
To control the brightness of the LEDS, use the `--led-brightness ` argument, which accepts integer numbers from 1 to 31.

Make sure to run `sudo systemctl daemon-reload` every time you make changes to the service.
2 changes: 1 addition & 1 deletion docs/tutorial_installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Create a voice satellite using a Raspberry Pi 3+ and USB microphone and speakers

## Install OS

Follow instructions to [install Raspberry Pi OS](https://www.raspberrypi.com/software/). Under "Choose OS", pick "Raspberry Pi OS (other)" and "Raspberry Pi OS (Legacy, **64-bit**) Lite".
Follow instructions to [install Raspberry Pi OS](https://www.raspberrypi.com/software/). Under "Choose OS", pick "Raspberry Pi OS (other)" and "Raspberry Pi OS (**64-bit**) Lite".

When asking if you'd like to apply customization settings, choose "Edit Settings" and:

Expand Down
8 changes: 7 additions & 1 deletion etc/install-respeaker-drivers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ mod='seeed-voicecard'
src='./'
kernel="$(uname -r)"
marker='0.0.0'
threads="$(getconf _NPROCESSORS_ONLN)"
memory="$(LANG=C free -m|awk '/^Mem:/{print $2}')"

if [ "${memory}" -le 512 ] && [ "${threads}" -gt 2 ]; then
threads=2
fi

mkdir -p "/usr/src/${mod}-${ver}"
cp -a "${src}"/* "/usr/src/${mod}-${ver}/"

dkms add -m "${mod}" -v "${ver}"
dkms build -k "${kernel}" -m "${mod}" -v "${ver}" && {
dkms build -k "${kernel}" -m "${mod}" -v "${ver}" -j "${threads}" && {
dkms install --force -k "${kernel}" -m "${mod}" -v "${ver}"
}

Expand Down
13 changes: 10 additions & 3 deletions examples/2mic_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ async def main() -> None:
"""Main entry point."""
parser = argparse.ArgumentParser()
parser.add_argument("--uri", required=True, help="unix:// or tcp://")
#
parser.add_argument("--debug", action="store_true", help="Log DEBUG messages")
parser.add_argument(
"--led-brightness",
type=int,
choices=range(1, 32),
default=31,
help="LED brightness (integer from 1 to 31)",
)
args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
Expand All @@ -54,7 +60,7 @@ async def main() -> None:
led_power = gpiozero.LED(LEDS_GPIO, active_high=False)
led_power.on()

leds = APA102(num_led=NUM_LEDS)
leds = APA102(num_led=NUM_LEDS, global_brightness=args.led_brightness)

# Start server
server = AsyncServer.from_uri(args.uri)
Expand Down Expand Up @@ -148,7 +154,7 @@ class APA102:
def __init__(
self,
num_led,
global_brightness=MAX_BRIGHTNESS,
global_brightness,
order="rgb",
bus=0,
device=1,
Expand All @@ -162,6 +168,7 @@ def __init__(
self.global_brightness = self.MAX_BRIGHTNESS
else:
self.global_brightness = global_brightness
_LOGGER.debug("LED brightness: %d", self.global_brightness)

self.leds = [self.LED_START, 0, 0, 0] * self.num_led # Pixel buffer
self.spi = spidev.SpiDev() # Init the SPI device
Expand Down
103 changes: 103 additions & 0 deletions examples/usbmic_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python3
"""Controls the LEDs on the ReSpeaker Mic Array v2.0 (USB) ."""
import argparse
import asyncio
import logging
import time
from functools import partial

from wyoming.event import Event
from wyoming.satellite import (
SatelliteConnected,
SatelliteDisconnected,
StreamingStarted,
StreamingStopped,
)
from wyoming.snd import Played
from wyoming.server import AsyncEventHandler, AsyncServer
from wyoming.vad import VoiceStarted, VoiceStopped
from wyoming.wake import Detection

from pixel_ring import pixel_ring

_LOGGER = logging.getLogger()

async def main() -> None:
"""Main entry point."""
parser = argparse.ArgumentParser()
parser.add_argument("--uri", required=True, help="unix:// or tcp://")
parser.add_argument("--debug", action="store_true", help="Log DEBUG messages")
args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
_LOGGER.debug(args)

_LOGGER.info("Ready")

# Turn on power to LEDs
pixel_ring.set_color_palette(0x0080ff, 0x007a37)
pixel_ring.think()
await asyncio.sleep(3)
pixel_ring.off()

# Start server
server = AsyncServer.from_uri(args.uri)

try:
await server.run(partial(LEDsEventHandler, args))
except KeyboardInterrupt:
pass
finally:
pixel_ring.off()


class LEDsEventHandler(AsyncEventHandler):
"""Event handler for clients."""

def __init__(
self,
cli_args: argparse.Namespace,
*args,
**kwargs,
) -> None:
super().__init__(*args, **kwargs)

self.cli_args = cli_args
self.client_id = str(time.monotonic_ns())

_LOGGER.debug("Client connected: %s", self.client_id)

async def handle_event(self, event: Event) -> bool:
_LOGGER.debug(event)

if Detection.is_type(event.type):
_LOGGER.debug("Detection")
pixel_ring.wakeup()
elif VoiceStarted.is_type(event.type):
_LOGGER.debug("VoiceStarted")
pixel_ring.speak()
elif VoiceStopped.is_type(event.type):
_LOGGER.debug("VoiceStopped")
pixel_ring.spin()
elif StreamingStopped.is_type(event.type):
_LOGGER.debug("StreamingStopped")
pixel_ring.off()
elif SatelliteConnected.is_type(event.type):
_LOGGER.debug("SatelliteConnected")
pixel_ring.think()
await asyncio.sleep(2)
pixel_ring.off()
elif Played.is_type(event.type):
_LOGGER.debug("Played")
pixel_ring.off()
elif SatelliteDisconnected.is_type(event.type):
_LOGGER.debug("SatelliteDisconnected")
pixel_ring.mono(0xff0000)

return True

if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
15 changes: 15 additions & 0 deletions script/run_usbmic
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
import sys
import subprocess
import venv
from pathlib import Path

_DIR = Path(__file__).parent
_PROGRAM_DIR = _DIR.parent
_VENV_DIR = _PROGRAM_DIR / ".venv"

context = venv.EnvBuilder().ensure_directories(_VENV_DIR)
subprocess.check_call(
[context.env_exe, str(_PROGRAM_DIR / "examples" / "usbmic_service.py")]
+ sys.argv[1:]
)
4 changes: 2 additions & 2 deletions wyoming_satellite/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ async def main() -> None:
try:
import webrtc_noise_gain # noqa: F401
except ImportError:
_LOGGER.fatal("Install extras for webrtc")
_LOGGER.exception("Extras for webrtc are not installed")
sys.exit(1)

if needs_silero(args):
try:
import pysilero_vad # noqa: F401
except ImportError:
_LOGGER.fatal("Install extras for silerovad")
_LOGGER.exception("Extras for silerovad are not installed")
sys.exit(1)

if args.awake_wav and (not Path(args.awake_wav).is_file()):
Expand Down
1 change: 0 additions & 1 deletion wyoming_satellite/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ async def _play_wav(
for event in wav_to_events(
wav_path,
samples_per_chunk=self.settings.snd.samples_per_chunk,
volume_multiplier=self.settings.snd.volume_multiplier,
):
await self.event_to_snd(event, is_tts=False)
except Exception:
Expand Down