Jim Bennett
f0e91dc212
|
3 years ago | |
---|---|---|
.. | ||
README.md | 3 years ago | |
assignment.md | 4 years ago |
README.md
Set a timer and provide spoken feedback
Add a sketchnote if possible/appropriate
Pre-lecture quiz
Introduction
Smart assistants are not one-way communication devices. You speak to them, and they respond:
"Alexa, set a 3 minute timer"
"Ok, your timer is set for 3 minutes"
In the last 2 lessons you learned how to take speech and create text, then extract a set timer request from that text. In this lesson you will learn how to set the timer on the IoT device, responding to the user with spoken words confirming their timer, and alerting them when their timer is finished.
In this lesson we'll cover:
Text to speech
Set the timer
The timer can be set by sending a command from the serverless code, instructing the IoT device to set the timer. This command will contain the time in seconds till the timer needs to go off.
Task - set the timer using a command
-
In your serverless code, add code to send a direct method request to your IoT device
⚠️ You can refer to the instructions for sending direct method requests in lesson 5 of the farm project if needed.
You will need to set up the connection string for the IoT Hub with the service policy (NOT the device) in your
local.settings.json
file and add theazure-iot-hub
pip package to yourrequirements.txt
file. The device ID can be extracted from the event. -
The direct method you send needs to be called
set-timer
, and will need to send the length of the timer as a JSON property calledtime
. Use the following code to build theCloudToDeviceMethod
using thetotal_time
calculated from the data extracted by LUIS:payload = { 'time': total_time } direct_method = CloudToDeviceMethod(method_name='set-timer', payload=json.dumps(payload))
💁 You can find this code in the code-command/functions folder.
Task - respond to the command on the IoT device
-
On your IoT device, respond to the command.
⚠️ You can refer to the instructions for handling direct method requests from IoT devices in lesson 4 of the farm project if needed.
-
Work through the relevant guide to set a timer for the required time:
💁 You can find this code in the code-command/wio-terminal, code-command/virtual-device, or code-command/pi folder.
Convert text to speech
The same speech service you used to convert speech to text can be used to convert text back into speech, and this can be played through a microphone on your IoT device.
Task - convert text to speech
Work through the relevant guide to convert text to speech using your IoT device: