Skip to content

Instantly share code, notes, and snippets.

@mickey-happygolucky
Last active January 24, 2019 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickey-happygolucky/55b484beddaf900db21e21bb269f9949 to your computer and use it in GitHub Desktop.
Save mickey-happygolucky/55b484beddaf900db21e21bb269f9949 to your computer and use it in GitHub Desktop.
sample program for Open JTalk with DHT11
# coding=utf-8
import os
import subprocess
import RPi.GPIO as GPIO
import dht11
def talk(s):
model = '/usr/share/Voice/mei/mei_happy.htsvoice'
dic = '/usr/share/dic'
wav = '/tmp/talk.wav'
txt = '/tmp/talk.txt'
with open(txt, mode='w') as f:
f.write(s)
command = 'open_jtalk -m %s -x %s -ow %s %s' % (model, dic, wav, txt)
subprocess.call(command.strip().split(' '))
os.remove(txt)
command = 'aplay %s' % wav
subprocess.call(command.strip().split(' '))
os.remove(wav)
if __name__ == '__main__':
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# GPIO21 set to input, pull-up
GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# GPIO10 connect to out pin of DHT11
instance = dht11.DHT11(pin=10)
talk('起動しました')
while True:
# Wait until button is pressed.
channel = GPIO.wait_for_edge(21, GPIO.FALLING, timeout=100)
if channel is not None:
# Read a data from DHT11
result = instance.read()
if result.is_valid():
temperature = '現在の温度は%d度です' % result.temperature
talk(temperature)
else:
talk('エラーが発生しました')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment