Skip to content

Commit

Permalink
Update Speech Recognizer Module for IoT Edge GA
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukeiot committed Nov 1, 2018
1 parent e683e61 commit 138f2fb
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
20 changes: 16 additions & 4 deletions seeed/3-speech-recognizer/deployment.template.json
Expand Up @@ -7,14 +7,21 @@
"type": "docker",
"settings": {
"minDockerVersion": "v1.25",
"loggingOptions": ""
"loggingOptions": "",
"registryCredentials": {
"registryName": {
"username": "$CONTAINER_REGISTRY_USERNAME",
"password": "$CONTAINER_REGISTRY_PASSWORD",
"address": "$CONTAINER_REGISTRY_ADDRESS"
}
}
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"settings": {
"image": "microsoft/azureiotedge-agent:1.0-preview",
"image": "mcr.microsoft.com/azureiotedge-agent:1.0.2",
"createOptions": ""
}
},
Expand All @@ -23,8 +30,13 @@
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "microsoft/azureiotedge-hub:1.0-preview",
"createOptions": ""
"image": "mcr.microsoft.com/azureiotedge-hub:1.0.2",
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}], \"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
},
"env": {
"OptimizeForPerformance": {
"value": "false"
}
}
}
},
Expand Down
Expand Up @@ -2,9 +2,9 @@
"$schema-version": "0.0.1",
"description": "",
"image": {
"repository": "microsoft/azureiotedge-seeed-natural-language-processing",
"repository": "$CONTAINER_REGISTRY_ADDRESS/azureiotedge-seeed-natural-language-processing",
"tag": {
"version": "1.0",
"version": "1.0.2",
"platforms": {
"arm32v7": "./Dockerfile.arm32v7"
}
Expand Down
@@ -1,8 +1,51 @@
FROM microsoft/azureiotedge-seeed-speech-to-text:1.0-deps-arm32v7
FROM resin/rpi-raspbian:stretch

RUN [ "cross-build-start" ]

WORKDIR /app

ENV PYTHONUNBUFFERED=1

# Install dependencies
RUN apt-get update && apt-get install -y \
git \
python3 \
python3-pip \
python3-dev \
wget \
swig \
build-essential \
i2c-tools \
libpulse-dev \
libboost-python1.62.0 \
libasound2-dev \
libopenjp2-7-dev \
libjpeg-dev \
portaudio19-dev \
python-pyaudio \
python-pil \
python-requests \
python-pocketsphinx \
pocketsphinx

COPY requirements.txt ./

RUN pip3 install --upgrade pip
RUN pip3 install --upgrade setuptools
RUN pip3 install --no-cache-dir -r requirements.txt

# RUN git clone --recursive https://github.com/jessebenson/pocketsphinx-python \
# && cd /app/pocketsphinx-python \
# && python3 setup.py install \
# && rm -rf /app/pocketsphinx-python

# Expose the port
EXPOSE 80

COPY fonts/. ./fonts/
COPY *.py ./

ENTRYPOINT [ "python", "main.py" ]
RUN [ "cross-build-end" ]

# Run the flask server for the endpoints
CMD ["python3", "-u", "main.py"]
@@ -1,6 +1,6 @@
#!/usr/bin/env python

import smbus
import smbus2


def check_for_oled():
Expand All @@ -11,7 +11,7 @@ def check_for_oled():


def look_for_device_address(address):
bus = smbus.SMBus(1)
bus = smbus2.SMBus(1)
is_device_found = False

for device in range(128):
Expand Down
24 changes: 5 additions & 19 deletions seeed/3-speech-recognizer/modules/speech-to-text/hubmanager.py
@@ -1,7 +1,7 @@
import os
import sys

from iothub_client import IoTHubClient, IoTHubClientError, IoTHubTransportProvider
import iothub_client
from iothub_client import IoTHubModuleClient, IoTHubClientError, IoTHubTransportProvider

# messageTimeout - the maximum time in milliseconds until a message times out.
# The timeout period starts at IoTHubClient.send_event_async.
Expand All @@ -10,30 +10,16 @@

class HubManager(object):

def __init__(self, connection_string = None, protocol = IoTHubTransportProvider.MQTT):
if not connection_string:
connection_string = os.environ['EdgeHubConnectionString']
def __init__(self, protocol = IoTHubTransportProvider.MQTT):

print("\nPython %s\n" % sys.version)
print("IoT Hub Client for Python")
print("Starting the IoT Hub Python sample using protocol %s..." % protocol)

self.client_protocol = protocol
self.client = IoTHubClient(connection_string, protocol)
self.client = IoTHubModuleClient()
self.client.create_from_environment(protocol)

# set the time until a message times out
self.client.set_option("messageTimeout", MESSAGE_TIMEOUT)
# some embedded platforms need certificate information
self.set_certificates()

def set_certificates(self):
CERT_FILE = os.environ['EdgeModuleCACertificateFile']
print("Adding TrustedCerts from: {0}".format(CERT_FILE))

# this brings in x509 privateKey and certificate
with open(CERT_FILE) as file:
try:
self.client.set_option("TrustedCerts", file.read())
print("set_option TrustedCerts successful")
except IoTHubClientError as iothub_client_error:
print("set_option TrustedCerts failed (%s)" % iothub_client_error)
2 changes: 1 addition & 1 deletion seeed/3-speech-recognizer/modules/speech-to-text/main.py
Expand Up @@ -7,7 +7,7 @@
import hubmanager
import mic
import oleddisplay
from iothub_client import IoTHubClient, IoTHubMessage
from iothub_client import IoTHubModuleClient, IoTHubMessage


oled_display = None
Expand Down
4 changes: 2 additions & 2 deletions seeed/3-speech-recognizer/modules/speech-to-text/module.json
Expand Up @@ -2,9 +2,9 @@
"$schema-version": "0.0.1",
"description": "",
"image": {
"repository": "microsoft/azureiotedge-seeed-speech-to-text",
"repository": "$CONTAINER_REGISTRY_ADDRESS/azureiotedge-seeed-speech-to-text",
"tag": {
"version": "1.0",
"version": "1.0.2",
"platforms": {
"arm32v7": "./Dockerfile.arm32v7"
}
Expand Down
@@ -0,0 +1,7 @@
azure-iothub-device-client
smbus2
requests
luma.oled
RPi.GPIO
pyaudio
pocketsphinx

0 comments on commit 138f2fb

Please sign in to comment.