try DHT22 with raspberry Pi


Get Flite works with the code!
I go all the way through the tutorial link Pedro put at the website. Here is the tutorial link : flite with raspberry Pi
It all goes very well!
My trial
I tried to make a simple robot that everytime the temperature is above 80 F, it would say “Hoeing grain in the blaze of noon, Sweat drops fall — grain to earth”, which is a Chinese poetry that tell how hot the weather is.
Everytime the temperature is below 80 F, it would say “wind and rain escorted Springs departure, Flying snow welcomes Springs return.”, which is a Chinese poetry saying how cold the weather is. I got them translated mannually.
Here are the link of the wav sound output I have. voice link
Code
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import os
import time
import board
import adafruit_dht
# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT22(board.D4, False)
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
# This may be necessary on a Linux single board computer like the Raspberry Pi,
# but it will not work in CircuitPython.
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
str1="Hoeing grain in the blaze of noon, Sweat drops fall — grain to earth"
str2="wind and rain escorted Springs departure, Flying snow welcomes Springs return. "
if temperature_f>80.4:
str3=str1
else:
str3=str2
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
os.system("flite -t ' " +str3+ str(temperature_f) + " degrees' -o nowtemperature.wav")
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(10.0)
difficulties
Actually I cannot manage to make tts_watson_ssml.js work. The tts_watson.js works for me. I don’t know if I should blame my Windows computer again for this failure. I think it shouldn’t be an issue of operating system. I got a wav file of 0 KB.