Flite with DHT

Flite with DHT
Published on Feb 04, 2021 by Jiaolyulu

try DHT22 with raspberry Pi

img
At first I tried to get the DHT22 working with Raspberry Pi. I came across 2 major problems. ##### First problem: Old Library The tutorial I found at first is using old DHT library which adafruit is no longer supporting. Here is the link for the old tutorial. old tutorial . This would give me error like this. Error: Import Error:cannot import name 'Beaglebone_Black_Driver' from 'Adafruit_DHT' (/usr/local/lib/python3.7/dist-packages/Adafruit_DHT/__init__.py) Then I found that I should use Adafruit CircuitPython-DHT Library. I should follow this tutorial on Adafruit website. It is really very clear to follow. Here is the tutorial link. DHT with Raspberry Pi ##### Second question:Can only run the script for one time When I hit "run module" for the first time it would works. However, when I hit the button for the second time, no data would be printed. I also saw many people coming across this problem and I tried several ways they recommended. At last, this one works for me. Error Issue explained and solution
img

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.